網絡橋接
• 網絡橋接用網絡橋實現共享上網主機和客戶機除了利用軟件外,還可以用系統自帶的網絡橋建立連接用雙網卡的機器做主機
網絡橋接的配置
• vim /etc/sysconfig/network-scripts/ifcfg-eth0
– BRIDGE=br0
• vim /etc/sysconfig/network-scripts/ifcfg-br0
– TYPE=Bridge
網絡橋接的管理命令
• brctl
### 橋接管理命令
– show ### 顯示
– addbr ### 添加網橋
– delbr ### 刪除網橋
– addif ### 添加網橋連接
– delif ### 刪除網橋連接
www.westos.orgbond 網絡
• Red Hat Enterprise Linux 允許管理員使用bonding 內核模塊和稱爲通道綁定接口的特殊網絡接口將多個網絡接口綁定到一個通道。根據選擇的綁定模式 , 通道綁定使兩個或更多個網絡接口作爲一個網絡接口 , 從而增加帶寬和 / 提供冗餘性
選擇 Linux 以太網綁定模式
• 模式 0 ( 平衡輪循 ) - 輪循策略 , 所有接口都使用
採用輪循方式在所有 Slave 中傳輸封包 ; 任何
Slave 都可以接收
• 模式 1 ( 主動備份 ) - 容錯。一次只能使用一個
Slave 接口 , 但是如果該接口出現故障 , 另一個
Slave 將 接替它
• 模式 3 ( 廣播 ) - 容錯。所有封包都通過所有
Slave 接口廣播
利用 nmcli 命令管理 bond
• nmcli con add type bond con-name bond0
ifname bond0 mode active-backup
• nmcli con mod bond0 ipv4.addresses
1.2.3.4/24
• nmcli con add type bond-slave ifname
eth0 master bond0 con-name bond0-eth1
• nmcli con add type bond-slave ifname
eth1 master bond0 con-name bond0-eth2
主動備份配置示例
• 建立綁定接口 bond0 配置文件 :
/etc/sysconfig/network-scripts/ifcfg-bond0
– DEVICE="bond0"
– BOOTPROTO="none"
– IPADDR="10.1.1.250"
– PREFIX=”24”
– ONBOOT="yes"
– BONDING_OPTS=”mode=1 miimon=50”
• 建立 Slave 接口 eth0 配置文件 :
/etc/sysconfig/network-scripts/ifcfg-eth0
– DEVICE="eth0"
– BOOTPROTO="none"
– ONBOOT="yes"
– MASTER="bond0"
– SLAVE="yes“
• 建立 Slave 接口 eth1 配置文件 :
/etc/sysconfig/network-scripts/ifcfg-eth1
– DEVICE="eth1"
– BOOTPROTO="none"
– ONBOOT="yes"
– MASTER="bond0"
– SLAVE="yes“
• 配置系統加載 binding 模塊 :
/etc/modprobe.d/bonding.conf
– alias bond0 bonding
• ifenslave bond0 eth0 eth1
• 查看 bonding 狀態
– cat /proc/net/bonding/bond0
Team 接口
• Team 和 bond0 功能類似
• Team 不需要手動加載相應內核模塊
• Team 有更強的拓展性
– 支持 8 快網卡
Team 的種類
broadcast
roundrobin
activebackup
loadbalance
廣播容錯
輪詢
主備
負載均衡
通過 nmcli 設定 team
• nmcli con add type team con-name team0
ifname team0 config '{"runner": {"name":
"loadbalance"}}'
• nmcli con mod team0 ipv4.addresses 1.2.3.4/24
• nmcli con mod team0 ipv4.method manual
• nmcli con add type team-slave ifname eth0
master team0 con-name team0-eth1
• nmcli con add type team-slave ifname eth1
master team0 con-name team0-eth2
操作實例:
1.橋接
(1)圖形橋接
[root@foudation37 ~]# cd /etc/sysconfig//network-scripts/
[root@foudation37 network-scripts]# rm -fr ifcfg-br0 ifcfg-salkdfnv
[root@foudation37 network-scripts]# ifconfig enp0s25
enp0s25: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500
inet 172.25.254.37 netmask 255.255.255.0 broadcast 172.25.254.255
inet6 fe80::221:ccff:fe61:9d31 prefixlen 64 scopeid 0x20<link>
ether 00:21:cc:61:9d:31 txqueuelen 1000 (Ethernet)
RX packets 42308 bytes 62994602 (60.0 MiB)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 2734 bytes 196210 (191.6 KiB)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
device interrupt 20 memory 0xd2600000-d2620000
[root@foudation37 network-scripts]# vim ifcfg-Ethernet_connection_1
[root@foudation37 network-scripts]# vim ifcfg-br0
[root@foudation37 network-scripts]# cat ifcfg-Ethernet_connection_1
BOOTPROTO=none
NAME="Ethernet connection 1"
DEVICE=enp0s25
ONBOOT=yes
BRIDGE=br0
[root@foudation37 network-scripts]# cat ifcfg-br0DEVICE=br0
BOOTPROTO=none
TYPE=bridge
IPADDR=172.25.254.37
PREFIX=24
ONBOOT=yes
[root@foudation37 network-scripts]# systemctl stop NetworkManager.service
[root@foudation37 network-scripts]# systemctl restart network
[root@foudation37 network-scripts]# ifconfig br0
br0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500
inet 172.25.254.37 netmask 255.255.255.0 broadcast 172.25.254.255
inet6 fe80::221:ccff:fe61:9d31 prefixlen 64 scopeid 0x20<link>
ether 00:21:cc:61:9d:31 txqueuelen 0 (Ethernet)
RX packets 1 bytes 142 (142.0 B)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 22 bytes 2949 (2.8 KiB)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
[root@foudation37 network-scripts]# systemctl start NetworkManager.service
(2)命令橋接
[root@localhost ~]# brctl show
bridge name bridge id STP enabled interfaces
[root@localhost ~]# brctl addbr br0 ##建立br0橋接
[root@localhost ~]# brctl show
bridge name bridge id STP enabled interfaces
br0 8000.000000000000 no
[root@localhost ~]# brctl addif br0 eth0 ## 將br0插到eth0上
[root@localhost ~]brctl show
[root@localhost ~]ifconfig br0 172.25.254.237 netmask 255.255.255.0
[root@localhost ~] brctl delif br0 eth0 ##將br0從eth0上取出來
[root@localhost ~] brctl delbr br0 ##刪除br0
2.bond ##支持雙網卡
(1)運用virt-manger 管理器 添加eth0和eth1雙網卡
(2)nm-connection-editor 刪除所有配置
(3)
[root@localhost ~]systemctl start Networkmanger
[root@localhost ~] nmcli con-name bond0 type bond mode active-backup ip4 172.25.254.137/24
[root@localhost ~] nmcli connection add con-name eth0 ifname eth0 type bond-slave master bond0
[root@localhost ~] nmcli connection add con-name eth1 ifname eth1 type bond-slave master bond0
##將會有雙網絡卡支持工作,一個損壞,另一個會頂替
##可用 watch -n 1 cat /proc/net/bonding/bond0來監控
3.team ##最多支持8個網卡
[root@localhost ~] nmcli connection add con-name team0 ifname team0 type team config '{"runner":{“name”:“activebackup”}' ip4 172.25.254.137/24
[root@localhost ~] nmcli connection add con-name eth0 ifname eth0 type team-slave master team0
[root@localhost ~] nmcli connection add con-name eth1 ifname eth1 type team-slave master team0
可用 watch -n 1 teamdctl team0 stat來監控