Skip to main content

Debian /etc/network/interfaces not loading on boot (How to fix race condition) [Resolved]

I had a server configuration that was working before, but recently I did an update and it seems to have broken things. I believe there were originally two issues, the first of which I've solved. I noticed when I was looking through systemctl status networking that a command I had never seen before was failing. I looked it up and it was from a package I've never seen before, ifupdown2. I installed it and that error resolved. I assume this was an unmarked dependency that was added because I never needed that package before.

Now when my server boots, the networking service runs successfully, but none of the networking configurations are set:

# ip link
1: lo:  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: enp2s5:  mtu 1500 qdisc pfifo_fast state UP mode DEFAULT group default qlen 1000
    link/ether 00:1e:2a:c2:08:13 brd ff:ff:ff:ff:ff:ff
# 
# ip addr
1: lo:  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: enp2s5:  mtu 1500 qdisc pfifo_fast state UP group default qlen 1000
    link/ether 00:1e:2a:c2:08:13 brd ff:ff:ff:ff:ff:ff
    inet6 fe80::21e:2aff:fec2:813/64 scope link 
       valid_lft forever preferred_lft forever
# 
# ip route # This is not a copy-paste error, it actually just prints nothing
# 
# journalctl -u networking
-- Logs begin at Thu 2019-03-28 15:17:47 CDT, end at Thu 2019-03-28 15:19:18 CDT. --
Mar 28 15:17:51 linux-01 systemd[1]: Starting ifupdown2 networking initialization...
Mar 28 15:17:51 linux-01 networking[572]: networking: Configuring network interfaces
Mar 28 15:17:54 linux-01 systemd[1]: Started ifupdown2 networking initialization.

This is my /etc/network/interfaces file:

# This file describes the network interfaces available on your system
# and how to activate them. For more information, see interfaces(5).

source /etc/network/interfaces.d/*

# The loopback network interface
auto lo
iface lo inet loopback

# The primary network interface
allow-hotplug enp2s5
iface enp2s5 inet static
        address 10.0.6.164/24
        gateway 10.0.6.1
        # dns-* options are implemented by the resolvconf package, if installed
        dns-nameservers 8.8.8.8

The weird part is even though networking started successfully if I reload it everything works.

# ip link
1: lo:  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: enp2s5:  mtu 1500 qdisc pfifo_fast state UP mode DEFAULT group default qlen 1000
    link/ether 00:1e:2a:c2:08:13 brd ff:ff:ff:ff:ff:ff
#
# ip addr
1: lo:  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: enp2s5:  mtu 1500 qdisc pfifo_fast state UP group default qlen 1000
    link/ether 00:1e:2a:c2:08:13 brd ff:ff:ff:ff:ff:ff
    inet 10.0.6.164/24 scope global enp2s5
       valid_lft forever preferred_lft forever
    inet6 fe80::21e:2aff:fec2:813/64 scope link 
       valid_lft forever preferred_lft forever
#
# ip route
default via 10.0.6.1 dev enp2s5 
10.0.6.0/24 dev enp2s5 proto kernel scope link src 10.0.6.164

I think it may be a race condition based on this. I've capture 3 failures from journalctl and all of them contain something like this:

Mar 28 15:11:51 linux-01 kernel: r8169 0000:02:05.0 enp2s5: link down
Mar 28 15:11:51 linux-01 kernel: r8169 0000:02:05.0 enp2s5: link down
Mar 28 15:11:51 linux-01 kernel: IPv6: ADDRCONF(NETDEV_UP): enp2s5: link is not ready
Mar 28 15:11:51 linux-01 systemd[1]: Started ifupdown2 networking initialization.
Mar 28 15:11:51 linux-01 systemd[1]: Reached target Network.
Mar 28 15:11:51 linux-01 systemd[1]: Starting Permit User Sessions...
Mar 28 15:11:51 linux-01 systemd[1]: Starting Fail2Ban Service...
...
Mar 28 15:11:54 linux-01 kernel: r8169 0000:02:05.0 enp2s5: link up
Mar 28 15:11:54 linux-01 kernel: IPv6: ADDRCONF(NETDEV_CHANGE): enp2s5: link becomes ready

It seems like the system is trying to load the network configuration before the device is ready, but I don't know how to make it wait until it is. Also, shouldn't allow-hotplug enp2s5 make the timing irrelevant?

Can anyone confirm my assessment of the problem and can anyone tell me how to make systemd wait until the device is ready?

Note: I don't have physical access to the server anymore and getting it is a massive pain. I'd prefer not to do any reboots until I'm 100% sure it will work.


Question Credit: user2752635
Question Reference
Asked April 17, 2019
Posted Under: Network
50 views
1 Answers

Thanks to @Mark Wagner for his advice:

I'm guessing adding auto enp2s5 to /etc/network/interfaces will fix this.

I'm not sure what the difference between auto and allow-hotplug is, but this seems to have fixed the problem.


credit: user2752635
Answered April 17, 2019
Your Answer