linux——高级网络配置之bond、team网络接口,网络桥接
一、bond 網(wǎng)絡(luò)接口
?????? Red Hat Enterprise Linux 允許管理員使用 bonding 內(nèi)核模塊和稱為通道綁定接口的特殊網(wǎng)絡(luò)接口將多個(gè)網(wǎng)絡(luò)接口綁定到一個(gè)通道。根據(jù)選擇的綁定模式,通道綁定使兩個(gè)或更多個(gè)網(wǎng)絡(luò)接口作為一個(gè)網(wǎng)絡(luò)接口,從而增加帶寬和 / 提供冗余性。
選擇linux以太網(wǎng)綁定模式
?? 目前網(wǎng)卡綁定mode共有七種(0~6):bond0、bond、bond1、bond2、bond3、bond4、bond5、bond6。這里介紹幾種,然后會(huì)有關(guān)于模式1的實(shí)驗(yàn)詳細(xì)說明。
模式0(平衡輪循):輪循策略。所有接口都采用輪循方式在所有 Slave 中傳輸封包;任何 Slave 都可以接收。
模式1(主動(dòng)備份):容錯(cuò)。一次只能使用一個(gè) Slave 接口,但是如果該接口出現(xiàn)故障,另一個(gè) Slave 將接替它。
模式3(廣播):容錯(cuò)。所有封包都通過所有 Slave 接口廣播。
實(shí)驗(yàn)——mode1(主動(dòng)備份)
1.為做實(shí)驗(yàn)的虛擬機(jī)添加兩塊網(wǎng)卡 eth0 和 eth1(步驟見圖)
?
[root@localhost Desktop]# ifconfig eth0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500inet 172.25.254.150 netmask 255.255.255.0 broadcast 172.25.254.255inet6 fe80::5054:ff:fe00:320a prefixlen 64 scopeid 0x20<link>ether 52:54:00:00:32:0a txqueuelen 1000 (Ethernet)RX packets 27 bytes 2832 (2.7 KiB)RX errors 0 dropped 0 overruns 0 frame 0TX packets 221 bytes 12177 (11.8 KiB)TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0 eth1: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500ether 52:54:00:80:fa:d5 txqueuelen 1000 (Ethernet)RX packets 35 bytes 1734 (1.6 KiB)RX errors 0 dropped 0 overruns 0 frame 0TX packets 0 bytes 0 (0.0 B)TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0 lo: flags=73<UP,LOOPBACK,RUNNING> mtu 65536inet 127.0.0.1 netmask 255.0.0.0inet6 ::1 prefixlen 128 scopeid 0x10<host>loop txqueuelen 0 (Local Loopback)RX packets 136 bytes 13228 (12.9 KiB)RX errors 0 dropped 0 overruns 0 frame 0TX packets 136 bytes 13228 (12.9 KiB)TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0 [root@localhost Desktop]# nmcli connection delete eth0 ##將已經(jīng)配置過的eth0恢復(fù)到默認(rèn)狀態(tài),即未配置前 [root@localhost Desktop]# ifconfig eth0 eth0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500ether 52:54:00:00:32:0a txqueuelen 1000 (Ethernet)RX packets 27 bytes 2832 (2.7 KiB)RX errors 0 dropped 0 overruns 0 frame 0TX packets 223 bytes 12273 (11.9 KiB)TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0 [root@localhost Desktop]# nmcli connection add con-name bond0 ifname bond0 type bond mode active-backup ip4 172.25.254.129/24 ##配置bond網(wǎng)絡(luò)接口,ip為172.25.254.129 Connection 'bond0' (68750e7d-8636-48aa-b9e6-89971dc56516) successfully added. [root@localhost Desktop]# ifconfig bond0 bond0: flags=5187<UP,BROADCAST,RUNNING,MASTER,MULTICAST> mtu 1500inet 172.25.254.129 netmask 255.255.255.0 broadcast 172.25.254.255ether 7a:c0:6f:e4:c3:22 txqueuelen 0 (Ethernet)RX packets 0 bytes 0 (0.0 B)RX errors 0 dropped 0 overruns 0 frame 0TX packets 0 bytes 0 (0.0 B)TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0 [root@localhost Desktop]# cat /proc/net/bonding/bond0 ##查看網(wǎng)絡(luò)接口bond0的信息。該文件只會(huì)在bond0接口添加后生成 Ethernet Channel Bonding Driver: v3.7.1 (April 27, 2011) Bonding Mode: fault-tolerance (active-backup) Primary Slave: None Currently Active Slave: None MII Status: up MII Polling Interval (ms): 100 Up Delay (ms): 0 Down Delay (ms): 0 [root@localhost Desktop]#開啟第二個(gè)命令面板,輸入以下監(jiān)控命令:
除了用命令的方式添加,還可以通過建立配置文件的方式
[root@localhost network-scripts]# ls ifcfg-bond0 ifdown-post ifup-bnep ifup-routes ifcfg-eth0 ifdown-ppp ifup-eth ifup-sit ifcfg-lo ifdown-routes ifup-ippp ifup-Team ifdown ifdown-sit ifup-ipv6 ifup-TeamPort ifdown-bnep ifdown-Team ifup-isdn ifup-tunnel ifdown-eth ifdown-TeamPort ifup-plip ifup-wireless ifdown-ippp ifdown-tunnel ifup-plusb init.ipv6-global ifdown-ipv6 ifup ifup-post network-functions ifdown-isdn ifup-aliases ifup-ppp network-functions-ipv6 [root@localhost network-scripts]# cat ifcfg-bond0 DEVICE=bond0 BONDING_OPTS=mode=active-backup TYPE=Bond BONDING_MASTER=yes BOOTPROTO=none IPADDR0=172.25.254.129 PREFIX0=24 DEFROUTE=yes IPV4_FAILURE_FATAL=no IPV6INIT=yes IPV6_AUTOCONF=yes IPV6_DEFROUTE=yes IPV6_PEERDNS=yes IPV6_PEERROUTES=yes IPV6_FAILURE_FATAL=no NAME=bond0 UUID=68750e7d-8636-48aa-b9e6-89971dc56516 ONBOOT=yes [root@localhost network-scripts]# cat ifcfg-eth0 TYPE=Ethernet NAME=eth0 UUID=e179929b-633b-4caf-87ad-d98cf7024354 DEVICE=eth0 ONBOOT=yes MASTER=bond0 SLAVE=yes [root@localhost network-scripts]# 注意:刪除bond網(wǎng)絡(luò)接口bond0的所有配置(不影響下面team網(wǎng)絡(luò)接口的實(shí)驗(yàn))[root@localhost network-scripts]# nmcli connection delete eth0 [root@localhost network-scripts]# nmcli connection delete eth1 [root@localhost network-scripts]# nmcli connection delete bond0
二、team 網(wǎng)絡(luò)接口(企業(yè)七之前的版本沒有這個(gè)功能)
- Team 和 bond0 功能類似
- Team 不需要手動(dòng)加載相應(yīng)內(nèi)核模塊
- Team 有更強(qiáng)的擴(kuò)展性
- 支持8塊網(wǎng)卡
- Team 的種類:
broadcast ????廣播容錯(cuò)
roundrobin ???平衡輪叫:比較機(jī)械
activebackup ?主動(dòng)備份
loadbalance ??負(fù)載均衡:將任務(wù)平衡分配
?team 網(wǎng)絡(luò)接口
[root@localhost ~]# ifconfig eth0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500ether 52:54:00:00:32:0a txqueuelen 1000 (Ethernet)RX packets 195 bytes 11502 (11.2 KiB)RX errors 0 dropped 129 overruns 0 frame 0TX packets 330 bytes 18401 (17.9 KiB)TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0 eth1: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500ether 52:54:00:80:fa:d5 txqueuelen 1000 (Ethernet)RX packets 180 bytes 9202 (8.9 KiB)RX errors 0 dropped 3 overruns 0 frame 0TX packets 118 bytes 6270 (6.1 KiB)TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0 lo: flags=73<UP,LOOPBACK,RUNNING> mtu 65536inet 127.0.0.1 netmask 255.0.0.0inet6 ::1 prefixlen 128 scopeid 0x10<host>loop txqueuelen 0 (Local Loopback)RX packets 513 bytes 50444 (49.2 KiB)RX errors 0 dropped 0 overruns 0 frame 0TX packets 513 bytes 50444 (49.2 KiB)TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0 [root@localhost ~]# nmcli connection add con-name team0 ifname team0 type team config '{"runner":{"name":"activebackup"}}' ip4 172.25.254.129/24 ##成功添加team網(wǎng)絡(luò)接口team0,ip為172.25.254.129 Connection 'team0' (97c3112a-532d-41ca-aa92-da48dad4adb5) successfully added. [root@localhost ~]# teamdctl team0 stat ##查看team0的信息 setup:runner: activebackup runner:active port: ##此處表示是可用接口,當(dāng)前表示沒有可用接口 [root@localhost ~]#開啟第二個(gè)命令面板:輸入以下監(jiān)控命令
[root@localhost ~]# watch -n 5 teamdctl team0 stat?
注意:刪除team網(wǎng)絡(luò)接口team0的所有配置
[root@localhost ~]# nmcli connection delete eth0 [root@localhost ~]# nmcli connection delete eth1 [root@localhost ~]# nmcli connection delete team0三、有無網(wǎng)橋的區(qū)別實(shí)驗(yàn)(真機(jī))
[kiosk@foundation50 Desktop]$ su Password: [root@foundation50 Desktop]# cd /etc/sysconfig/network-scripts/ [root@foundation50 network-scripts]# ls ifcfg-br0 ifdown-isdn ifup ifup-plip ifup-tunnel ifcfg-lo ifdown-post ifup-aliases ifup-plusb ifup-wireless ifdown ifdown-ppp ifup-bnep ifup-post init.ipv6-global ifdown-bnep ifdown-routes ifup-eth ifup-ppp network-functions ifdown-eth ifdown-sit ifup-ib ifup-routes network-functions-ipv6 ifdown-ib ifdown-Team ifup-ippp ifup-sit ifdown-ippp ifdown-TeamPort ifup-ipv6 ifup-Team ifdown-ipv6 ifdown-tunnel ifup-isdn ifup-TeamPort [root@foundation50 network-scripts]# mv ifcfg-br0 /opt/ ##做備份!!!一定要做的 [root@foundation50 network-scripts]# ls ifcfg-lo ifdown-post ifup-aliases ifup-plusb ifup-wireless ifdown ifdown-ppp ifup-bnep ifup-post init.ipv6-global ifdown-bnep ifdown-routes ifup-eth ifup-ppp network-functions ifdown-eth ifdown-sit ifup-ib ifup-routes network-functions-ipv6 ifdown-ib ifdown-Team ifup-ippp ifup-sit ifdown-ippp ifdown-TeamPort ifup-ipv6 ifup-Team ifdown-ipv6 ifdown-tunnel ifup-isdn ifup-TeamPort ifdown-isdn ifup ifup-plip ifup-tunnel [root@foundation50 network-scripts]# nm-connection-editor [root@foundation50 network-scripts]# ifconfig enp1s0: flags=4099<UP,BROADCAST,MULTICAST> mtu 1500inet 172.25.254.50 netmask 255.255.255.0 broadcast 172.25.254.255inet6 fe80::ca5b:76ff:fe87:3653 prefixlen 64 scopeid 0x20<link>ether c8:5b:76:87:36:53 txqueuelen 1000 (Ethernet)RX packets 0 bytes 0 (0.0 B)RX errors 0 dropped 0 overruns 0 frame 0TX packets 0 bytes 0 (0.0 B)TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0 lo: flags=73<UP,LOOPBACK,RUNNING> mtu 65536inet 127.0.0.1 netmask 255.0.0.0inet6 ::1 prefixlen 128 scopeid 0x10<host>loop txqueuelen 0 (Local Loopback)RX packets 819357 bytes 263780151 (251.5 MiB)RX errors 0 dropped 0 overruns 0 frame 0TX packets 819357 bytes 263780151 (251.5 MiB)TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0 virbr0: flags=4099<UP,BROADCAST,MULTICAST> mtu 1500inet 192.168.122.1 netmask 255.255.255.0 broadcast 192.168.122.255ether 52:54:00:37:a4:20 txqueuelen 0 (Ethernet)RX packets 0 bytes 0 (0.0 B)RX errors 0 dropped 0 overruns 0 frame 0TX packets 0 bytes 0 (0.0 B)TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0 [root@foundation50 network-scripts]# virt-manager建立網(wǎng)橋
[root@foundation50 network-scripts]# ls ifcfg-enp1s0 ifdown-isdn ifup ifup-plip ifup-tunnel ifcfg-lo ifdown-post ifup-aliases ifup-plusb ifup-wireless ifdown ifdown-ppp ifup-bnep ifup-post init.ipv6-global ifdown-bnep ifdown-routes ifup-eth ifup-ppp network-functions ifdown-eth ifdown-sit ifup-ib ifup-routes network-functions-ipv6 ifdown-ib ifdown-Team ifup-ippp ifup-sit ifdown-ippp ifdown-TeamPort ifup-ipv6 ifup-Team ifdown-ipv6 ifdown-tunnel ifup-isdn ifup-TeamPort [root@foundation50 network-scripts]# vim ifcfg-enp1s0 [root@foundation50 network-scripts]# cat ifcfg-enp1s0 DEVICE=enp1s0 BOOTPROTO=none ONBOOT=yes BRIDGE=br0 [root@foundation50 network-scripts]# vim ifcfg-br0 [root@foundation50 network-scripts]# cat ifcfg-br0 DEVICE=br0 ONBOOT=yes BOOTPROTO=none IPADDR=172.25.254.50 NETMASK=255.255.255.0 TYPE=Bridge [root@foundation50 network-scripts]# systemctl stop NetworkManager.service [root@foundation50 network-scripts]# systemctl restart network [root@foundation50 network-scripts]# brctl show bridge name bridge id STP enabled interfaces br0 8000.c85b76873653 no enp1s0 virbr0 8000.52540037a420 yes virbr0-nic [root@foundation50 network-scripts]# virt-manager其他步驟和沒網(wǎng)橋的相同,不同的是如下圖:
四、網(wǎng)橋的建立與刪除(虛擬機(jī))
網(wǎng)橋的建立與刪除
[root@localhost Desktop]# brctl show bridge name bridge id STP enabled interfaces [root@localhost Desktop]# brctl addbr br0 [root@localhost Desktop]# ifconfig br0 br0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500inet6 fe80::bcab:1bff:fea8:249e prefixlen 64 scopeid 0x20<link>ether be:ab:1b:a8:24:9e txqueuelen 0 (Ethernet)RX packets 0 bytes 0 (0.0 B)RX errors 0 dropped 0 overruns 0 frame 0TX packets 8 bytes 648 (648.0 B)TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0 [root@localhost Desktop]# ifconfig br0 172.25.254.127/24 [root@localhost Desktop]# ifconfig br0 br0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500inet 172.25.254.127 netmask 255.255.255.0 broadcast 172.25.254.255inet6 fe80::bcab:1bff:fea8:249e prefixlen 64 scopeid 0x20<link>ether be:ab:1b:a8:24:9e txqueuelen 0 (Ethernet)RX packets 0 bytes 0 (0.0 B)RX errors 0 dropped 0 overruns 0 frame 0TX packets 19 bytes 3377 (3.2 KiB)TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0 [root@localhost Desktop]# brctl show bridge name bridge id STP enabled interfaces br0 8000.000000000000 no [root@localhost Desktop]# ping 172.25.254.50 PING 172.25.254.50 (172.25.254.50) 56(84) bytes of data. From 172.25.254.127 icmp_seq=1 Destination Host Unreachable From 172.25.254.127 icmp_seq=2 Destination Host Unreachable From 172.25.254.127 icmp_seq=3 Destination Host Unreachable From 172.25.254.127 icmp_seq=4 Destination Host Unreachable ^C --- 172.25.254.50 ping statistics --- 5 packets transmitted, 0 received, +4 errors, 100% packet loss, time 4000ms pipe 4 [root@localhost Desktop]# brctl addif br0 eth0 [root@localhost Desktop]# brctl show bridge name bridge id STP enabled interfaces br0 8000.52540000320a no eth0 [root@localhost Desktop]# ping 172.25.254.50 PING 172.25.254.50 (172.25.254.50) 56(84) bytes of data. 64 bytes from 172.25.254.50: icmp_seq=1 ttl=64 time=0.316 ms 64 bytes from 172.25.254.50: icmp_seq=2 ttl=64 time=0.148 ms 64 bytes from 172.25.254.50: icmp_seq=3 ttl=64 time=0.340 ms ^C --- 172.25.254.50 ping statistics --- 3 packets transmitted, 3 received, 0% packet loss, time 1999ms rtt min/avg/max/mdev = 0.148/0.268/0.340/0.085 ms [root@localhost Desktop]#
網(wǎng)橋的刪除
[root@localhost Desktop]# brctl show bridge name bridge id STP enabled interfaces br0 8000.52540000320a no eth0 [root@localhost Desktop]# brctl delif br0 eth0 [root@localhost Desktop]# brctl show bridge name bridge id STP enabled interfaces br0 8000.000000000000 no [root@localhost Desktop]# ifconfig br0 down [root@localhost Desktop]# ifconfig eth0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500ether 52:54:00:00:32:0a txqueuelen 1000 (Ethernet)RX packets 13 bytes 1026 (1.0 KiB)RX errors 0 dropped 0 overruns 0 frame 0TX packets 4 bytes 336 (336.0 B)TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0 eth1: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500ether 52:54:00:80:fa:d5 txqueuelen 1000 (Ethernet)RX packets 9 bytes 690 (690.0 B)RX errors 0 dropped 0 overruns 0 frame 0TX packets 0 bytes 0 (0.0 B)TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0 lo: flags=73<UP,LOOPBACK,RUNNING> mtu 65536inet 127.0.0.1 netmask 255.0.0.0inet6 ::1 prefixlen 128 scopeid 0x10<host>loop txqueuelen 0 (Local Loopback)RX packets 13 bytes 1116 (1.0 KiB)RX errors 0 dropped 0 overruns 0 frame 0TX packets 13 bytes 1116 (1.0 KiB)TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0 [root@localhost Desktop]# brctl delbr br0 [root@localhost Desktop]# brctl show bridge name bridge id STP enabled interfaces [root@localhost Desktop]#總結(jié)
以上是生活随笔為你收集整理的linux——高级网络配置之bond、team网络接口,网络桥接的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: linux——系统排错之引导恢复shel
- 下一篇: linux——部署DNS