specific binds vlan to NIC

docent

Renowned Member
Jul 23, 2009
96
1
73
Hi!

How can I bind a specific network card of a virtual machine to a specific network card of a host?
I'd like to bind eth0,eth1,eth2 of a VM (KVM) to eth2,eth0,eth1 of a host.

By hand, I did so:
Code:
/usr/bin/kvm \
    -monitor unix:/var/run/qemu-server/105.mon,server,nowait \
    -vnc unix:/var/run/qemu-server/105.vnc,password \
    -pidfile /var/run/qemu-server/105.pid \
    -daemonize \
    -usbdevice tablet \
    -name gw.ugk \
    -smp 2 \
    -id 105 \
    -cpuunits 1000 \
    -vga cirrus \
    -tdf \
    -k en-us \
    -drive file=/var/lib/vz/images/105/vm-105-disk.qcow2,if=ide,index=0,boot=on \
    -m 256 \
    -net tap,vlan=0,ifname=vmtab105i0,script=/var/lib/qemu-server/bridge-vlan1 \
    -net nic,vlan=0,model=rtl8139,macaddr=6E:67:B8:69:A6:74 \
    -net tap,vlan=1,ifname=vmtab105i1,script=/var/lib/qemu-server/bridge-vlan2 \
    -net nic,vlan=1,model=rtl8139,macaddr=C6:38:D5:C9:0B:3C \
    -net tap,vlan=2,ifname=vmtab105i2,script=/var/lib/qemu-server/bridge-vlan0 \
    -net nic,vlan=2,model=rtl8139,macaddr=96:D8:17:47:EF:C3
 
You can create several bridges, and add a virtual network card on each bridge. All that can be done on the web interface.
 
Not quite. In the manager I can't establish order of NICs in VM.
For example, there is only one NIC on my host - eth0. I want to create an additional two virtual NICs.
HTML:
Ethernet devices
Model   Bridge  MAC address
rtl8139 vmbr0   C6:38:D5:C9:0B:3C 
e1000   vmbr1   96:D8:17:47:EF:C3 
e1000   vmbr2   6E:67:B8:69:A6:74
In that case rtl8139 becomes eth0 in my VM, but I need that it would becomes eth2 and two e1000 become eth0 and eth1, respectively.
 
The order is controlled by the VM, not by the host. So this depends on the VM Guest you use (for debian modify /etc/udev/rules.d/70-persistent-net.rules)
 
Yes, of course, but...
I wrote this code to 70-persistent-net.rules on VM (Debian 5.02):
Code:
# PCI device (e1000)
SUBSYSTEM=="net", ACTION=="add", DRIVERS=="?*", ATTR{address}=="96:D8:17:47:EF:C3", ATTR{type}=="1", KERNEL=="eth*", NAME="eth0"
 # PCI device (e1000)
SUBSYSTEM=="net", ACTION=="add", DRIVERS=="?*", ATTR{address}=="6E:67:B8:69:A6:74", ATTR{type}=="1", KERNEL=="eth*", NAME="eth1"
 # PCI device 0x10ec:0x8168 (r8169)
SUBSYSTEM=="net", ACTION=="add", DRIVERS=="?*", ATTR{address}=="C6:38:D5:C9:0B:3C", ATTR{type}=="1", KERNEL=="eth*", NAME="eth2"
However,
dmesg out:
Code:
[    4.996402] eth0: RTL-8139C+ at 0xffffc200000b8000, c6:38:d5:c9:0b:3c, IRQ 10
[    5.376181] e1000: 0000:00:04.0: e1000_probe: (PCI:33MHz:32-bit) 96:d8:17:47:ef:c3
[    5.447551] e1000: eth1: e1000_probe: Intel(R) PRO/1000 Network Connection
[    5.856766] e1000: 0000:00:05.0: e1000_probe: (PCI:33MHz:32-bit) 6e:67:b8:69:a6:74
[    5.910219] e1000: eth2: e1000_probe: Intel(R) PRO/1000 Network Connection
[    5.942697] 8139too Fast Ethernet driver 0.9.28
[   18.463286] eth0: link up, 100Mbps, full-duplex, lpa 0x05E1
[   18.841670] ADDRCONF(NETDEV_UP): eth1: link is not ready
[   18.907697] e1000: eth1: e1000_watchdog: NIC Link is Up 1000 Mbps Full Duplex, Flow Control: RX
[   18.907697] ADDRCONF(NETDEV_CHANGE): eth1: link becomes ready
[   19.192304] e1000: eth2: e1000_watchdog: NIC Link is Up 1000 Mbps Full Duplex, Flow Control: RX
[   19.199258] ADDRCONF(NETDEV_UP): eth2: link is not ready
[   19.209594] ADDRCONF(NETDEV_CHANGE): eth2: link becomes ready
mii-tool out:
Code:
eth0: no autonegotiation, 100baseTx-FD flow-control, link ok
eth1: no autonegotiation, 1000baseT-FD flow-control, link ok
eth2: no autonegotiation, 1000baseT-FD flow-control, link ok
But, if I run VM using this command:
Code:
/usr/bin/kvm \
    -monitor unix:/var/run/qemu-server/105.mon,server,nowait \
    -vnc unix:/var/run/qemu-server/105.vnc,password \
    -pidfile /var/run/qemu-server/105.pid \
    -daemonize \
    -usbdevice tablet \
    -name gw.ugk \
    -smp 2 \
    -id 105 \
    -cpuunits 1000 \
    -vga cirrus \
    -tdf \
    -k en-us \
    -drive file=/var/lib/vz/images/105/vm-105-disk.qcow2,if=ide,index=0,boot=on \
    -m 256 \
    -net tap,vlan=0,ifname=vmtab105i0,script=/var/lib/qemu-server/bridge-vlan1 \
    -net nic,vlan=0,model=e1000,macaddr=6E:67:B8:69:A6:74 \
    -net tap,vlan=1,ifname=vmtab105i1,script=/var/lib/qemu-server/bridge-vlan2 \
    -net nic,vlan=1,model=e1000,macaddr=C6:38:D5:C9:0B:3C \
    -net tap,vlan=2,ifname=vmtab105i2,script=/var/lib/qemu-server/bridge-vlan0 \
    -net nic,vlan=2,model=rtl8139,macaddr=96:D8:17:47:EF:C3
I get the following:
dmesg out:
Code:
[    5.691851] e1000: 0000:00:03.0: e1000_probe: (PCI:33MHz:32-bit) 6e:67:b8:69:a6:74
[    5.750277] e1000: eth0: e1000_probe: Intel(R) PRO/1000 Network Connection
[    6.156770] e1000: 0000:00:04.0: e1000_probe: (PCI:33MHz:32-bit) c6:38:d5:c9:0b:3c
[    6.218555] e1000: eth1: e1000_probe: Intel(R) PRO/1000 Network Connection
[    6.258424] eth2: RTL-8139C+ at 0xffffc200000b8000, 96:d8:17:47:ef:c3, IRQ 10
[    6.272274] 8139too Fast Ethernet driver 0.9.28
[   16.197838] e1000: eth0: e1000_watchdog: NIC Link is Up 1000 Mbps Full Duplex, Flow Control: RX
[   16.197838] ADDRCONF(NETDEV_UP): eth0: link is not ready
[   16.200839] ADDRCONF(NETDEV_CHANGE): eth0: link becomes ready
[   16.612507] e1000: eth1: e1000_watchdog: NIC Link is Up 1000 Mbps Full Duplex, Flow Control: RX
[   16.986511] eth2: link up, 100Mbps, full-duplex, lpa 0x05E1
mii-tool out:
Code:
eth0: no autonegotiation, 1000baseT-FD flow-control, link ok
eth1: no autonegotiation, 1000baseT-FD flow-control, link ok
eth2: no autonegotiation, 100baseTx-FD flow-control, link ok
ie just what I need.

It would be nice if you add in the configuration file something like this:
Code:
vlan0: e1000=96:D8:17:47:EF:C3,bridge-vlan1
vlan1: e1000=6E:67:B8:69:A6:74,bridge-vlan2
vlan2: rtl8139=C6:38:D5:C9:0B:3C,bridge-vlan0
or just by order in config file.
 
Last edited:
I thought we already do that - please check with

# qm showcmd <VMID>

Unfortunately, no.
Code:
# qm showcmd 105
/usr/bin/kvm \
-monitor unix:/var/run/qemu-server/105.mon,server,nowait \
-vnc unix:/var/run/qemu-server/105.vnc,password \
-pidfile /var/run/qemu-server/105.pid \
-daemonize \
-usbdevice tablet \
-name gw.ugk \
-smp 2 \
-id 105 \
-cpuunits 1000 \
-vga cirrus \
-tdf \
-k en-us \
-drive file=/var/lib/vz/images/105/vm-105-disk.qcow2,if=ide,index=0,boot=on \
-m 256 \
-net tap,vlan=[B][COLOR=Red]0[/COLOR][/B],ifname=vmtab105i[COLOR=Red][B]0[/B][/COLOR],script=/var/lib/qemu-server/bridge-vlan[B][COLOR=Red]0[/COLOR][/B] \
-net nic,vlan=[COLOR=Red][B]0[/B][/COLOR],model=rtl8139,macaddr=C6:38:D5:C9:0B:3C \
-net tap,vlan=[B][COLOR=Blue]1[/COLOR][/B],ifname=vmtab105i[B][COLOR=Blue]1[/COLOR][/B],script=/var/lib/qemu-server/bridge-vlan[COLOR=Blue][B]1[/B][/COLOR] \
-net nic,vlan=[COLOR=Blue][B]1[/B][/COLOR],model=e1000,macaddr=96:D8:17:47:EF:C3 \
-net tap,vlan=[B][COLOR=Lime]2[/COLOR][/B],ifname=vmtab105i[B][COLOR=Lime]2[/COLOR][/B],script=/var/lib/qemu-server/bridge-vlan[B][COLOR=Lime]2[/COLOR][/B] \
-net nic,vlan=[COLOR=Lime][B]2[/B][/COLOR],model=e1000,macaddr=6E:67:B8:69:A6:74
You generate a command line with identical number of vlan, ifname and bridge-vlan.
QemuServer.pm:
Code:
for (my $i = 0; $i < 10; $i++) {
  if ($conf->{"vlan$i"} && (my $vlan = parse_vlan ($conf->{"vlan$i"}))) {
    $foundnet = 1;
    my $ifname = "vmtab${vmid}i[B][COLOR=Red]$i[/COLOR][/B]";
    push @$cmd, '-net', "tap,vlan=[B][COLOR=Red]$i[/COLOR][/B],ifname=$ifname,script=/var/lib/qemu-server/bridge-vlan[B][COLOR=Red]$i[/COLOR][/B]";
    foreach my $nic (@{$vlan->{nics}}) {
      push @$cmd, '-net', "nic,vlan=$i,model=$nic->{model},macaddr=$nic->{macaddr}";
    }
  }
}
 
Sorry, I still don't get it. What is the suggestion - reserve the order? why?

I have only one NIC (vmbr0) on the host and two fake ifaces (vmbr1 and vmbr2) that I plan to use as internal LAN. And I need to place this NIC (vmbr0) as eth2 on VM.
I don't know why 70-persistent-net.rules does not work on VM, on hw computers it works fine.
 

About

The Proxmox community has been around for many years and offers help and support for Proxmox VE, Proxmox Backup Server, and Proxmox Mail Gateway.
We think our community is one of the best thanks to people like you!

Get your subscription!

The Proxmox team works very hard to make sure you are running the best software and getting stable updates and security enhancements, as well as quick enterprise support. Tens of thousands of happy customers have a Proxmox subscription. Get yours easily in our online shop.

Buy now!