Warning: THE VOID WIKI IS DEPRECATED. It is no longer being maintained, contains outdated and incorrect information, and will eventually be shut down. Please refer to the Void Handbook, https://docs.voidlinux.org/, for the official documentation. If you can't find the information you're seeking, please raise an issue at https://github.com/void-linux/void-docs/issues

Difference between revisions of "Network Configuration"

From Void Linux Wiki
Jump to navigation Jump to search
(Explains how to connect to free wifi hotspots offered by commercial establishments that do not have an accompanying WEP / WPA key using the command line.)
m (Duncaen moved page Network Configuration - to Network Configuration without leaving a redirect)
 
(41 intermediate revisions by 10 users not shown)
Line 1: Line 1:
=== Static IP ===
+
As this wiki is deprecated, and will soon disappear, please refer to [https://docs.voidlinux.org/config/network/index.html the "Network" section of the Void Handbook].
 
 
Static IP configuration can either be done through <code>dhcpcd</code> and its configuration file <code>/etc/dhcpcd.conf</code>, or iproute commands in <code>/etc/rc.local</code> (see below). If an ethernet interface was configured at the installer, the <code>dhcpcd.conf</code> file should look like as follows:
 
 
 
<pre># Static IP configuration.
 
interface eth0
 
static ip_address=192.168.1.2
 
static routers=192.168.1.1
 
static domain_name_servers=8.8.8.8 8.8.4.4</pre>
 
The <code>dhcpcd</code> service must be enabled in the <code>default</code> runlevel:
 
 
 
<pre># ln -s /etc/sv/dhcpcd /var/service/</pre>
 
A simpler solution without the need of running the <code>dhcpcd</code> daemon would be to setup the network interface in the file <code>/etc/rc.local</code> via commands from the <code>iproute</code> package:
 
 
 
<pre># Static IP configuration via iproute
 
ip link set dev eth0 up
 
ip addr add 192.168.1.2/24 brd + dev eth0
 
ip route add default via 192.168.1.1</pre>
 
=== Dynamic IP (DHCP) ===
 
 
 
This is handled by the <code>dhcpcd</code> package and its service. To acquire a lease for any known interface simply enable the <code>dhcpcd</code> system service:
 
 
 
<pre># ln -s /etc/sv/dhcpcd /var/service/</pre>
 
=== DHCP per interface ===
 
 
 
The default <code>dhcpcd</code> runit service works in all available network interfaces, but sometimes only a single interface needs to be setup, in that case we'll make another <code>service</code> with some modifications:
 
 
 
<pre># mkdir -p /etc/sv/dhcpcd-eth0
 
# vi /etc/sv/dhcpcd-eth0/run</pre>
 
<pre>      #!/bin/sh
 
      exec dhcpcd -B eth0</pre>
 
<pre># chmod 755 /etc/sv/dhcpcd-eth0/run
 
# ln -s /run/runit/supervise.dhcpcd-eth0  /etc/sv/dhcpcd-eth0/supervise</pre>
 
This <code>new</code> runit service will only work for the <code>eth0</code> device. Now you just need to symlink it to the <code>current</code> runlevel to enable and start it:
 
 
 
<pre># ln -s /etc/sv/dhcpcd-eth0 /var/service/</pre>
 
<blockquote>You can find available network devices by executing <code>ip link</code>.
 
</blockquote>
 
=== Desktop Network Daemons (NetworkManager, wicd and connman) ===
 
 
 
These applications conflict with the methods mentioned above so before using <code>NetworkManager</code>, <code>wicd</code> or <code>conmman</code> make sure that <code>dhcpcd</code> and <code>wpa_supplicant</code> services are stopped and disabled:
 
 
 
<pre># rm -f /var/service/&lt;foo&gt;</pre>
 
or for the per interface service; make sure that none of these services are started by default.
 
 
 
=== NetworkManager-openvpn issues ===
 
 
 
For those having issues with NetworkManager-openvpn not connecting, it seems that the nm-      openvpn user is not added. Do so (make sure dbus, cgmanager and consolekit are installed):
 
<pre># groupadd -r nm-openvpn </pre>
 
<pre># useradd -r -g nm-openvpn -d / -s /sbin/nologin -c "Default user for running openvpn      spawned by NetworkManager" nm-openvpn </pre>
 
 
 
This should take care of it, credits to AnAkkk on the Arch forums!
 
 
 
=== Wireless (default) ===
 
 
 
Wireless connections are handled by the <code>wpa_supplicant</code> package; it can handle multiple kinds of security against the APs: none, WEP, WPA-PSK (WPA Personal), WPA-EAP (WPA Enterprise) and more.
 
 
 
Copy the <code>wpa_supplicant.conf</code> file to match your network device:
 
 
 
<pre>$ cp /etc/wpa_supplicant/wpa_supplicant.conf /etc/wpa_supplicant/wpa_supplicant-&lt;device&gt;.conf</pre>
 
==== WEP ====
 
 
 
Just edit <code>/etc/wpa_supplicant/wpa_supplicant-&lt;device&gt;.conf</code> and add the following lines:
 
 
 
<pre># Default configuration file for wpa_supplicant.conf(5).
 
ctrl_interface=/run/wpa_supplicant
 
ctrl_interface_group=wheel
 
eapol_version=1
 
ap_scan=1
 
fast_reauth=1
 
# Add here your networks.
 
network={
 
    ssid=&quot;MYSSID&quot;
 
    key_mgmt=NONE
 
    wep_key0=&quot;YOUR AP WEP KEY&quot;
 
    wep_tx_keyidx=0
 
    auth_alg=SHARED
 
}</pre>
 
==== WPA-PSK (WPA Personal) ====
 
 
 
For <code>WPA-PSK</code> we must generate the <code>pre shared key</code> with <code>wpa_passphrase(8)</code>:
 
 
 
<pre>$ wpa_passphrase MYSSID key</pre>
 
Just append the resulting output from the above command to <code>/etc/wpa_supplicant/wpa_supplicant-&lt;device&gt;.conf</code>:
 
 
 
<pre># Default configuration file for wpa_supplicant.conf(5).
 
ctrl_interface=/run/wpa_supplicant
 
ctrl_interface_group=wheel
 
eapol_version=1
 
ap_scan=1
 
fast_reauth=1
 
# Add here your networks.
 
network={
 
    ssid=&quot;MYSSID&quot;
 
    #psk=&quot;YOUR AP KEY&quot;
 
    psk=a8c34100ab4e5afac33cad7184d45a29ee0079001577d579bec6b74e4d7b5ac8
 
}</pre>
 
 
 
==== Starting <code>wpa_supplicant</code> ====
 
 
 
You can now enable the <code>dhcpcd</code> service, which has a hook to start wpa_supplicant, and use the <code>wpa_cli(8)</code> command to see details of this AP connection.
 
 
 
<pre>Note: Behaviour changed in dhcpcd-6.10.0-1: The hook is not enabled by default anymore.</pre>
 
 
 
Check which version you are using (<code>$ dhcpcd --version</code>). If you're using 6.10.0-1 or newer you have to enable the <code>wpa_supplicant</code> hook:
 
 
 
<pre>$ sudo ln -s /usr/share/dhcpcd/hooks/10-wpa_supplicant /usr/libexec/dhcpcd-hooks</pre>
 
 
 
If you happen to need a special driver (option -D) you can edit <code>/etc/dhcpcd.conf</code> and add a line like <code>env wpa_supplicant_driver=wext</code>.
 
 
 
After enabling this hook, don't forget to restart <code>dhcpcd</code>: <code>$ sudo sv restart dhcpcd</code>.
 
 
 
If <code>wpa_supplicant</code> is still not starting after this, try starting it from the command line (<code>$ sudo wpa_supplicant -i &lt;device&gt; -c /etc/wpa_supplicant/wpa_supplicant-&lt;device&gt;.conf</code>) to see if you get any errors.
 
 
 
=== Connecting to hotel / restaurant / airport hotspots via the command line ===
 
 
 
Oftentimes, wifi hotspots in various public places don't have an accompanying WPA / WEP key. They require you to connect to their ESSID, obtain an IP address, and subsequently log in via a web interface of some sort. To do this, follow these simple steps:
 
 
 
Step 1: stop the current dhcpcd service if it's running.
 
<pre>$ sudo sv stop dhcpcd</pre>
 
 
 
Step 2: bring up your wireless NIC.
 
<pre>$ sudo ip link set <device> up</pre>
 
 
 
Replace <device> with the name assigned to your wireless card. If you don't know its name, you can use the <code>ip a</code> or <code>ip link</code> command.
 
 
 
Step 3: connect the ESSID of the establishment.
 
<pre>$ sudo iw dev <device> connect -w "AwesomeHotel"</pre>
 
 
 
The <code>-w</code> option waits until the connection either succeeds or an error occurs.
 
 
 
Step 4: obtain an IP address from the network
 
<pre>$ sudo dhcpcd <device></pre>
 
 
 
You should now be able to fire up your favourite web browser and log into the network normally.
 
 
 
 
 
=== Wireless (NetworkManager) ===
 
 
 
Install required packages:
 
<pre>
 
# xbps-install NetworkManager network-manager-applet gnome-icon-theme inetutils-ifconfig gnome-keyring
 
</pre>
 
 
 
If you want messages about the state:
 
<pre>
 
# xbps-install xfce4-notifyd
 
</pre>
 
 
 
Remove dhcpcd and wpa_supplicant services:
 
 
 
<pre>
 
# rm -fr /var/service/dhcpcd
 
# rm -fr /var/service/wpa_supplicant
 
</pre>
 
 
 
Include new services:
 
 
 
<pre>
 
# ln -s /etc/sv/NetworkManager /var/service
 
# ln -s /etc/sv/dbus /var/service
 
</pre>
 
 
 
The <code>nm-applet</code> requires some privileges, so, in the same way explained above (NetworkManager-openvpn issues):
 
<pre>
 
# groupadd -r nm-applet
 
# useradd -r -g nm-applet -d / -s /sbin/nologin -c "Default user for running nm-applet spawned by NetworkManager" nm-applet
 
</pre>
 
 
 
Start <code>nm-applet</code> in the desktop manager start file:
 
 
 
<pre>nm-applet &</pre>
 
 
 
The applet would show in the system tray. If your desktop manager doesn't have one, look for <code>stalonetray</code> or <code>trayer-srg</code> which are include in voidlinux.
 
 
 
 
 
(See also: <code>dhcpcd(8)</code>, <code>dhcpcd-run-hooks(8)</code>)
 
 
 
[[Category:Guides]]
 

Latest revision as of 14:33, 13 June 2020

As this wiki is deprecated, and will soon disappear, please refer to the "Network" section of the Void Handbook.