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.
7 comments
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).
Good catch. Fixed now. Thanks.
thank you very much.
U saved my life thank u very much
Thank you very much ! 🙂
netctl not found
Install it using the following command:
sudo pacman -S netctl