archlinux

27 - Network configuration

Previous: Reboot the system

References:


Login as a regular user and use sudo to execute commands as superuser.

We will configure the network to connect automatically to the internet.

First, we describe two options for network manager:

NetworkManager

(Alternative to Systemd-networkd) Use networkmanager as the network manager (we have already installed it):

Enable

sudo systemctl enable NetworkManager.service --now

After reboot, check status with

systemctl status NetworkManager.service

(Wired) Ethernet connections with DHCP are automatically configured and should work out of the box (NetworkManager will auto-connect in the future).

Systemd-networkd

(Alternative to NetworkManager) Use systemd-networked as the network manager:

Networkd is already installed on the computer as it is part of systemd.

(Wired) Create a config file for a wired adapter with

sudo nano /etc/systemd/network/20-wired.network

(Wired) Add (replace enp3s0f0 accordingly)

[Match]
Name=enp3s0f0

[Link]
RequiredForOnline=routable

[Network]
DHCP=yes
MulticastDNS=yes

(Wireless) Create a config file for a wireless adapter with

sudo nano /etc/systemd/network/25-wireless.network

(Wireless) Add (replace wlan0 accordingly)

[Match]
Name=wlan0

[Link]
RequiredForOnline=routable

[Network]
DHCP=yes
MulticastDNS=yes
IgnoreCarrierLoss=3s

Enable

sudo systemctl enable systemd-networkd.service --now

After reboot, check status with

networkctl

and

networkctl status

Wireless authentication

(With Systemd-networkd only) Use iwd to authenticate (we have already installed it):

Enable

sudo systemctl enable iwd.service --now

After reboot, check status with

systemctl status iwd.service

DNS configuration

(With NetworkManager or Systemd-networkd) Use systemd-resolved to manage DNS:

Resolved is already installed on the computer as it is part of systemd.

Enable

sudo systemctl enable systemd-resolved.service --now

Replace /etc/resolve.conf with a symbolic link to stub-resolv.conf:

sudo ln -sf /run/systemd/resolve/stub-resolv.conf /etc/resolv.conf

After reboot, check status with

resolvectl

mDNS configuration

Use systemd-resolved to manage mDNS:

It is enabled by default with systemd-resolved. The interfaces must be configured to use mDNS as described above (with MulticastDNS=yes).

After reboot, try local DNS resolution with (replace myhostname accordingly)

ping -c 3 myhostname.local

Timesyncd

(With NetworkManager or Systemd-networkd) Use systemd-timesync to manage time synchromization:

Timesyncd is already installed on the computer as it is part of systemd.

Edit the config file with

sudo nano /etc/systemd/timesyncd.conf

Add

NTP=time.google.com

Enable

sudo systemctl enable systemd-timesyncd.service --now

After reboot, check status with

timedatectl status

or

timedatectl timesync-status --all

Connect to wifi

Iwd

(With Systemd-networkd and iwd only) Use the client iwctl:

First, check for software blocks (to avoid errors):

rfkill list

Look for “Soft blocked: yes” or “Hard blocked: yes” next to your wireless device. Unblock the device (actually, all the devices):

rfkill unblock all

Run rfkill list again to confirm that the block is gone.

In the command line, enter the following (replace wlan0 and SSID accordingly):

iwctl
device list
station wlan0 scan
station wlan0 get-networks
station wlan0 connect SSID
station wlan0 show
quit

Note: To connect to a network with spaces in the SSID, the network name should be double quoted (for example, “my network”).

The program iwd automatically stores network passphrases in the /var/lib/iwd directory and uses them to auto-connect in the future.

Internet connection should work. Check the connection with

ping -c 3 www.google.com

NetworkManager

(With NetworkManager only) Use the client nmcli:

In the command line, enter the following commands (replace SSID and mypassword accordingly):

nmcli device wifi list
nmcli device wifi connect SSID password mypassword
nmcli connection show

Internet connection should work (and NetworkManager will auto-connect in the future). Check the connection with

ping -c 3 www.google.com

Check status

To verify that automatic connection is working, reboot the system:

sudo reboot

Login as user an execute the following commands (verify the output):

ping -c 3 www.google.com

(With Systemd-networkd and iwd only) :

networkctl
networkctl status
systemctl status iwd.service

(With NetworkManager or Systemd-networkd) (replace myhostname accordingly):

resolvectl
ping -c 3 myhostname.local
timedatectl status
timedatectl timesync-status --all

To check swap, execute

systemctl status systemd-zram-setup@zram0.service
zramctl
swapon --show

Next: Install a graphical environment