When working with KVM bridged interfaces, KVM will automatically name the virtual NIC that is spawned when the VM is started. This typically follows a naming convention of:
vnet0, vnet1, vnet2, ..., vnetN
The virtual NIC names are dynamically applied to each VM instance. Thus, a spawned VM is not guaranteed to receive the same virtual NIC when it is restarted. Generally speaking, this may not be a problem. However, what if you *need* to have a script, or some function whereby it is important to know which virtual NIC is allocated to a specific VM? There are ways of scripting this, but to avoid the headaches of scripting, it may be helpful to just specify a fixed, hard-coded name on the generated virtual NIC of the VM. To do this, you must use the
virsh command line utility.
To implement this, follow the steps below as a user that has rights to use the
- Run the command:
- At the
virshconsole, you need to type the command:
edit <domain/VM Name>(substitute the name of your VM in here)
- This will open up a
vilike interface to edit the XML entries for your VM. NOTE: I am making the assumption that you are using a standard bridged setup. I have not tested this with non-bridged setups, and especially not on libvirt managed bridged setups. Thus, your mileage may vary.
- Locate the XML entry for your network setup. It should look something like this:
<interface type='bridge'> <mac address='00:11:22:33:44:55'/> <source bridge='br0'/> <model type='virtio'/> <address type='pci' domain='0x0000' bus='0x00' slot='0x03' function='0x0'/> </interface>
You need to add a line to theNote: the name of the NIC needs to be a valid interface name. All lowercase and underscores work. As an example, I named my VM’s virtual NIC’s to something like this:
interfacetag that looks like this:
vm1_net, vm2_net, vm3_net, ..., vmN_net
- Once it’s entered, it should look something like this:
<interface type='bridge'> <mac address='00:11:22:33:44:55'/> <source bridge='br0'/> <target dev='vm1_net'/> <model type='virtio'/> <address type='pci' domain='0x0000' bus='0x00' slot='0x03' function='0x0'/> </interface>
- Save the changes and start the VM.
Once everything is set, you should see something like this if you use the
vm1_net Link encap:Ethernet HWaddr 00:11:22:33:44:55 inet6 addr: fe80::fc54:ff:fec7:11/64 Scope:Link UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1 RX packets:6 errors:0 dropped:0 overruns:0 frame:0 TX packets:6 errors:0 dropped:0 overruns:0 carrier:0 collisions:0 txqueuelen:500 RX bytes:468 (468.0 b) TX bytes:468 (468.0 b) vm2_net Link encap:Ethernet HWaddr 00:11:22:33:44:56 inet6 addr: fe80::fc54:ff:fec7:22/64 Scope:Link UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1 RX packets:0 errors:0 dropped:0 overruns:0 frame:0 TX packets:6 errors:0 dropped:0 overruns:0 carrier:0 collisions:0 txqueuelen:500 RX bytes:0 (0.0 b) TX bytes:468 (468.0 b)
This guarantees that the VM will always start with the virtual NIC name that you specify. In my case, I have VM1 using
vm1_net, and VM2 using
For most people this will not be an issue, however, there are a few individuals who are exhibiting network problems when using the VirtualBox Bridged Networking driver on the *host* machine.
The problem is that some systems running Windows 7 with the “VirtualBox Bridged Networking” driver installed will have network outage issues when resuming the system from hibernation. The only way to fix this is the either reboot the machine, or disable/enable the NIC.
This bug has been reported here: http://www.virtualbox.org/ticket/4677, but it doesn’t seem like it will ever be fixed
The temporary solution:
Until Oracle gets around to fixing this bug, the following instructions below will correct the problem. Do note, following the steps below will disable the bridged networking feature of VirtualBox. However, utilizing this method gives you a simple avenue to re-enable it if you need to use it.
- Click the Start Menu / Start Orb.
- Type: “View network connections”
- Press Enter.
- A window should appear with a list of all the network devices attached to your system.
- Right click the adapter that is giving you a problem > Properties
- Uncheck “VirtualBox Bridged Networking Driver”
- Click OK, and you’re all set.
To enable the feature after it is disabled utilizing this method, follow the instructions above in reverse.
Alternatively, you can also just opt out of installing the VirtualBox Bridged Networking driver altogether. However, doing so will not allow you to easily enable that great feature.