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

How To Configure Static And Dynamic IP Address In Arch Linux

By sk
Published: Last Updated on 79.1K views

This brief tutorial describes how to configure static and dynamic IP address in Arch Linux and its derivatives like EndeavourOS and Manjaro Linux.

Configure Static IP Address in Arch Linux

We can configure static IP address in two methods. We will see both.

Method 1: Assign 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.

As you might already know, the sample network configuration files will be stored under /etc/netctl/examples/ location in Arch Linux.

$ ls /etc/netctl/examples/

Sample output:

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

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.

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

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

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

Replace enp0s3 with your network card name.

Now, edit the network config file:

$ sudo nano /etc/netctl/enp0s3

Enter 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 eth0 with your actual network card name (i.e enp0s3 in our case) in the above configuration file. Save and close the file.

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

$ sudo netctl enable enp0s3

Finally, start the network profile as shown below.

$ sudo netctl start enp0s3

Stop and disable dhcp service.

$ sudo systemctl stop dhcpcd
$ sudo systemctl disable dhcpcd

Restart your system to take effect the changes.

Now, verify the static IP address using command:

$ ip addr

Sample output would be:

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.

Method 2: Set Static IP Address in Arch Linux using systemd

systemd is a system and service manager for Linux operating systems. Let us now see how to configure static IP address using systemd.

Create a network profile like below.

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

Replace enp0s3 with your network card's name. And, 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

Save and close the file.

Next, you need to disable netctl. To find out what is enabled that is netctl related, run the following command:

$ sudo systemctl list-unit-files

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, 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

Then, 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

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 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

Edit /etc/netctl/enp0s3 file:

$ sudo vi /etc/netctl/enp0s3

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

Hope this helps.

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