Difference between pages "Hostname" and "Install/pt-br/Network"

From Funtoo
(Difference between pages)
Jump to navigation Jump to search
 
(Created page with "=== Configuring your network === It's important to ensure that you will be able to connect to your local-area network after you reboot into Funtoo Linux. There are three appr...")
 
Line 1: Line 1:
w.i.p
=== Configuring your network ===
==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.
It's important to ensure that you will be able to connect to your local-area network after you reboot into Funtoo Linux. There are three approaches you can use for configuring your network: NetworkManager, dhcpcd, and the [[Funtoo Linux Networking]] scripts. Here's how to choose which one to use based on the type of network you want to set up.
==Configuration==
 
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:
==== Wi-Fi ====
===== Using NetworkManager =====
For laptop/mobile systems where you will be using Wi-Fi and connecting to various networks, NetworkManager is strongly recommended. The Funtoo version of NetworkManager is fully functional even from the command-line, so you can use it even without X or without the Network Manager applet. Here are the steps involved in setting up NetworkManager:
 
<console>
<console>
localhost ~ # ##i## Hello :)
(chroot) # ##i##emerge linux-firmware
(chroot) # ##i##emerge networkmanager
(chroot) # ##i##rc-update add NetworkManager default
</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.
 
Above, we installed linux-firmware which contains a complete collection of available firmware for many hardware devices including Wi-Fi adapters, plus NetworkManager to manage our network connection. Then we added NetworkManager to the <code>default</code> runlevel so it will start when Funtoo Linux boots.
 
After you reboot into Funtoo Linux, you will be able to add a Wi-Fi connection this way:
 
{{Note|The following command will not work as long as you are in chroot environment. The reason for this is that addwifi will need dbus and rfkill to be set up. So don't forget to reboot!}}
 
<console>
<console>
localhost ~ # ##i## nano /etc/conf.d/hostname
# ##i##addwifi -S wpa -K 'wifipassword' mywifinetwork
</console>
</console>
Let's set it to hostname="oleg-stable.host.funtoo.org". Save the file and restart  a hostname service:
 
The <code>addwifi</code> command is used to configure and connect to a WPA/WPA2 Wi-Fi network named <code>mywifinetwork</code> with the password <code>wifipassword</code>. This network configuration entry is stored in <code>/etc/NetworkManager/system-connections</code> so that it will be remembered in the future. You should only need to enter this command once for each Wi-Fi network you connect to.
 
===== Using wpa_supplicant =====
If for some reason you don't want to use a tool such as NetworkManager or <code>wicd</code>, you can use wpa_supplicant for wireless network connections.
 
First, emerge wpa_supplicant:
 
<console>
<console>
localhost ~ # ##i## service hostname restart
(chroot) ###i## emerge -a wpa_supplicant
</console>
</console>
Now, let's examine our changes, after a restarting a hostname
 
Now, edit the wpa_supplicant configuration file, located at /etc/wpa_supplicant/wpa_supplicant.conf.
The syntax is very easy:
<pre>
network={
ssid="MyWifiName"
psk="lol42-wifi"
}
 
network={
ssid="Other Network"
psk="6d96270004515a0486bb7f76196a72b40c55a47f"
}
</pre>
 
You will need to add both <code>wpa_supplicant</code> and <code>dhcpcd</code> to the default runlevel. <code>wpa_supplicant</code> will connect to your access point, and <code>dhcpcd</code> will acquire an IP address via DHCP:
 
<console>
<console>
oleg-stable ~ # ##i## Hello :)
(chroot) # ##i##rc-update add dhcpcd default
(chroot) # ##i##rc-update add wpa_supplicant default
</console>
</console>
== 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
==== Desktop (Wired Ethernet) ====
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>
For a home desktop or workstation with wired Ethernet that will use DHCP, the simplest and most effective option to enable network connectivity is to simply add <code>dhcpcd</code> to the default runlevel:
oleg-stable ~ # ##i## hostname
 
oleg-stable.host.funtoo.org
</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.
<console>
oleg-stable ~ # ##i## hostname -s
oleg-stable
</console>
Good! Hostname offers more then just displaying a system host name but can also set one. Let's try:
<console>
<console>
oleg-stable ~ # ##i## hostname foo.bar.baz
(chroot) # ##i##rc-update add dhcpcd default
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.}}


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.
When you reboot, <code>dhcpcd</code> will run in the background and manage all network interfaces and use DHCP to acquire network addresses from a DHCP server.


==Hosts case==
==== Server (Static IP) ====
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
{{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:
For servers, the [[Funtoo Linux Networking]] scripts are recommended. They are optimized for static configurations and things like virtual ethernet bridging for virtualization setups. See [[Funtoo Linux Networking]] for information on how to use Funtoo Linux's template-based network configuration system.
<console>
oleg-stable ~ # ##i## echo 'aliases="10.1.12 oleg.distant.home"' >> /etc/conf.d/hostname
oleg-stable ~ # ##i## service hostname restart
</console>
Examine our changes:
<console>
oleg-stable ~ # ##i## cat /etc/hosts
</console>
{{file|name=/etc/hosts|body=
# 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
}}

Revision as of 15:39, March 2, 2015

Configuring your network

It's important to ensure that you will be able to connect to your local-area network after you reboot into Funtoo Linux. There are three approaches you can use for configuring your network: NetworkManager, dhcpcd, and the Funtoo Linux Networking scripts. Here's how to choose which one to use based on the type of network you want to set up.

Wi-Fi

Using NetworkManager

For laptop/mobile systems where you will be using Wi-Fi and connecting to various networks, NetworkManager is strongly recommended. The Funtoo version of NetworkManager is fully functional even from the command-line, so you can use it even without X or without the Network Manager applet. Here are the steps involved in setting up NetworkManager:

(chroot) # emerge linux-firmware
(chroot) # emerge networkmanager
(chroot) # rc-update add NetworkManager default

Above, we installed linux-firmware which contains a complete collection of available firmware for many hardware devices including Wi-Fi adapters, plus NetworkManager to manage our network connection. Then we added NetworkManager to the default runlevel so it will start when Funtoo Linux boots.

After you reboot into Funtoo Linux, you will be able to add a Wi-Fi connection this way:

   Note

The following command will not work as long as you are in chroot environment. The reason for this is that addwifi will need dbus and rfkill to be set up. So don't forget to reboot!

root # addwifi -S wpa -K 'wifipassword' mywifinetwork

The addwifi command is used to configure and connect to a WPA/WPA2 Wi-Fi network named mywifinetwork with the password wifipassword. This network configuration entry is stored in /etc/NetworkManager/system-connections so that it will be remembered in the future. You should only need to enter this command once for each Wi-Fi network you connect to.

Using wpa_supplicant

If for some reason you don't want to use a tool such as NetworkManager or wicd, you can use wpa_supplicant for wireless network connections.

First, emerge wpa_supplicant:

(chroot) # emerge -a wpa_supplicant

Now, edit the wpa_supplicant configuration file, located at /etc/wpa_supplicant/wpa_supplicant.conf. The syntax is very easy:

network={
ssid="MyWifiName"
psk="lol42-wifi"
}

network={
ssid="Other Network"
psk="6d96270004515a0486bb7f76196a72b40c55a47f"
}

You will need to add both wpa_supplicant and dhcpcd to the default runlevel. wpa_supplicant will connect to your access point, and dhcpcd will acquire an IP address via DHCP:

(chroot) # rc-update add dhcpcd default
(chroot) # rc-update add wpa_supplicant default

Desktop (Wired Ethernet)

For a home desktop or workstation with wired Ethernet that will use DHCP, the simplest and most effective option to enable network connectivity is to simply add dhcpcd to the default runlevel:

(chroot) # rc-update add dhcpcd default

When you reboot, dhcpcd will run in the background and manage all network interfaces and use DHCP to acquire network addresses from a DHCP server.

Server (Static IP)

For servers, the Funtoo Linux Networking scripts are recommended. They are optimized for static configurations and things like virtual ethernet bridging for virtualization setups. See Funtoo Linux Networking for information on how to use Funtoo Linux's template-based network configuration system.