[CentOS-virt] Disable/stop nic in a virtual guest with virsh

Wed Feb 18 13:32:55 UTC 2015
Juerg Haefliger <juergh at gmail.com>

On Wed, Feb 18, 2015 at 9:10 AM, C. L. Martinez <carlopmart at gmail.com> wrote:
> On Tue, Feb 17, 2015 at 1:43 PM, Sven Kieske <s.kieske at mittwald.de> wrote:
>> On 17/02/15 09:18, C. L. Martinez wrote:
>>> Hi all,
>>> How can I stop/disable a nic in a virtual guest using a virsh
>>> command?? I am searching the same effect like if I unplug network
>>> cable ... Is it possible?? I have tried with "detach-interface"
>>> command without luck. I don't want to remove the nic from guest
>>> configuration, only to stop the nic ...

There's a qemu monitor command for that. You can pass it in through virsh:

$ virsh qemu-monitor-command --hmp <instance name> 'set_link <nic name> off'

# virsh list
 Id    Name                           State
 3     dwarf-00000039                 running

# virsh qemu-monitor-command --hmp dwarf-00000039 'info network'
net0: index=0,type=nic,model=virtio-net-pci,macaddr=52:54:00:a8:85:ea
 \ hostnet0: index=0,type=tap,fd=24

# virsh qemu-monitor-command --hmp dwarf-00000039 'set_link net0 off'


>> Depending on your network architecture you could just ifdown
>> the vmnet, but this just works if you don't have multiple
>> vms on one vmnet (which you shouldn't).
>> HTH
>> --
> Ok, to do a ifdown of virtual bridge it seems the only option.
> Many thanks to all for your answers.
> _______________________________________________
> CentOS-virt mailing list
> CentOS-virt at centos.org
> http://lists.centos.org/mailman/listinfo/centos-virt