How To Configure Static And Dynamic IP Address In Arch Linux

Configure Static And Dynamic IP Address In Arch Linux

This brief tutorial describes how to configure static and dynamic IP address in Arch Linux and its derivatives like Antergos and Manjaro Linux etc. This steps provided here should work on both newly installed system and already installed system. First, we will see how to configure static IP address.

Configure Static IP Address in Arch Linux

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

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.

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

First let us find the 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: Configure Static IP Address in Arch Linux using systemd

systemd is a system and service manager for Linux operating systems.

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. Go through and disable all netctl related stuff. I have the following service enabled, 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 stop dhcpcd

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

ip addr

That’s all for now folks. Hope this helps. If you find this guide useful, please share it on your social networks and share it on your social networks.

Cheers!

Thanks for stopping by!

How can I benefit from this blog:

Have a Good day!!

You may also like...