Difference between revisions of "Kvm vlans"

From Asenjo
Jump to: navigation, search
m
 
Line 7: Line 7:
 
The KVM host has only one NIC eth0. This nic will be bridged to br0, and this br0 interface will have the management ip addres of the KVM host:
 
The KVM host has only one NIC eth0. This nic will be bridged to br0, and this br0 interface will have the management ip addres of the KVM host:
  
<code><pre>
+
<pre>
 
# cat ifcfg-eth0
 
# cat ifcfg-eth0
 
DEVICE="eth0"
 
DEVICE="eth0"
Line 17: Line 17:
 
BRIDGE=br0
 
BRIDGE=br0
 
UUID="0f311907-6878-42f3-8974-cecd79ea2f7c"
 
UUID="0f311907-6878-42f3-8974-cecd79ea2f7c"
</pre></code>
+
</pre>
  
<code><pre>
+
<pre>
 
# cat ifcfg-br0
 
# cat ifcfg-br0
 
DEVICE="br0"
 
DEVICE="br0"
Line 32: Line 32:
 
NETMASK=255.255.255.0
 
NETMASK=255.255.255.0
 
GATEWAY=192.168.0.7
 
GATEWAY=192.168.0.7
</pre></code>
+
</pre>
  
 
In the coreswitch I have defined some vlans, I join the eth0 port to those vlans as tagged ports (config cisco switch sg 300-10).
 
In the coreswitch I have defined some vlans, I join the eth0 port to those vlans as tagged ports (config cisco switch sg 300-10).
Line 38: Line 38:
 
back to centos, for every vlan I need to create 2 files, and eth0.vlan_id and a br_vlan_id ifcfg- file. Here examples for vlan 10:
 
back to centos, for every vlan I need to create 2 files, and eth0.vlan_id and a br_vlan_id ifcfg- file. Here examples for vlan 10:
  
<code><pre>
+
<pre>
 
# cat ifcfg-eth0.10
 
# cat ifcfg-eth0.10
 
DEVICE=eth0.10
 
DEVICE=eth0.10
Line 53: Line 53:
 
DELAY=0
 
DELAY=0
  
</pre></code>
+
</pre>
  
 
Add as many of those interfaces as vlan's you need to use. Then restart the network service and you will see this:
 
Add as many of those interfaces as vlan's you need to use. Then restart the network service and you will see this:
  
<code><pre>
+
<pre>
 
# ifconfig
 
# ifconfig
 
br_v10    Link encap:Ethernet  HWaddr 00:9C:02:A0:37:8F  
 
br_v10    Link encap:Ethernet  HWaddr 00:9C:02:A0:37:8F  
Line 126: Line 126:
 
           RX bytes:0 (0.0 b)  TX bytes:0 (0.0 b)
 
           RX bytes:0 (0.0 b)  TX bytes:0 (0.0 b)
  
</pre></code>
+
</pre>
  
 
Use as source for the guest vnic the br_vlanid interface. See [[Kvm_change_guest_vlan| change vm vlan without reboot]]
 
Use as source for the guest vnic the br_vlanid interface. See [[Kvm_change_guest_vlan| change vm vlan without reboot]]

Latest revision as of 21:21, 28 August 2015


In order to use vlans in our KVM virtual machines we need to configure the networking stack in the KVM host.

This shows how I have done it in a test lab running centos 6.3.

The KVM host has only one NIC eth0. This nic will be bridged to br0, and this br0 interface will have the management ip addres of the KVM host:

# cat ifcfg-eth0
DEVICE="eth0"
HWADDR="00:9C:02:A0:37:8F"
IPV6INIT="no"
MTU="1500"
NM_CONTROLLED="no"
ONBOOT="yes"
BRIDGE=br0
UUID="0f311907-6878-42f3-8974-cecd79ea2f7c"
# cat ifcfg-br0
DEVICE="br0"
TYPE="Bridge"
BOOTPROTO="static"
IPV6INIT="no"
MTU="1500"
NM_CONTROLLED="no"
ONBOOT="yes"
UUID="0f311907-6878-42f3-8974-cecd79ea2f7c"
IPADDR=192.168.0.172
NETMASK=255.255.255.0
GATEWAY=192.168.0.7

In the coreswitch I have defined some vlans, I join the eth0 port to those vlans as tagged ports (config cisco switch sg 300-10).

back to centos, for every vlan I need to create 2 files, and eth0.vlan_id and a br_vlan_id ifcfg- file. Here examples for vlan 10:

# cat ifcfg-eth0.10
DEVICE=eth0.10
VLAN=yes
ONBOOT=yes
BRIDGE=br_v10

cat ifcfg-br_v10
DEVICE=br_v10
TYPE=Bridge
BOOTPROTO=static
STP=on
ONBOOT=yes
DELAY=0

Add as many of those interfaces as vlan's you need to use. Then restart the network service and you will see this:

# ifconfig
br_v10    Link encap:Ethernet  HWaddr 00:9C:02:A0:37:8F 
          inet6 addr: fe80::29c:2ff:fea0:378f/64 Scope:Link
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
          RX packets:220918 errors:0 dropped:0 overruns:0 frame:0
          TX packets:13 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:0
          RX bytes:10186243 (9.7 MiB)  TX bytes:1046 (1.0 KiB)

br_v20    Link encap:Ethernet  HWaddr 00:9C:02:A0:37:8F 
          inet6 addr: fe80::29c:2ff:fea0:378f/64 Scope:Link
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
          RX packets:414 errors:0 dropped:0 overruns:0 frame:0
          TX packets:6 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:0
          RX bytes:38280 (37.3 KiB)  TX bytes:468 (468.0 b)

br0       Link encap:Ethernet  HWaddr 00:9C:02:A0:37:8F 
          inet addr:192.168.0.172  Bcast:192.168.0.255  Mask:255.255.255.0
          inet6 addr: fe80::29c:2ff:fea0:378f/64 Scope:Link
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
          RX packets:434016 errors:0 dropped:0 overruns:0 frame:0
          TX packets:376825 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:0
          RX bytes:55048227 (52.4 MiB)  TX bytes:155770837 (148.5 MiB)

eth0      Link encap:Ethernet  HWaddr 00:9C:02:A0:37:8F 
          inet6 addr: fe80::29c:2ff:fea0:378f/64 Scope:Link
          UP BROADCAST RUNNING PROMISC MULTICAST  MTU:1500  Metric:1
          RX packets:314021 errors:0 dropped:0 overruns:0 frame:0
          TX packets:313169 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1000
          RX bytes:47985625 (45.7 MiB)  TX bytes:118658184 (113.1 MiB)
          Interrupt:18

eth0.10   Link encap:Ethernet  HWaddr 00:9C:02:A0:37:8F 
          inet6 addr: fe80::29c:2ff:fea0:378f/64 Scope:Link
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
          RX packets:5781 errors:0 dropped:0 overruns:0 frame:0
          TX packets:6975 errors:0 dropped:3 overruns:0 carrier:0
          collisions:0 txqueuelen:0
          RX bytes:368596 (359.9 KiB)  TX bytes:430381 (420.2 KiB)

eth0.20   Link encap:Ethernet  HWaddr 00:9C:02:A0:37:8F 
          inet6 addr: fe80::29c:2ff:fea0:378f/64 Scope:Link
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
          RX packets:1812 errors:0 dropped:0 overruns:0 frame:0
          TX packets:7790 errors:0 dropped:4 overruns:0 carrier:0
          collisions:0 txqueuelen:0
          RX bytes:213612 (208.6 KiB)  TX bytes:860334 (840.1 KiB)

lo        Link encap:Local Loopback 
          inet addr:127.0.0.1  Mask:255.0.0.0
          inet6 addr: ::1/128 Scope:Host
          UP LOOPBACK RUNNING  MTU:16436  Metric:1
          RX packets:37818 errors:0 dropped:0 overruns:0 frame:0
          TX packets:37818 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:0
          RX bytes:55946604 (53.3 MiB)  TX bytes:55946604 (53.3 MiB)

virbr0    Link encap:Ethernet  HWaddr 52:54:00:0E:BA:27 
          inet addr:192.168.122.1  Bcast:192.168.122.255  Mask:255.255.255.0
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
          RX packets:0 errors:0 dropped:0 overruns:0 frame:0
          TX packets:0 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:0
          RX bytes:0 (0.0 b)  TX bytes:0 (0.0 b)

Use as source for the guest vnic the br_vlanid interface. See change vm vlan without reboot