Setting up a static ip on Arch Linux

The current Arch release comes with netctl enabled out of the box, so we will use that for our setup.

Create a new netctl profile and open it in your editor.

sudo cp /etc/netctl/examples/ethernet-static /etc/netctl/static  
sudo vim /etc/netctl/static  

Adjust the config file to your network setup. Here’s an example:

Description='A basic static ethernet connection'  
Interface=eth0  
Connection=ethernet  
IP=static  
Address=('192.168.1.31/24')  
#Routes=('192.168.0.0/24 via 192.168.1.2')
Gateway='192.168.1.1'  
DNS=('192.168.1.1')  

Execute

netctl enable static  
netctl start static  

If you reboot you RPI to test this setup you’ll notice that it reboots fine, but when it comes up, you’ll end up with another ip?

Apparently your Pi is still using a DHCP config!?
However, if you execute systemctl is-enabled dhcpcd it will tell you that that service is disabled.
You can also use systemctl –type=service to ensure that no other service is running that may want to configure the network. Now, if you execute this command you’ll notice a service in the returned list called netctl-ifplugd@eth0.service

Here’s what the documentation tells you about that service:


Automatic switching of profiles netctl provides two special systemd services for automatic switching of profiles:

-For wired interfaces: netctl-ifplugd@interface.service. Using this netctl profiles change as you plug the cable in and out. - For wireless interfaces: netctl-auto@interface.service. Using this netctl profiles change as you move from range of one network into range of other network.

A few lines below, you also find the following statement:
netctl-ifplugd@interface.service will prefer profiles which use DHCP. To prefer a profile with a static IP, you can use AutoWired=yes


That was my ‘aha erlebnis’! So as long as you don’t add AutoWired=yes to your config, it will use a DHCP profile, if available.

Adjust your config to:

Description='A basic static ethernet connection'  
Interface=eth0  
Connection=ethernet  
AutoWired=yes  
IP=static  
Address=('192.168.1.31/24')  
#Routes=('192.168.0.0/24 via 192.168.1.2')
Gateway='192.168.1.1'  
DNS=('192.168.1.1')  

Reboot and you’re all set!