I have an issue with a virtual machine taking time to connect to the local network on boot.

I create a virtual machine using the following command:

virt-install \
    --connect qemu:///system \
    --name demo \
    --noautoconsole \
    --disk path=/demo.qcow2,device=disk,format=qcow2,bus=virtio,cache=writeback \
    --disk path=/base.qcow2,device=disk,format=qcow2,bus=virtio,cache=writeback \
    --import \
    --vcpus 1 \
    --virt-type kvm \
    --ram 256 \
    --hvm \
    --os-type linux

When I create the machine on a host running Ubuntu 14.04.4 LTS, everything works fine: the virtual machine boots and is connected to the LAN right before running systemd scripts. However, when the host runs Debian 8.5, it takes a while for the virtual machine to be connected, and systemd scripts start running before network resources could actually be used.

During the debugging, I've created the following script:


date >> /ping.log
ping -c 3 -W 3 "" >> /ping.log
date >> /ping.log
curl google.com >> ping.log
date >> /ping.log

Here's the corresponding systemd configuration:




After the machine boots, ping.log contains the following:

Tue Jul 19 12:57:56 UTC 2016
PING ( 56(84) bytes of data.
From icmp_seq=1 Destination Host Unreachable
From icmp_seq=2 Destination Host Unreachable
From icmp_seq=3 Destination Host Unreachable

--- ping statistics ---
3 packets transmitted, 0 received, +3 errors, 100% packet loss, time 2001ms
pipe 3
Tue Jul 19 12:57:59 UTC 2016
<HTML><HEAD><meta http-equiv="content-type" content="text/html;charset=utf-8">
Tue Jul 19 12:58:16 UTC 2016

It means that:

  • ping fails,
  • It takes 20 seconds to connect.

By comparison, when running the same machine on an Ubuntu host, this is what is stored in ping.log:

Tue Jul 19 13:18:12 UTC 2016
PING ( 56(84) bytes of data.
64 bytes from icmp_seq=1 ttl=64 time=2.27 ms
64 bytes from icmp_seq=2 ttl=64 time=0.711 ms
64 bytes from icmp_seq=3 ttl=64 time=5.47 ms

--- ping statistics ---
3 packets transmitted, 3 received, 0% packet loss, time 2002ms
rtt min/avg/max/mdev = 0.711/2.819/5.472/1.981 ms
Tue Jul 19 13:18:14 UTC 2016
<HTML><HEAD><meta http-equiv="content-type" content="text/html;charset=utf-8">
Tue Jul 19 13:18:14 UTC 2016


  • ping is successful,
  • It takes 2 seconds, that is the time to do the actual ping.

The actual hosts (Debian and Ubuntu) have different hardware (including different number of NIC), making it difficult to compare the configuration. The virtual machine, however, is deployed in the exact same way, is based on the same base disk with pre-installed Debian, and has the exact same /etc/network/interfaces:

# The loopback network interface
auto lo
iface lo inet loopback

# The primary network interface
auto eth0
iface eth0 inet static

I have two questions:

  • What could be the possible reasons for that enormous delay?

  • Have I misunderstood the purpose of network-online.target? I thought that it would guarantee basic connectivity when running the script. Since it's actually not the case, what is the purpose of it?


Found it. In a similar case, the author complained that:

I have to wait for about 20 seconds until my network comes up.

It appeared that:

This delay is caused by Spanning Tree Protocol (STP)

Indeed, one of the differences was that the /etc/network/interfaces of Debian host contained bridge_stp on, while on Ubuntu, there was no bridge_stp statement.

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.