29

[Background: I'd like to actually test How to take down a static network interface when not connected? ]

I'm setting up a QEMU-KVM virtual machine using libvirt (via virt-manager). I put two NICs on it (both virtio). They are bridged to a physical NIC on the host.

I want to test what NetworkManager does when I "unplug" one. But there isn't button/checkbox for that in virt-manager, nor a quick Google search turn up anything.

How do I emulate unplugging the network cable?

2
  • 1
    virt-manager is not the best GUI ever made... Jun 28, 2013 at 17:34
  • @HaukeLaging that is definitely true!
    – derobert
    Jun 28, 2013 at 17:38

2 Answers 2

37

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
$ sudo virsh domif-setlink ubuntu17.10 vnet0 up  
Device updated successfully

$ sudo virsh domif-getlink ubuntu17.10 vnet0
vnet0 up
1
  • 1
    The version of virsh I have on my distro is pretty old (1.2.2) and doesn't have the domifaddr command. I had to use domiflist instead.
    – Lacek
    Jul 10, 2019 at 4:12
3

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.

1
  • Do you know if set_link in the qemu console (monitor?) has the same effect as virsh domif-setlink in the other answer? Mar 8, 2021 at 16:09

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .