如何在Ubuntu LTS服务器上设置绑定(bond0)和桥接(br0)网络
时间:2020-01-09 10:45:34 来源:igfitidea点击:
如何在Ubuntu Linux 16.04 LTS服务器上通过绑定设置KVM桥接器。
我总共有四个Intel I350千兆网络连接(NIC)。
如何将eth0通过eth2绑定/奴役到一个绑定的接口,该接口称为bond0,具有802.3ad动态链接聚合模式。
如何配置与Ubuntu Server 16.04 LTS的桥接和绑定?
您需要设置桥接,以便基于KVM/XEN或者LXC容器的虚拟机(来宾)显示在与主机服务器相同的网络上。
桥接配置需要安装bridge-utils。
绑定配置需要ifenslave实用程序。
在本教程中,您将"学习如何在Ubuntu 16.04 LTS服务器上创建绑定和桥接网络"。
在Ubuntu LTS服务器上具有绑定功能的示例设置KVM桥接器
在Ubuntu上安装ifenslave
执行以下命令:
$ sudo apt install ifenslave bridge-utils
在Ubuntu上使用Bonding桥接
备份您的/etc/network/interfaces文件,运行:
$ sudo cp /etc/network/interfaces /etc/network/interfaces.bakup
编辑/etc/network/interfaces,运行:
$ sudo vi /etc/network/interfaces
首先创建不带IP地址的bond0接口配置,并按如下方式奴役eth0和eth2:
auto bond0 iface bond0 inet manual bond-lacp-rate 1 post-up ifenslave bond0 eth0 eth2 pre-down ifenslave -d bond0 eth0 eth2 bond-slaves none bond-mode 4 bond-lacp-rate fast bond-miimon 100 bond-downdelay 0 bond-updelay 0 bond-xmit_hash_policy 1
下一步编辑/更新eth0,而没有绑定主键bond0的IP地址:
auto eth0 iface eth0 inet manual bond-master bond0 auto eth2 iface eth2 inet manual bond-master bond0
最后,创建br0网桥并分配IP地址和其他IP设置,包括网关:
auto br0 iface br0 inet static address 10.86.115.66 netmask 255.255.255.192 broadcast 10.86.115.127 gateway 10.86.115.65 # ----------------------------------------- # Example: set dns server too # dns-nameservers 8.8.8.8 8.8.4.4 10.86.115.1 # ----------------------------------------- # Static route example #up route add -net 10.0.0.0/8 gateway 10.86.115.65 #down route del -net 10.0.0.0/8 #up route add -net 161.26.0.0/16 gateway 10.86.115.65 #down route del -net 161.26.0.0/16 # ----------------------------------------- # Want to know what the default and more info # on the following options? # Read brctl(8) man page # ----------------------------------------- bridge_ports bond0 bridge_stp off bridge_fd 9 bridge_hello 2 bridge_maxage 12
保存并关闭文件。
重新启动服务器或者重新启动网络服务:
$ sudo systemctl restart networking
验证一下:
$ brctl show
输出示例:
bridge name bridge id STP enabled interfaces br0 8000.0025904fb06c no bond0
查看bond0状态和其他信息:
$ more /proc/net/bonding/bond0
输出示例:
Ethernet Channel Bonding Driver: v3.7.1 (April 27, 2011) Bonding Mode: IEEE 802.3ad Dynamic link aggregation Transmit Hash Policy: layer3+4 (1) MII Status: up MII Polling Interval (ms): 100 Up Delay (ms): 0 Down Delay (ms): 0 802.3ad info LACP rate: fast Min links: 0 Aggregator selection policy (ad_select): stable System priority: 65535 System MAC address: 00:25:90:4f:b0:6c Active Aggregator Info: Aggregator ID: 1 Number of ports: 1 Actor Key: 9 Partner Key: 43 Partner Mac Address: b0:fa:eb:13:97:00 Slave Interface: eth0 MII Status: up Speed: 1000 Mbps Duplex: full Link Failure Count: 0 Permanent HW addr: 00:25:90:4f:b0:6c Slave queue ID: 0 Aggregator ID: 1 Actor Churn State: none Partner Churn State: none Actor Churned Count: 0 Partner Churned Count: 0 details actor lacp pdu: system priority: 65535 system mac address: 00:25:90:4f:b0:6c port key: 9 port priority: 255 port number: 1 port state: 63 details partner lacp pdu: system priority: 32768 system mac address: b0:fa:eb:13:97:00 oper key: 43 port priority: 32768 port number: 300 port state: 61 Slave Interface: eth2 MII Status: down Speed: Unknown Duplex: Unknown Link Failure Count: 0 Permanent HW addr: 00:25:90:4f:b0:6e Slave queue ID: 0 Aggregator ID: 2 Actor Churn State: churned Partner Churn State: churned Actor Churned Count: 1 Partner Churned Count: 1 details actor lacp pdu: system priority: 65535 system mac address: 00:25:90:4f:b0:6c port key: 0 port priority: 255 port number: 2 port state: 71 details partner lacp pdu: system priority: 65535 system mac address: 00:00:00:00:00:00 oper key: 1 port priority: 255 port number: 1 port state: 1
确保路由正确无误:
$ ip r show $ ping google.com $ ping www.theitroad.local