Home Linux Networking How To Configure Static IP And Dynamic IP Address In Arch Linux

How To Configure Static IP And Dynamic IP Address In Arch Linux

Arch Linux Networking: A Step-by-Step Guide to Set Static and Dynamic IP Address

By sk
Published: Last Updated on 80K views

This step-by-step tutorial explains how to configure static IP and dynamic IP address in Arch Linux and its derivatives like EndeavourOS and Manjaro Linux.

To configure an IP address in Arch Linux, you generally have two main methods: using the command line interface directly or setting it through a network management service like netctl or systemd-networkd or NetworkManager.

First, we will discuss the netctl way of configuring static IP address in Arch Linux.

Method 1 : Configure Static IP Address in Arch Linux using netctl

Netctl is a command-line utility that can be used to introspect and control the state of the systemd services for the network profile manager.

It’s particularly useful on systems without NetworkManager or systemd-networkd, and it provides a simple and straightforward way to manage network connections using profiles.

Step 1: Identify Network Adaptor

Identify your network interface name with ip link or ls /sys/class/net commands.

First let us find our network card name. To do so, run:

$ ip link

Sample output:

1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN mode DEFAULT group default qlen 1
 link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
2: enp0s3: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc fq_codel state UP mode DEFAULT group default qlen 1000
 link/ether 08:00:27:db:14:7a brd ff:ff:ff:ff:ff:ff
$ ls /sys/class/net
enp0s3 lo

As you see in the above output, my network card name is enp0s3.

Step 2: Install Netctl

Netctl is usually installed by default on Arch Linux. If for some reason it's not installed, you can install it using the package manager:

$ sudo pacman -S netctl

Step 3: Create a Profile

Netctl profiles are located in /etc/netctl/. You can start by copying a sample profile and editing it to fit your requirements.

The sample network configuration files will be stored under /etc/netctl/examples/ location in Arch Linux.

$ ls /etc/netctl/examples/

Sample Output:

bonding          macvlan-static  vlan-dhcp      wireless-wpa-config
bridge mobile_ppp vlan-static wireless-wpa-configsection
ethernet-custom openvswitch wireguard wireless-wpa-static
ethernet-dhcp pppoe wireless-open
ethernet-static tunnel wireless-wep
macvlan-dhcp tuntap wireless-wpa

As you see in the above output, ethernet-static and ethernet-dhcp files are the sample Ethernet profiles. You will also see the wireless network profiles in that location as well.

Copy a sample profile:

Now, Copy the sample network card profile from /etc/netctl/examples/ directory to /etc/netctl/ directory as shown below.

$ sudo cp /etc/netctl/examples/ethernet-static /etc/netctl/enp0s3-static

Replace enp0s3 with your network card name.

Edit the profile:

Now, edit the network config file:

$ sudo nano /etc/netctl/enp0s3-static

Update your IP address, Netmask, gateway, and DNS server details as shown below.

Description='A basic static ethernet connection'
Interface=enp0s3
Connection=ethernet
IP=static
Address=('192.168.1.102/24')
Gateway=('192.168.1.1')
DNS=('8.8.8.8' '8.8.4.4')

You must replace enp0s3 with your actual network card name (i.e enp0s3 in our case) in the above configuration file. Save and close the file.

Step 4: Enable and Start the Profile

Enable the network profile to start automatically on every reboot with command:

$ sudo netctl enable enp0s3-static

Finally, start the network profile as shown below.

$ sudo netctl start enp0s3-static

Stop and disable dhcp service if they are running already.

$ sudo systemctl stop dhcpcd
$ sudo systemctl disable dhcpcd

Restart your system to take effect the changes.

Step 5: Verify the Configuration

After starting the profile, check that the configuration is correct and that the network interface has the correct IP settings:

Now, verify the static IP address using command:

$ ip addr

Sample Output:

1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN group default qlen 1
 link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
 inet 127.0.0.1/8 scope host lo
 valid_lft forever preferred_lft forever
 inet6 ::1/128 scope host 
 valid_lft forever preferred_lft forever
2: enp0s3: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc fq_codel state UP group default qlen 1000
 link/ether 08:00:27:db:14:7a brd ff:ff:ff:ff:ff:ff
 inet 192.168.1.102/24 brd 192.168.1.255 scope global enp0s3
 valid_lft forever preferred_lft forever
 inet6 fe80::367c:d479:4d21:cede/64 scope link 
 valid_lft forever preferred_lft forever

As you see in the above output, static IP address (192.168.1.102) has been assigned to the network card.

You can also directly specify the name of the interface like below:

$ ip addr show enp0s3

Replace enp0s3 with the name of your network interface.

Netctl is particularly popular for use with simple or static network configurations and on systems like laptops where simple switching between multiple networks (e.g., home and work networks) is necessary.

Method 2 : Using systemd-networkd for Assigning Static IP Address in Arch Linux

systemd-networkd is a system daemon that manages network configurations. Here are the steps to set up a static IP address using this method:

Disable and stop NetworkManager (if it is installed and running):

$ sudo systemctl stop NetworkManager
$ sudo systemctl disable NetworkManager

Enable and start systemd-networkd:

$ sudo systemctl enable systemd-networkd
$ sudo systemctl start systemd-networkd

Identify your network interface name using any one of the following commands:

$ ip link

Or,

$ ls /sys/class/net

Create a new configuration file in /etc/systemd/network/, for example, enp0s3.network, adjusting it for your interface and network settings:

$ sudo nano /etc/systemd/network/enp0s3.network

Add the following lines:

[Match]
Name=enp0s3

[Network]
Address=192.168.1.102/24
Gateway=192.168.1.1
DNS=8.8.8.8
DNS=8.8.4.4

Replace eth0 with your actual interface name, and adjust the IP address, gateway, and DNS as necessary.

Save and close the file.

Next, you need to disable all netctl-related services or units if they are already running.

To see all the netctl profiles that are enabled, you can use a combination of systemctl and grep:

$ sudo systemctl list-unit-files | grep enabled | grep netctl

This command lists all unit files, filters those that are enabled, and further filters to show only netctl-related entries.

Once you identify all netctl related stuff, disable all of them. I had the following service enabled in my system, so I disabled it as shown below.

$ sudo systemctl disable netctl@enp0s3.service

And then, remove netctl package from your Arch Linux using command:

$ sudo pacman -Rns netctl

Also, don't forget to stop and disable dhcp service.

$ sudo systemctl stop dhcpcd
$ sudo systemctl disable dhcpcd

Finally, enable and start systemd-networkd service as shown below:

$ sudo systemctl enable systemd-networkd
$ sudo systemctl start systemd-networkd

Reboot your system. And, check if IP address is correctly assigned using command:

$ ip addr

Method 3 : Configure Static IP address using NetworkManager in Arch Linux

If you prefer using NetworkManager, which provides a more user-friendly and flexible interface, follow these steps:

Ensure NetworkManager is installed and enabled:

$ sudo pacman -S networkmanager
$ sudo systemctl enable NetworkManager
$ sudo systemctl start NetworkManager

Use nmcli to configure the static IP:

Find your connection name:

$ nmcli con show

For instance, if the connection name is "Wired connection 1", you need to modify the connection settings like below:

$ sudo nmcli con mod "Wired connection 1" ipv4.addresses 192.168.1.24/24
$ sudo nmcli con mod "Wired connection 1" ipv4.gateway 192.168.1.101
$ sudo nmcli con mod "Wired connection 1" ipv4.dns "8.8.8.8,1.1.1.1"
$ sudo nmcli con mod "Wired connection 1" ipv4.method manual

You can also set all details in a single command like below.

$ sudo nmcli connection modify 'Wired connection 1' ip4 192.168.1.24/24 gw4 192.168.1.101 ipv4.dns 8.8.8.8

Replace "Wired connection 1" with your actual connection name.

Next, find and disable all the netctl profiles that are enabled on your Arch Linux system as described in the previous section.

And them, disable and stop systemd-networkd service as shown below:

$ sudo systemctl disable systemd-networkd
$ sudo systemctl stop systemd-networkd

If you change a service file or any other unit configuration, reloading the daemon is necessary to apply those changes.

$ sudo systemctl daemon-reload

Finally, Restart NetworkManager to apply the changes:

$ sudo systemctl restart NetworkManager

Warning:
Be aware that having multiple network managers active at the same time (like netctl, systemd-networkd, and NetworkManager) can lead to conflicting configurations. Make sure to disable or uninstall others and use only one network manager as your primary network manager at a time.

Each method has its own advantages, depending on whether you prefer more control over your network configurations (netctl or systemd-networkd) or an easier, more graphical approach (NetworkManager). Choose the one that best fits your needs.

You know now how to configure static IP address. Next, we will see how to assign dynamic ip address to a network card.

Configure Dynamic IP Address in Arch Linux using Netctl

First, Install netctl package if it is not installed already.

$ sudo pacman -S netctl

Copy ethernet-dhcp profile from /etc/netctl/examples/ directory to /etc/netctl/ directory as shown below.

$ sudo cp /etc/netctl/examples/ethernet-dhcp /etc/netctl/enp0s3-dhcp

Edit /etc/netctl/enp0s3 file:

$ sudo vi /etc/netctl/enp0s3

Update the network interface's name in the configuration file. Replace eth0 with your actual network interface name i.e enp0s3.

Description='A basic dhcp ethernet connection'
Interface=enps03
Connection=ethernet
IP=dhcp
#DHCPClient=dhcpcd
#DHCPReleaseOnStop=no
## for DHCPv6
#IP6=dhcp
#DHCP6Client=dhclient
## for IPv6 autoconfiguration
#IP6=stateless

Save and close the file.

Enable and start dhcpcd service:

$ sudo systemctl enable dhcpcd
$ sudo systemctl start dhcpcd

Reboot your system. Verify IP address using the following command:

$ ip addr

Conclusion

In this detailed tutorial, we discussed three methods to configure static IP address in Arch Linux and its variants. Additionally, we explained the steps to configure dynamic (DHCP) ip address in Arch Linux.

Whether you prefer using netctl, systemd-networkd, or NetworkManager, each tool offers a reliable way to set up a fixed IP configuration.

systemd-networkd is ideal for users looking for a lightweight and straightforward approach, handling network settings directly through systemd.

NetworkManager provides a more interactive and GUI-friendly experience, suitable for desktop environments and users who appreciate a graphical interface.

On the other hand, netctl excels in simplicity and effectiveness, particularly favored for its ease of use in managing profiles for both static and dynamic IP setups.

Related Read:

You May Also Like

7 comments

Kevin February 13, 2018 - 3:17 am

Thanks a lot for this. The last but one command at the end of the post (in the configure dynamic IP address section) should probably be `sudo systemctl start dhcpcd` (i.e. not stop).

Reply
sk February 13, 2018 - 1:50 pm

Good catch. Fixed now. Thanks.

Reply
asd October 18, 2018 - 6:51 pm

thank you very much.

Reply
yassine June 7, 2019 - 4:00 am

U saved my life thank u very much

Reply
Manfred April 1, 2020 - 8:51 pm

Thank you very much ! 🙂

Reply
tux September 11, 2022 - 9:28 am

netctl not found

Reply
sk September 11, 2022 - 11:08 am

Install it using the following command:

sudo pacman -S netctl

Reply

Leave a Comment

* By using this form you agree with the storage and handling of your data by this website.

This site uses Akismet to reduce spam. Learn how your comment data is processed.

This website uses cookies to improve your experience. By using this site, we will assume that you're OK with it. Accept Read More