Skip to content

Setting Up an IP address in Arch Linux

In this article

Note

Network interfaces in Arch Linux are configured through the systemd-networkd system or the ip tool.

Configuring DHCP Using systemd-networkd

To configure automatic IP address acquisition via the DHCP protocol, follow these steps:

1. Preparation

Ensure that the systemd-networkd service is installed, enabled, and running. You can check this with the following command:

systemctl status systemd-networkd

If the service is not enabled, run:

systemctl enable --now systemd-networkd

2. Creating a Configuration File

In the /etc/systemd/network/ directory, create a configuration file for the network interface. If the directory doesn't exist, create it manually:

mkdir -p /etc/systemd/network

Create a file, such as /etc/systemd/network/20-wired.network, and add the following configuration:

vi /etc/systemd/network/20-wired.network
[Match]
Name=ens1

[Network]
DHCP=yes

Note

Replace ens1 with your network interface name. You can find the interface name using the command ip link.

3. Restarting the Service

After making changes, restart systemd-networkd to apply the settings:

systemctl restart systemd-networkd

4. Checking the Connection

Ensure that the IP address was successfully acquired:

ip addr show ens1

The command output should display a line containing the obtained IP address:

5. Troubleshooting

If the connection doesn't work:

  1. Check the systemd-networkd service log for detailed error information:

    journalctl -u systemd-networkd
    
  2. Make sure that the resolved configuration is set up correctly, and the systemd-resolved service is running:

    systemctl enable --now systemd-resolved
    

    Check the symbolic link to the /etc/resolv.conf file:

    ls -l /etc/resolv.conf
    

    If the file isn't configured, create a link:

    bash ln -sf /run/systemd/resolve/resolv.conf /etc/resolv.conf

Configuring a Static IP Address

Example configuration for a static IP address on the ens1 interface:

  1. Create or modify the /etc/systemd/network/20-wired.network file with the following content:

    [Match]
    Name=ens1
    
    [Network]
    Address=192.168.1.100/24
    Gateway=192.168.1.1  # Specify your gateway IP address
    DNS=8.8.8.8 8.8.4.4
    
    • Address: Set the static IP address for your device. In this example, 192.168.1.100 is used.
    • Gateway: Specify the IP address of your network gateway. This is usually the IP address of your router, e.g., 192.168.1.1.
    • DNS: Specify DNS servers. In this example, public Google DNS servers are used.
  2. Apply the settings by restarting the systemd-networkd service:

    systemctl restart systemd-networkd
    
  3. Verify that the settings are applied correctly:

    ip addr show ens1
    

You should see the specified IP address in the list:

Attention

To ensure proper functionality of the DNS parameter, make sure systemd-resolved is enabled and running:

systemctl enable --now systemd-resolved 

If necessary, configure /etc/resolv.conf as a symbolic link to systemd-resolved:

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

Applying the Configuration

After setting up the network, you can check its status using the command:

ip addr show 
Or view routing parameters:

ip route show  
For more information, refer to the official Arch Linux documentation.