Emulate unplugging a network cable with qemu-kvm

You can do that in the console with:

virsh domif-setlink domain interface-device state

And check its status with:

virsh domifstat domain interface-device

You can see the network interfaces configured with:

virsh domifaddr domain

Have a look at the man page for details.


Here's an example of a typical workflow:

$ sudo virsh list
 Id    Name                           State
----------------------------------------------------
 24    ubuntu17.10                    running

$ sudo virsh domifaddr ubuntu17.10
 Name       MAC address          Protocol     Address
-------------------------------------------------------------------------------
 vnet0      52:54:00:d0:76:cb    ipv4         192.168.122.183/24

$ sudo virsh domif-getlink ubuntu17.10 vnet0
vnet0 up
$ sudo virsh domif-setlink ubuntu17.10 vnet0 down
Device updated successfully

$ sudo virsh domif-getlink ubuntu17.10 vnet0
vnet0 down
gerlos@mediavault[20:53]:~$ sudo virsh domif-setlink ubuntu17.10 vnet0 up  
Device updated successfully

gerlos@mediavault[20:53]:~$ sudo virsh domif-getlink ubuntu17.10 vnet0
vnet0 up

Based on the advice at https://lists.gnu.org/archive/html/qemu-discuss/2017-01/msg00103.html, you can plug/unplug a cable in the qemu console using set_link <name> on|off.

info network shows you the available network links.