to inspire confidence in somebody.

0%

CentOS系统Bonding+VLAN+Bridge配置

由于业务的需要,需要在我们的一台虚拟化机器上,实现如下的配置:

首先,需要将两块网卡设置Bonding并配置交换机对应端口trunk模式;在此基础上,添加宿主机的IP地址,并添加相应的VLAN,最后,还需要添加一个Bridge,用于桥接创建的虚拟机。

由于本身这台机器就是Openstack的宿主机,所以当前的状况是除了所需要的一个Bridge,其他都已经配置完成了,并且由于Openstack的原因,已经有个Bridge virbr0被绑定到bond0上了。
但是呢,这个Bridge是给ovs用的,也就是说,桥接在virbr0上的网络需要自己带上VLAN的tag才能正常工作,而我们希望的是再有一个Bridge br0,桥接在br0上不需要管理VLAN,保持和宿主机相同就可以。

一开始有点蒙,因为VLAN和Bridge同属于二层,理论上配置的Bridge,需要将IP配置在Bridge上,但是现在IP配置在了VLAN上,牵扯到谁先谁后的问题,于是就查了查资料,找到这篇帖子,里面提供了一张图,来自于redhat官方:

Multiple Bridge, Multiple VLAN, and Multiple NIC with Bond connection

看到图后,就明白了,VLAN配置独立存在,在VLAN之上配置Bridge就可以,

参考上面帖子和redhat的文档给出配置:

eth0:

1
~]# vi /etc/sysconfig/network-scripts/ifcfg-eth0
2
NAME=bond0-slave0
3
DEVICE=eth0
4
TYPE=Ethernet
5
BOOTPROTO=none
6
ONBOOT=yes
7
MASTER=bond0
8
SLAVE=yes
9
NM_CONTROLLED=no

eth1:

1
~]# vi /etc/sysconfig/network-scripts/ifcfg-eth1
2
NAME=bond0-slave1
3
DEVICE=eth1
4
TYPE=Ethernet
5
BOOTPROTO=none
6
ONBOOT=yes
7
MASTER=bond0
8
SLAVE=yes
9
NM_CONTROLLED=no

bond0:

1
~]# vi /etc/sysconfig/network-scripts/ifcfg-bond0
2
NAME=bond0
3
DEVICE=bond0
4
BONDING_MASTER=yes
5
TYPE=Bond
6
ONBOOT=yes
7
BOOTPROTO=none
8
BONDING_OPTS="mode=0 miimon=100"
9
NM_CONTROLLED=no

vlan:

1
~]# vi /etc/sysconfig/network-scripts/ifcfg-bond0.10
2
DEVICE=bond0.10
3
BOOTPROTO=none
4
ONPARENT=yes
5
#IPADDR=192.168.10.1
6
#NETMASK=255.255.255.0
7
VLAN=yes
8
NM_CONTROLLED=no
9
BRIDGE=br0

br0:

1
~]# vi /etc/sysconfig/network-scripts/ifcfg-br0
2
DEVICE=br0
3
ONBOOT=yes
4
TYPE=Bridge
5
IPADDR=192.168.10.1
6
NETMASK=255.255.255.0
7
NM_CONTROLLED=no

配置完成后: systemctl restart network 等待网卡重启,搞定!

参考:

  1. https://www.centos.org/forums/viewtopic.php?t=63449
  2. https://access.redhat.com/documentation/en-US/Red_Hat_Enterprise_Virtualization/3.1/html/Technical_Reference_Guide/sect-Technical_Reference_Guide-Host_Networking_Configurations-Multiple_Bridge_Multiple_VLAN_and_Bond_Configuration.html
  3. https://access.redhat.com/documentation/en-us/red_hat_enterprise_linux/6/html/deployment_guide/sec-Configuring_a_VLAN_over_a_Bond
  4. https://access.redhat.com/documentation/en-us/red_hat_enterprise_linux/6/html/deployment_guide/s2-networkscripts-interfaces_network-bridge-with-vlan