Difference between pages "Package:I3 (Window Manager)" and "Hostname"

From Funtoo
(Difference between pages)
Jump to navigation Jump to search
 
 
Line 1: Line 1:
== Introduction ==  
==Introduction==
i3 is a tiling window manager that is based upon experiences the developers shared while attempting to fix/hack wmii. i3 has the ability for either floating windows, which you can resize and move, and tiling windows. i3 uses a tree as a data structure to allow for more flexibility.  i3 defaults with home-row key-bindings which are quick and easy to get beginners off the ground.
A hostname is a unique name created to identify a machine on a network. In computer networking, a hostname is a label that is assigned to a device connected to a computer network and that is used to identify the device in various forms of electronic communication such as the World Wide Web, e-mail or Usenet. Hostnames may be simple names consisting of a single word or phrase, or they may be structured.
 
==Configuration==
'''NOTE:  This wiki is made following the steps produced to get a working i3 using xrandr instead of xinerama, ATI proprietary drivers instead of radeon drivers, a dual-monitor setup, and no login managerFor Nvidia and Twinview users, a link is supplied in [[#X11 and xrandr|X11 and xrandr]]. Xinerama was initially used and worked in the dual-monitor setup so it possible to substitute xinerama for xrandr with minimal changes.'''   
In Funtoo Linux <code>/etc/conf.d/hostname</code> is the only configuration file for setting a hostname. In OpenRC framework <code>/etc/conf.d/foo</code> is the configuration file for a corresponding Init script <code>/etc/init.d/foo</code>With the case of hostname, default value in <code>/etc/conf.d/hostname</code> is set to ''localhost'', means when system boots and OpenRC's <code>/etc/init.d/hostname</code> script started a hostname getting only ''localhost'' name.  How it looks? In your shell promt this will look in following way, an example for root:
 
== Installation ==
 
=== Portage ===
 
The easiest and quickest way:
<console>
<console>
###i## emerge -avt x11-wm/i3
localhost ~ # ##i## Hello :)
</console>
</console>
 
Let's play a bit with a configuration. Open <code>/etc/conf.d/hostname</code> with your favorite editor and set a hostname of your choice. Below, I will use a real examples  from one of my working test boxes.
=== Manual ===
 
==== Tarball ====
 
Download the latest version from the i3 website.
[http://i3wm.org/downloads/i3-4.8.tar.bz2 i3-4.8]
 
<console>
<console>
###i## cd /PATH/TO/TARBALL
localhost ~ # ##i## nano /etc/conf.d/hostname
###i## make
###i## sudo make install
</console>
</console>
 
Let's set it to hostname="oleg-stable.host.funtoo.org". Save the file and restart  a hostname service:
==== Git ====
 
<console>
<console>
###i## git clone git://code.i3wm.org/i3
localhost ~ # ##i## service hostname restart
###i## cd i3
###i## make
###i## sudo make install
</console>
</console>
 
Now, let's examine our changes, after a restarting a hostname
== Setup ==
 
=== xinitrc ===
 
Edit <tt>~/.xinitrc</tt>:
 
<pre>
exec i3
</pre>
 
 
For i3 logging, edit <tt>~/.xinitrc</tt>:
 
<pre>
exec i3 -V -d all >~/.i3/i3log-$(date +'%F-%k-%M-%S') 2>&1
</pre>
 
If you are using Nvidia or for some reason don't use xrandr, edit ~/.xinitrc
<pre style="color:green">exec i3 --force-xinerama</pre>
and nvidia with logging:
<pre style="color:green">exec i3 --force-xinerama -V -d all >~/.i3/i3log-$(date +'%F-%k-%M-%S') 2>&1</pre>
Example ~/.xinitrc that uses consolekit and dbus in launch and also logs on exit.
<pre style="color:purple">#!/bin/zsh
xrdb -merge ~/.Xresources
xcompmgr &
 
if [[ $1 == "i3" ]]; then
    exec ck-launch-session dbus-launch --sh-syntax --exit-with-session i3 -V -d all > ~/.i3/i3log-$(date +'%F-%k-%M-%S') 2>&1
elif [[ $1 == "razor" ]]; then
    exec ck-launch-session dbus-launch startrazor
elif [[ $1 == "awesome" ]]; then
    exec ck-launch-session dbus-launch awesome
elif [[ $1 == "qtile" ]]; then
    exec ck-launch-session dbus-launch ~/.qtile-session
else
    echo "Choose a window manager"
fi</pre>
 
<div id="X11 and xrandr"></div>
 
=== X11 and xrandr ===
 
=== X and RandR ===
'''NOTE: RandR and Xinerama do not play together.  Use one or the other.'''
 
I use an AMD HD 6870 with 3 monitors (2 DVI and 1 with an AMD validated Mini DisplayPort™ to DVI dongle).
 
Install {{Package|x11-apps/xrandr}}:
<console>
<console>
###i## emerge x11-apps/xrandr
oleg-stable ~ # ##i## Hello :)
</console>
</console>
and if you want a GUI with xrandr:
== Diving deeper==
Notice, that in above output we seeing a shortened hostname and not a FQDN (Fully Qualified Domain Name). Don't be frustrated. This is  how  default bash promt <code>PS1</code> set. To get nice promts, please, follow http://www.funtoo.org/Prompt_Magic
Another way to test our settings is using a '''hostname''' command. Here we will show only  some of it's features. Let's try to execute '''hostname''' command:
<console>
<console>
###i## emerge x11-misc/arandr
oleg-stable ~ # ##i## hostname
oleg-stable.host.funtoo.org
</console>
</console>
 
Now we see our fully qualified domain name hostname just how we configured it in <code>/etc/conf.d/hostname</code> in above paragraph. To get a short hostname we need to set '''-s ''' (short) argument to hostname command.  
If you do not have X configured yet, follow the link on the [http://en.gentoo-wiki.com/wiki/X.Org Gentoo Wiki]
 
My xorg.conf.d folder for example: [https://github.com/akiress/dotfiles/blob/master/etc/X11/xorg.conf.d/30-screen.conf 30-screen.conf]
 
Since the names of the monitors are already known in xrandr, I just use those names in my 30-screen.conf configuration. It doesn't matter what you use in your X configuration however.
 
Once you have X configured however you like, start qtile with either:
<console>
<console>
###i## startx
oleg-stable ~ # ##i## hostname -s
oleg-stable
</console>
</console>
or, in a case similar to mine:
Good! Hostname offers more then just displaying a system host name but can also set one. Let's try:
<console>
<console>
###i## xinit qtile
oleg-stable ~ # ##i## hostname foo.bar.baz
oleg-stable ~ # ##i## hostname
foo.bar.baz
</console>
</console>
As you can see, we changed a hostname on-the-fly. This is not recommended way.
{{fancywarning|Please, notice that using '''hostname''' command to configure will work temporary for a current session and will be reverted back to a value set in <code>/etc/conf.d/hostname</code> file with next system restart.}}


=== i3 config ===
Now that we got a brief description of a hostname and basic configuration steps, its time to reflect another important case which is directly related to a Funtoo Linux hostname generation, a hosts.
The i3 configuration file can be found in /etc/i3/config, but I suggest that you copy the file into a local ~/.i3 directory.
<pre># mkdir -p ~/.i3 && cp /etc/i3/config ~/.i3/config</pre>
Open up ~/i3/config in your editor of choice.
<code style="color:green">set $mod Mod1</code> assigns the variable $mod to be Mod1.  In i3, Mod1 is the Alt key.  If you wish to use the Windows key then use <code style="color:green">set $mod Mod4</code>  In the keybinding section, $mod is used in place of Mod1 in the case that you do wish to change the modifier.  In the workspace key, the keybindings are set with Mod1 instead of the variable, so remember to change those bindings manually if you are replacing the Mod1 modifier.  Else you can change Mod1 in those sections to $mod and change all the keybindings at the same time by setting the $mod variable.
<pre style="color:green">set $mod Mod1</pre>
To have programs start automatically in i3, use the command <code style="color:green">exec APPLICATION</code>.  This is the section that the xrandr screen layout bash file created earlier will be placed.  The i3bar is a tray and status bar combination.  If you have applications that run in the system tray that you want to autostart, call those applications with exec.
<pre style="color:green">exec /PATH/TO/XRANDR-BASH-FILE
exec NAME OF BROWSER
exec NAME OF EDITOR
exec volumeicon
exec dropbox</pre>
In the workspace section, you have the opportunity to name the workspaces by setting either the number of the workspace, the name of the workspace, or the number and name of the workspace.  <code style="color:green">bindsym KEYBIND workspace NAME/NUMBER OF WORKSPACE</code>.  Remember to use quotes when naming a workspace.
<pre style="color:green">bindsym Mod1+1 workspace 1
bindsym Mod1+1 workspace "my first workspace"
bindsym Mod1+1 workspace "1: my first workspace"</pre>
To assign a workspace to a certain output you will need the output from running xrandr again if you do not remember which connections are being used.  In the example from [#X11 and xrandr|X11 and xrandr], the connected outputs are DFP3 and DFP4.  To assign the workspace, you need to add <code style="color:green">workspace NAME OF WORKSPACE or NUMBER output CONNECTED OUTPUT</code>.  There are several types of outputs so make sure that you are using the connected outputs from xrandr when assigning workspaces, else the workspace will not show up.
<pre style="color:green">workspace 1 output DFP3
workspace "my first workspace" output DFP3
workspace "1: my first workspace" output DFP3
workspace "2: my second workspace" output DFP4</pre>
To assign a program to a certain workspace, you will need to run xprop.  If you do not have xprop, emerge it.
<pre># emerge -avt x11-apps/xprop</pre>
To run xprop, open a terminal and run <pre># xprop</pre>  Your mouse cursor should become a crosshair and you will want to mouse over the window that contains the running application.  Click on that window and xprop will then output the window information.  The easiest way to assign a program is to look for <pre style="color:green">WM_CLASS(STRING) = "INSTANCE", "CLASS"</pre>  Be sure to note that the window INSTANCE is before the window CLASS.  In the config file, add <code style="color:green">assign [class="^INSTANCE$" instance="^CLASS$] NAME OF WORKSPACE</code>.  For aesthetic purposes, you can add → before NAME OF WORKSPACE, but mind that the → is a UTF-8 character and not <code>-></code>.  For the assignments, do not put the workspace name within quotes as you do when naming them and setting their output.
<pre style="color:green">
assign [class="^Chromium-browser$" instance="^chromium-browser$"] 1
assign [class="^Chromium-browser$" instance="^chromium-browser$"] web
assign [class="^Chromium-browser$" instance="^chromium-browser$"] 1: web
assign [class="^Chromium-browser$" instance="^chromium-browser$"] → 1
assign [class="^Chromium-browser$" instance="^chromium-browser$"] → web
assign [class="^Chromium-browser$" instance="^chromium-browser$"] → 1: web</pre>
For aesthetic purposes, their are three types of borders for the windows.  This can be set by adding <code style="color:green">new_window <normal|1pixel|none></code>.  There are also keybindings that allow you to switch between the 3 border styles.
<pre style="color:green">new_window 1pixel
bindsym $mod+t border normal
bindsym $mod+y border 1pixel
bindsym $mod+u border none</pre>
The orientation for new workspaces can be set by adding <code style="color:green">default_orientation <horizontal|vertical|auto></code>
<pre style="color:green">default_orientation horizontal</pre>


A sample ~/.i3/config:
==Hosts case==
<div style="height:250px;overflow:scroll;color:green"><pre>
As per man page <code>hosts</code> stands for static table lookup for hostnames and it's configuration file is <code>/etc/hosts</code>. Here is how it looks
set $mod Mod1
{{file|name=/etc/hosts|body=
# Auto-generated hostname. Please do not remove this comment.
127.0.0.1      oleg-stable.host.funtoo.org oleg-stable localhost localhost.localdomain
::1            oleg-stable.host.funtoo.org oleg-stable localhost localhost.localdomain
}}
As you can see it has entries from our <code>/etc/conf.d/hostname</code>. As you may have guessed, in Funtoo Linux <code>/etc/hosts</code> file entries are auto-generated, when OpenRC hostname service starts. Previously, it is used to edit <code>/etc/hosts</code> manually. In Funtoo Linux there is no such need.


########################################################
What about custom hosts entries? This can be easily configured with 'aliases'. For example you want to have a hosts for your remote router or a computer in home LAN. Let's try to modify <code>/etc/conf.d/hostname</code> with adding following - my remote computer oleg.distant.home has an IP 10.1.1.2:
######## Autostart ########
  <console>
########################################################
oleg-stable ~ # ##i## echo 'aliases="10.1.12 oleg.distant.home"' >> /etc/conf.d/hostname
exec ~/.screenlayout/dualdtop.sh
oleg-stable ~ # ##i## service hostname restart
exec chromium-browser
exec gvim
exec volumeicon
exec parcellite
exec dropbox
 
########################################################
######## Workspaces ########
########################################################
# switch to workspace
bindsym Mod1+1 workspace "1: web"
bindsym Mod1+2 workspace "2: irc"
bindsym Mod1+3 workspace "3: gvim"
bindsym Mod1+4 workspace "4: ranger"
bindsym Mod1+5 workspace "5: terms"
bindsym Mod1+6 workspace "6: mplayer"
bindsym Mod1+7 workspace "7: mail"
bindsym Mod1+8 workspace "8: firefox"
bindsym Mod1+9 workspace "9: music"
bindsym Mod1+0 workspace "10: office"
 
## Output certain workspaces
workspace "1: web" output DFP3
workspace "2: irc" output DFP4
workspace "3: gvim" output DFP4
workspace "4: ranger" output DFP3
workspace "5: terms" output DFP4
workspace "6: mplayer" output DFP3
workspace "7: mail" output DFP3
workspace "8: firefox" output DFP3
workspace "9: music" output DFP3
workspace "10: office" output DFP4
 
## Assign workspaces to programs
assign [class="^Chromium-browser$" instance="^chromium-browser$"] → 1: web
assign [class="^Gvim$" instance="^gvim$"] → 3: gvim
assign [class="^MPlayer$" instance="^gl$"] → 6: mplayer
assign [class="^Firefox$" instance="^Navigator$"] → 8: firefox
assign [class="^Emacs$" instance="^emacs$"] → 9: emacs
assign [class="^libreoffice-startcenter$" instance="^VCLSalFrame.DocumentWindow$"] 10: office
 
# move focused container to workspace
bindsym Mod1+Shift+1 move workspace 1
bindsym Mod1+Shift+2 move workspace 2
bindsym Mod1+Shift+3 move workspace 3
bindsym Mod1+Shift+4 move workspace 4
bindsym Mod1+Shift+5 move workspace 5
bindsym Mod1+Shift+6 move workspace 6
bindsym Mod1+Shift+7 move workspace 7
bindsym Mod1+Shift+8 move workspace 8
bindsym Mod1+Shift+9 move workspace 9
bindsym Mod1+Shift+0 move workspace 10
 
########################################################
######## Aesthetics ########
########################################################
# Window border style: normal: border normal, with window title bar;
# none: no border or window title bar; 1pixel: 1 pixel border.
new_window 1pixel
bindsym $mod+t border normal
bindsym $mod+y border 1pixel
bindsym $mod+u border none
 
# font for window titles. ISO 10646 = Unicode
font -misc-fixed-medium-r-normal--13-120-75-75-C-70-iso10646-1
 
# Orientation for new workspaces
# Can be set <horizontal|vertical|auto>
default_orientation horizontal
 
# Layout for new containers
# Can be set <default|stacking|tabbed>
workspace_layout default
 
# Use Mouse+$mod to drag floating windows to their wanted position
floating_modifier $mod
 
########################################################
######## Keybindings ########
########################################################
 
# start a terminal
bindsym $mod+Return exec i3-sensible-terminal
 
# kill focused window
bindsym $mod+Shift+Q kill
 
# start dmenu (a program launcher)
bindsym $mod+d exec dmenu_run
 
# change focus
bindsym $mod+j focus left
bindsym $mod+k focus down
bindsym $mod+l focus up
bindsym $mod+semicolon focus right
 
# alternatively, you can use the cursor keys:
bindsym $mod+Left focus left
bindsym $mod+Down focus down
bindsym $mod+Up focus up
bindsym $mod+Right focus right
 
# move focused window
bindsym $mod+Shift+J move left
bindsym $mod+Shift+K move down
bindsym $mod+Shift+L move up
bindsym $mod+Shift+colon move right
 
# alternatively, you can use the cursor keys:
bindsym $mod+Shift+Left move left
bindsym $mod+Shift+Down move down
bindsym $mod+Shift+Up move up
bindsym $mod+Shift+Right move right
 
# split in horizontal orientation
bindsym $mod+h split h
 
# split in vertical orientation
bindsym $mod+v split v
 
# enter fullscreen mode for the focused container
bindsym $mod+f fullscreen
 
# change container layout (stacked, tabbed, default)
bindsym $mod+s layout stacking
bindsym $mod+w layout tabbed
bindsym $mod+e layout default
 
# toggle tiling / floating
bindsym $mod+Shift+space floating toggle
 
# change focus between tiling / floating windows
bindsym $mod+space focus mode_toggle
 
# focus the parent container
bindsym $mod+a focus parent
 
# focus the child container
#bindcode $mod+d focus child
 
# reload the configuration file
bindsym $mod+Shift+C reload
# restart i3 inplace (preserves your layout/session, can be used to upgrade i3)
bindsym $mod+Shift+R restart
# exit i3 (logs you out of your X session)
bindsym $mod+Shift+E exit
 
# resize window (you can also use the mouse for that)
mode "resize" {
        # These bindings trigger as soon as you enter the resize mode
        # They resize the border in the direction you pressed, e.g.
        # when pressing left, the window is resized so that it has
        # more space on its left
 
bindsym j resize shrink left 10 px or 10 ppt
bindsym Shift+J resize grow left 10 px or 10 ppt
 
bindsym k resize shrink down 10 px or 10 ppt
bindsym Shift+K resize grow down 10 px or 10 ppt
 
bindsym l resize shrink up 10 px or 10 ppt
bindsym Shift+L resize grow up 10 px or 10 ppt
 
bindsym semicolon resize shrink right 10 px or 10 ppt
bindsym Shift+colon resize grow right 10 px or 10 ppt
 
        # same bindings, but for the arrow keys
bindsym Left resize shrink left 10 px or 10 ppt
bindsym Shift+Left resize grow left 10 px or 10 ppt
 
bindsym Down resize shrink down 10 px or 10 ppt
bindsym Shift+Down resize grow down 10 px or 10 ppt
 
bindsym Up resize shrink up 10 px or 10 ppt
bindsym Shift+Up resize grow up 10 px or 10 ppt
 
bindsym Right resize shrink right 10 px or 10 ppt
bindsym Shift+Right resize grow right 10 px or 10 ppt
 
        # back to normal: Enter or Escape
bindsym Return mode "default"
bindsym Escape mode "default"
}
 
bindsym $mod+r mode "resize"
 
########################################################
######## i3bar ########
########################################################
 
# Start i3bar to display a workspace bar (plus the system information i3status
# finds out, if available)
bar {
    output            DFP3
    output       DFP4
    status_command    i3status -c ~/.i3status.conf
    position          top
    mode              dock
    workspace_buttons yes
    tray_output      DFP3
   
    font -misc-fixed-medium-r-normal--13-120-75-75-C-70-iso10646-1
 
    colors {
        background #000000
        statusline #FFFFFF
 
        focused_workspace  #ffffff #9932CC
        active_workspace  #ffffff #DA70D6
        inactive_workspace #888888 #242424
        urgent_workspace  #ffffff #32CD32
    }
} </pre></div>
 
These scripts can be found in /usr/bin/
 
=== i3nagbar ===
 
The i3nagbar is the error bar that pops up on top of the screen when there is an error in the i3 configuration.
 
=== i3-sensible-editor ===
 
i3-sensible-editor is callen when the user presses the edit button on the i3nagbar. If $EDITOR is set, that editor will be used, else i3-sensible-editor will open the first editor that is installed according to the order in i3-sensible-editor. If the user has a preference, he will set $EDITOR.
 
=== i3-sensible-terminal ===
 
i3-sensible-terminal is called when the user opens a terminal. If $TERMINAL is set, that terminal will be used, else i3-sensible-terminal will open the first terminal that is installed according to the order in i3-sensible-terminal. If the user has a preference, he will set $TERMINAL.
 
=== i3-sensible-pager ===
 
i3-sensible-pager is called when the user presses the view button on the i3nagbar. If $PAGER is set, that pager will be used, else i3-sensible-pager will open the first pager that is installed accordding to the order in i3-sensible-pager.  If the user has a preference, he will set $PAGER.
 
=== i3status ===
 
i3status generates a status bar similar to conky in i3.  i3status replaces dzen2, xmobar, and other similar applications used in older versions of i3.  It is suggested to create an <tt>~/.i3status.conf</tt> file to configure the i3status bar locally. 
A sample <tt>~/.i3status.conf</tt>:
 
<pre>
general {
        colors = true
        interval = 5
}
 
order = "disk /"
order += "disk /home"
order += "ethernet eth0"
order += "cpu_temperature 0"
order += "cpu_temperature 1"
order += "cpu_temperature 2"
order += "cpu_temperature 3"
order += "load"
order += "time"
 
ethernet eth0 {
        # if you use %speed, i3status requires the cap_net_admin capability
        format_up = "Eth0: %ip (%speed)"
        format_down = "Eth0: down"
}
 
time {
        format = "%a:%d-%b-%Y %I:%M:%S %p"
}
 
load {
        format = "Load: %5min"
}
 
cpu_temperature 0 {
format = "T1: %degrees °C"
path = "/sys/devices/platform/coretemp.0/temp2_input"
}
 
cpu_temperature 1 {
format = "T2: %degrees °C"
path = "/sys/devices/platform/coretemp.0/temp3_input"
}
 
cpu_temperature 2 {
format = "T3: %degrees °C"
path = "/sys/devices/platform/coretemp.0/temp4_input"
}
 
cpu_temperature 3 {
format = "T4: %degrees °C"
path = "/sys/devices/platform/coretemp.0/temp5_input"
}
 
disk "/" {
        format = "/: %free"
}
 
disk "/home" {
format = "/home: %free"
}
</pre>
 
== dmenu ==
 
i3 uses {{Package|x11-misc/dmenu}} as the application launcher. To install it, run the following:
 
<console>
###i## emerge dmenu
</console>
</console>
 
Examine our changes:
{{fancynote| The default key-binding for dmenu is Mod1+d.}}
 
== Default Keybindings ==
 
{| class="wikitable" border="2" style="text-align:center;"
|Alt + Enter
|Open terminal
|-
|Alt + A
|Focus Parent
|-
|Alt + S
|Stacked Layout
|-Advanced SearchSearch…
|Alt + W
|Tabbed Layout
|-
|Alt + E
|Default Layout
|-
|Alt + SpaceBar
|Focus tiling/floating
|-
|Alt + D
|dmenu
|-
|Alt + H
|Split Horizontal
|-
|Alt + V
|Split Vertically
|-
|Alt + J
|Left
|-
|Alt + K
|Down
|-
|Alt + J
|Up
|-
|Alt + ;
|Right
|-
|Alt + Shift + Q
|Kill window
|-
|Alt + Shift + E
|Exit i3
|-
|Alt + Shift + C
|Reload i3config without restarting
|-
|Alt + Shift + R
|Restart i3 (reloads i3config without exiting i3)
|-
|Alt + Shift + J
|Move left
|-
|Alt + Shift + K
|Move down
|-
|Alt + Shift + L
|Move up
|-
|Alt + Shift + :
|Move right
|-
|Alt + Shift + SpaceBar
|Toggle tiling/floating
|}
 
== Troubleshooting ==
 
=== i3status ===
 
{{fancynote| i3status may not work out of box}} The permissions may be set to: <tt>-r-xr-x---</tt>: when run as non-root, sh would return with "permission denied".
If i3status does not work for you, this can be easily corrected by changing the permissions.
<console>
<console>
###i## sudo chmod 755 /usr/bin/i3status
oleg-stable ~ # ##i## cat /etc/hosts
</console>
</console>
 
{{file|name=/etc/hosts|body=
=== Documentation ===
# Auto-generated hostname. Please do not remove this comment.
 
10.1.1.2        oleg.distant.home
==== Websites ====
127.0.0.1      oleg-stable.host.funtoo.org oleg-stable localhost localhost.localdomain
 
::1            oleg-stable.host.funtoo.org oleg-stable localhost localhost.localdomain
[http://i3wm.org/ i3]
}}
 
[http://i3wm.org/docs/userguide.html User Guide]
 
[http://i3wm.org/docs/ More Documentation]
 
==== Man pages ====
 
* i3
* i3-config-wizard
* i3-input
* i3-migrate-config-to-v4
* i3-msg
* i3-nagbar
* i3-sensible-editor
* i3-sensible-pager
* i3-sensible-terminal
* i3-wsbar
* i3bar
* i3lock
* i3status
 
[[Category:Desktop]]

Revision as of 16:06, February 24, 2015

Introduction

A hostname is a unique name created to identify a machine on a network. In computer networking, a hostname is a label that is assigned to a device connected to a computer network and that is used to identify the device in various forms of electronic communication such as the World Wide Web, e-mail or Usenet. Hostnames may be simple names consisting of a single word or phrase, or they may be structured.

Configuration

In Funtoo Linux /etc/conf.d/hostname is the only configuration file for setting a hostname. In OpenRC framework /etc/conf.d/foo is the configuration file for a corresponding Init script /etc/init.d/foo. With the case of hostname, default value in /etc/conf.d/hostname is set to localhost, means when system boots and OpenRC's /etc/init.d/hostname script started a hostname getting only localhost name. How it looks? In your shell promt this will look in following way, an example for root:

localhost ~ #  Hello :)

Let's play a bit with a configuration. Open /etc/conf.d/hostname with your favorite editor and set a hostname of your choice. Below, I will use a real examples from one of my working test boxes.

localhost ~ #  nano /etc/conf.d/hostname

Let's set it to hostname="oleg-stable.host.funtoo.org". Save the file and restart a hostname service:

localhost ~ #  service hostname restart

Now, let's examine our changes, after a restarting a hostname

oleg-stable ~ #  Hello :)

Diving deeper

Notice, that in above output we seeing a shortened hostname and not a FQDN (Fully Qualified Domain Name). Don't be frustrated. This is how default bash promt PS1 set. To get nice promts, please, follow http://www.funtoo.org/Prompt_Magic Another way to test our settings is using a hostname command. Here we will show only some of it's features. Let's try to execute hostname command:

oleg-stable ~ #  hostname
oleg-stable.host.funtoo.org

Now we see our fully qualified domain name hostname just how we configured it in /etc/conf.d/hostname in above paragraph. To get a short hostname we need to set -s (short) argument to hostname command.

oleg-stable ~ #  hostname -s
oleg-stable

Good! Hostname offers more then just displaying a system host name but can also set one. Let's try:

oleg-stable ~ #  hostname foo.bar.baz
oleg-stable ~ #  hostname 
foo.bar.baz

As you can see, we changed a hostname on-the-fly. This is not recommended way.

   Warning

Please, notice that using hostname command to configure will work temporary for a current session and will be reverted back to a value set in /etc/conf.d/hostname file with next system restart.

Now that we got a brief description of a hostname and basic configuration steps, its time to reflect another important case which is directly related to a Funtoo Linux hostname generation, a hosts.

Hosts case

As per man page hosts stands for static table lookup for hostnames and it's configuration file is /etc/hosts. Here is how it looks

   /etc/hosts
# Auto-generated hostname. Please do not remove this comment.
127.0.0.1       oleg-stable.host.funtoo.org oleg-stable localhost localhost.localdomain
::1             oleg-stable.host.funtoo.org oleg-stable localhost localhost.localdomain

As you can see it has entries from our /etc/conf.d/hostname. As you may have guessed, in Funtoo Linux /etc/hosts file entries are auto-generated, when OpenRC hostname service starts. Previously, it is used to edit /etc/hosts manually. In Funtoo Linux there is no such need.

What about custom hosts entries? This can be easily configured with 'aliases'. For example you want to have a hosts for your remote router or a computer in home LAN. Let's try to modify /etc/conf.d/hostname with adding following - my remote computer oleg.distant.home has an IP 10.1.1.2:

oleg-stable ~ #  echo 'aliases="10.1.12 oleg.distant.home"' >> /etc/conf.d/hostname
oleg-stable ~ #  service hostname restart
Examine our changes:
oleg-stable ~ #  cat /etc/hosts
   /etc/hosts
# Auto-generated hostname. Please do not remove this comment.
10.1.1.2        oleg.distant.home
127.0.0.1       oleg-stable.host.funtoo.org oleg-stable localhost localhost.localdomain
::1             oleg-stable.host.funtoo.org oleg-stable localhost localhost.localdomain