About Arch Linux network devices names

9. septembris, 2021

I have been using linux for long time. That is why I remeber that network devices was named eth0, eth1 etc. Nowdays more and more I see that network devices are named like enp1s0. But I was not bothered about that and why its named as it is named. I didnt care. Just run command ip link show and here are listed all your network device names

Here comes the day when I start to experiment with Arch Linux. The one Linux distro which only elite is using.

If you have slept under rock and dont know what is Arch, than Arch Linux is super bare minimum distro where you have to do all configuration/installation yourself. You might think its stupid, but actually its super educational and fun (if you find suffering fun). Just take a look at Arch Wiki page. If you want to learn how Linux work internaly, than Arch is best way to start exporing it

So I installed Arch and as you might expect, there is no internet connection. I have to set up internet connection myself. To make things more easy I chose to use static IP address

It is super easy, just read this Network configuration page. No seriously its easy. It consists of three steps

  1. Take up network device
  2. Set IP address
  3. Set gateway
ip link set <device_name> up
ip addr add broadcast + dev <device_name>
ip route add default via dev <device_name>

Only key moments here is which network device name to use. In my case network device name is enp1s0. Run ip link show to see all network devices

At this point I have internet connection. But these settings are not permament, after system reboot they are gone and you have to execute these 3 commands again. To solve this you can install network manager or you can go deeper into linux and find out how to run these 3 commands on system start up.

Here comes systemd. Shortly it is an init system used to manage user processes. When linux is booting it is systemd which is starting every process. So you can instruct systemd to run these 3 ip setting commands. To do it you have to create systemd unit file

These are steps to acomplish that

  1. Create bash file. This is the way to run all 3 commands at once. Name it set-static-ip.sh Save it here /root/set-static-ip.sh (you can save it where ever you want). Below is content of this file
ip link set enp1s0 up
ip addr add broadcast + dev enp1s0
ip route add default via dev enp1s0

2. Create systemd unit file here /etc/systemd/system/set-static-ip.service Below is content of this file

Description=Setup static ip address



3. Enable systemd unit file. Make sure you are in dir /etc/systemd/system

cd /etc/systemd/system
systemctl enable set-static-ip.service

Now reboot linux and after reboot system should have internet connection. In your dreams 😀 Ofcourse nothing works and system still has not internet connection. But running set-static-ip.sh manualy sets internet connection just fine. So what is the problem?

First I need to see what is status of my set-static-ip service. If there was some error it will show it. To see the status run this command

systemctl status set-static-ip.service

And this is result

As you can see set-static-ip.service failed. And error is Cannot find device enp1s0. So what is going on? Because if you run ip link show it will list device enp1s0. Why it is not available at startup?

To figure this out I decided to log output of command ip link show. That way I can see if there even is any network device available. To do this add this line at begining of set-static-ip.sh file

set-static-ip.sh file
ip link >> /root/ip-link.log

Now set-static-ip-log.sh file should look like this

set-static-ip.sh file

# write output to file
ip link >> /root/ip-link.log

ip link set enp1s0 up
ip addr add broadcast + dev enp1s0
ip route add default via dev enp1s0

Long story short, this is what was written to log file

I was little bit confused. Why there is eth0 which I remeber from old days. And where is my enp1s0?

Little bit of googling and turns out there is system called udev which renames network devices to Predictable Network Interface Names

In short whats happening is system boots up, systemd sets up network devices and calls udev to rename network devices and also calls my script to set up static ip address. Ofcourse there is run condition and my scripts is executing too early and at this time network device is still named eth0. I have to figure out how to run my script after udev have renamed devices. At this point I dont know how to do this, but I know old trick of command sleep. Just sleep few seconds before setting up static ip. After sleep device will be already renamed. In real world scenarion sleep would be super bad practice. But for learning it does its job perfect.

Here you can see ip link show logged twice. First time we get device name eth0. Second log is after sleeping 2 seconds and here is enp1s0

Here you go little bit of learning and exploring of Arch linux leads to some interesting knowledge. This takes time, but it gives back exeperience