Setting a static IP for Arch Linux ARM on Raspberry PI

Setting a static IP for Arch Linux ARM on Raspberry PI

I was using Pirelli (can't remember the model) router in my home network. Its DHCP server has ability to assign a static sub-ip (eg. 192.168.0.0/24) to a device with a specific mac. I was using this feature to assign static IP to my Raspberry PI. A few weeks ago my router broke and my ISP replaced this Pirelli with a Huawei HG253. Guess what, this brand new cool-looking router didn't have mac-ip matching feature.

Since I am connecting to my Raspberry PI from outside of home network (to reach other devices in network via NAT or just to add some torrents to queue :P) a lot, I needed to set a port forwarding to my Raspberry PI, thus it was supposed to have a specific IP.

First, I asked for Turkcell Superonline (my ISP) if router had such a feature or if they can replace my router having this feature if this one doesn't. Very nice person on the call center wasn't aware of the difference between public IP and the private IP, so she offered me static public IP service. And when I told them about the difference between public IP and private IP they made me wait on the line for like 2 minutes and then answered all in one breath: "we don't provide such a service, is there anything else I can help you with?" This is when I said "thank you nice knowledgeable person, seems that I have to handle it myself.".

Luckily, HG253 router had DHCP IP range setting. I have set the range for DHCP as 192.168.1.50 - 192.168.1.254 and kept the range 192.168.1.2 - 192.168.1.49 for devices with static IPs. And then, all needed to be done is to set Arch Linux on Raspberry PI to use a static IP from this range.

To do so;

  • First I had to disable the enabled dhcpcd systemd service:
# systemctl disable dhcpcd@eth0.service
  • Then to create a netctl profile and enable it to make it run on startup.

netctl profiles are stored in /etc/netctl/ and there are example configurations in /etc/netctl/examples/. Since I am connecting via ethernet I started with copying the matching example:

# cp /etc/netctl/examples/ethernet-static /etc/netctl/home

and then edited file according to my preferences:

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

I selected 192.168.1.3 for my Raspberry PI, you can change that part to suit your needs. DNS part is also optional.

Don't forget to reboot and check if your configuration works, or you may realize that it doesn't work when you are outside trying to connect :)

Also, play carefully with network settings if you are connecting to your Raspberry PI via SSH, since disconnecting Raspberry PI from network will shut down SSH connection as well.