Arch Linux Static Manual IP

Published on August 17, 2022 at 6:35 pm by LEW

Introduction

I had occasion to set up a persistent static IP address on an Arch Linux installation a few days ago. So I turned to the Arch Wiki, which did have instructions for setting a non persistent static IP address.

I noticed the on line documentation and tutorials for setting up a persistent static IP address was very little, and in many cases contradictory. This is understandable, as Arch Linux does not have a reputation for stability, or for use as a server (that is not to say it canโ€™t be done).

I eventually worked though my problem and would like to share my solution for setting up a persistent static IP address in an Arch installation.

The Arch Documentation

My search for information tended to lead me to the Network Configuration page of the Arch Linux Wiki. If you scroll down, there is a section on static IP addresses. The instructions use the โ€œipโ€ command, with references to DHCP and DNS. While this solution is doable, I found it did not really survive a reboot. I could have scripted something, and set up a cron job. But figured there had to be a better way.

Some other sources suggested using the netctl package. But this is a command line based network manager, something I was trying to get away from. If I wanted a network manager, I would have just used the netwrokmanager package.

Another common way that I saw was to setup a static IP address in the router for the computer, based on the MAC address. This would assure the same IP address assigned to the computer every time. But this solution depends on having access to a router. While not a problem on a home LAN, it could be an issue if you are not managing the network you are on.

Arch uses systemd, and I recalled that it had a networking module of some sort. Doing a search of the Arch Wiki, I found the systemd-networkd page. This page contained the basic solution to the problem. It is not the full solution to my particular case, which I shall elaborate on below.

Static IP Address with Systemd-Networkd

There are a couple of prerequisites to be aware of before proceeding.

To assign your computer a static IP address, you will need to create a new configuration file in the folder etc/systemd/network. Actually you could also setup a Dynamic DHCP address this way also.

Creating Network Config file

I need to make this comparisons, it is quite similar to setting up a network in a Debian install, just a different folder location. And you do not need to be on line to do this.

First issue the following command to find your adapter name (it will most likely start with a โ€œenโ€).

ip a

When you have that, you can create the config file. The wiki suggests calling it โ€œ20-wired.networkโ€. However I donโ€™t thin the name really matters. I named mine after my one and only network adapter โ€œenp0s25.networkโ€, and it worked without issue. Now when I look at the file name, I will know what it is for.

I used touch to create the file, then vi to edit it.

touch enp0s25.network

vi enp0s25.network

I added the following text to the file.

# Static IP address Adapter Settings for enp0s25

[Match]
	Name=enp0s25

[Network]
	Address=	192.168.50.8/24
	Gateway=	192.168.50.1
	DNS=	        192.168.50.1

I always like to start with a comment describing the file. Then the name of the adapter to Match, and finally the desired adapter network settings. Note that capitalization is important in this file. I also used local IP addresses, yours will be different. Instead of having a different line for Netmask, we append the bit count (24) to the end of the Address.

Once done, save the file.

Systemd-NetworkD

Lets go ahead and determine the status o0f the systemd-networkd program.

systemctl status systemd-networkd

If it is not running you will need to enable it, and start it. Otherwise, you will need to restart it.

systemctl enable systemd-networkd
systemctl start systemd-networkd

systemctl restart systemd-networkd

At this point your network should come up. Try pinging a known IP address, and you should get a response.

Possible Issue

Depending on what you are doing, there may be an issue in that since there is no network manager, there is no DHCP client program. If you have the need to use site names, you will want to install a DHCP client (of which there are several). If you do not have this need, you are good to go at this point.

Conclusion

This has been a quick โ€œhow toโ€ for manually setting a static IP address in Arch Linux. It is not a difficult process, and has proven useful on several occasions.

Add New Comment

Your email address will not be published. Required fields are marked *