Saturday, April 5, 2025

Arch Linux: Network interfaces configuration options

If the adapter is in the DOWN status and the OS does not have netctl, networkmanager packages, you can temporarily configure the network as follows:

1. Display the current network interfaces:
ip link show

2. Raise the interface (in our case "ens33"):
sudo ip link set dev ens33 up

3. Configure the TCP/IP configuration, use the following commands as needed:

ip link show   #View network connections
ip -s l   #View statistics on sent/received packets
ip address show   #View TCP/IP configuration
ip link set dev ens33 up   #Enable the interface if it was disabled
ip address flush dev ens33   #Reset interface configuration
ip addr add 192.168.0.5/24 broadcast + dev ens33   #Set IP and mask
ip addr del 192.168.0.5/24 dev ens33   #Delete IP and mask (in case of error)
ip route show   #View routing table
ip route add default via 192.168.0.1 dev ens33   #Set default gateway
ip route delete default   #Delete default gateway
ip route add 192.168.10.0/24 via 192.168.0.254 dev ens33   #Add route
ip route del 192.168.10.0/24 dev ens33   #Delete route
echo "nameserver 192.168.0.1 8.8.8.8" | sudo tee /etc/resolv.conf   #Add DNS


Configuring an interface with "netctl":

1. Install "netctl" and "dhcpcd" if you want to use DHCP:
sudo pacman -S netctl dhcpcd

2. Copy the profile for your interface from the examples folder:
cd /etc/netctl
sudo cp examples/ethernet-static my-network
   #For static IP
sudo cp examples/ethernet-dhcp my-network   #For DHCP

3. Edit the file:
sudo nano my-network

Specify the correct interface (in our example - "ens33"), and in case of a static address: IP address, mask, default gateway, additional routes if necessary.

With DNS, there may be the following options:
- if you use the parameter from the "my-network" file, then you will need to start the "systemd-resolved" service:
sudo systemctl enable --now systemd-resolved
- if you use "/etc/resolv.conf" with the "nameserver" parameter, then leave the "DNS" parameter commented out, in this case you can completely disable the services:
sudo systemctl mask systemd-resolved
sudo systemctl mask systemd-networkd


4. Run our profile and enable autoload:
sudo netctl start my-network
sudo netctl enable my-network



Configuring the interface using "NetworkManager":

1. Install NetworkManager:
sudo pacman -S networkmanager

2. Enable and start the service:
sudo systemctl enable --now NetworkManager

3. Configure the network interface using the terminal utility "nmtui" or on the command line with the utility "nmcli":

View:
nmcli con show   #View network connections
nmcli dev show ens33   #View active connection on "ens33"
nmcli con show 'Wired connection 1'   #View connection parameters


Configuration for DHCP:
nmcli con mod 'Wired connection 1' ipv4.method auto
nmcli con mod 'Wired connection 1' ipv4.addresses "" ipv4.gateway ""
nmcli con mod 'Wired connection 1' ipv4.dns ""
nmcli con mod 'Wired connection 1' ipv4.routes ""
nmcli con up 'Wired connection 1'


Configuration for static IP:
nmcli con mod 'Wired connection 1' ipv4.addresses 192.168.0.5/24
nmcli con mod 'Wired connection 1' ipv4.gateway 192.168.0.1
nmcli con mod 'Wired connection 1' ipv4.dns "192.168.0.1 8.8.8.8"
nmcli con mod 'Wired connection 1' +ipv4.routes "192.168.10.0/24 192.168.0.254"
nmcli con mod 'Wired connection 1' ipv4.method manual
nmcli con up 'Wired connection 1'


The situation with DNS is the same as with the "netctl" method.
If the "systemd-resolved" service is running, then name resolution will work.
If not, use the "/etc/resolv.conf" file:
echo "nameserver 192.168.0.1 8.8.8.8" | sudo tee /etc/resolv.conf
In case of an error, first delete the file ("sudo rm -f /etc/resolv.conf") and repeat.


Configuring the interface with "systemd-networkd":

1. Make sure that the "systemd-networkd" and "systemd-resolved" services are running and are in autostart:
sudo systemctl enable --now systemd-networkd
sudo systemctl enable --now systemd-resolved


2. Create a configuration file (the ".network" extension is required):
sudo nano /etc/systemd/network/20-wired.network

DHCP settings:

[Match]
Name=ens33
[Network]
DHCP=ipv4


Static IP settings:

[Match]
Name=ens33
[Network]
Address=192.168.0.5/24
Gateway=192.168.0.1
DNS=192.168.0.1 8.8.8.8
[Route]
Destination=192.168.10.0/24
Gateway=192.168.0.254
Metric=10   #Optional


3. Restart the service:
sudo systemctl restart systemd-networkd

The situation with DNS is the same as with the "netctl" method.
If the "systemd-resolved" service is running, then name resolution will work.
If not, use the "/etc/resolv.conf" file:
echo "nameserver 192.168.0.1 8.8.8.8" | sudo tee /etc/resolv.conf
In case of an error, first delete the file ("sudo rm -f /etc/resolv.conf") and repeat.


General tips:
1. Do not use multiple network managers at the same time (select one).
2. To view the parameters, use the commands:
ip link show
ip address show
ip route show
resolvectl status

No comments:

Post a Comment