日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 运维知识 > linux >内容正文

linux

linux——高级网络配置之bond、team网络接口,网络桥接

發布時間:2025/3/19 linux 36 豆豆
生活随笔 收集整理的這篇文章主要介紹了 linux——高级网络配置之bond、team网络接口,网络桥接 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

一、bond 網絡接口

?????? Red Hat Enterprise Linux 允許管理員使用 bonding 內核模塊和稱為通道綁定接口的特殊網絡接口將多個網絡接口綁定到一個通道。根據選擇的綁定模式,通道綁定使兩個或更多個網絡接口作為一個網絡接口,從而增加帶寬和 / 提供冗余性。

選擇linux以太網綁定模式

?? 目前網卡綁定mode共有七種(06):bond0bondbond1bond2bond3bond4bond5bond6。這里介紹幾種,然后會有關于模式1的實驗詳細說明。

模式0(平衡輪循):輪循策略。所有接口都采用輪循方式在所有 Slave 中傳輸封包;任何 Slave 都可以接收。

模式1(主動備份):容錯。一次只能使用一個 Slave 接口,但是如果該接口出現故障,另一個 Slave 將接替它。

模式3(廣播):容錯。所有封包都通過所有 Slave 接口廣播。

實驗——mode1(主動備份)

1.為做實驗的虛擬機添加兩塊網卡 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 ##將已經配置過的eth0恢復到默認狀態,即未配置前 [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網絡接口,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 ##查看網絡接口bond0的信息。該文件只會在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]#

開啟第二個命令面板,輸入以下監控命令:

[root@localhost Desktop]# watch -n 15 cat /proc/net/bonding/bond0




除了用命令的方式添加,還可以通過建立配置文件的方式

[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網絡接口bond0的所有配置(不影響下面team網絡接口的實驗)

[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 網絡接口(企業七之前的版本沒有這個功能)

  • Team bond0 功能類似
  • Team 不需要手動加載相應內核模塊
  • Team 有更強的擴展性
  • 支持8塊網卡
  • Team 的種類:

broadcast ????廣播容錯

roundrobin ???平衡輪叫:比較機械

activebackup ?主動備份

loadbalance ??負載均衡:將任務平衡分配

?team 網絡接口

[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網絡接口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: ##此處表示是可用接口,當前表示沒有可用接口 [root@localhost ~]#

開啟第二個命令面板:輸入以下監控命令

[root@localhost ~]# watch -n 5 teamdctl team0 stat



?

注意:刪除team網絡接口team0的所有配置

[root@localhost ~]# nmcli connection delete eth0 [root@localhost ~]# nmcli connection delete eth1 [root@localhost ~]# nmcli connection delete team0

三、有無網橋的區別實驗(真機)

[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


建立網橋

[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

其他步驟和沒網橋的相同,不同的是如下圖:


四、網橋的建立與刪除(虛擬機)

  • 網橋的建立與刪除
網橋的建立

[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]#

網橋的刪除

[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]#

總結

以上是生活随笔為你收集整理的linux——高级网络配置之bond、team网络接口,网络桥接的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。