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 1500
        inet 172.25.254.150  netmask 255.255.255.0  broadcast 172.25.254.255
        inet6 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 0
        TX 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 1500
        ether 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 0
        TX 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 65536
        inet 127.0.0.1  netmask 255.0.0.0
        inet6 ::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 0
        TX 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 1500
        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 0
        TX 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 1500
        inet 172.25.254.129  netmask 255.255.255.0  broadcast 172.25.254.255
        ether 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 0
        TX 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 1500
        ether 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 0
        TX 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 1500
        ether 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 0
        TX 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 65536
        inet 127.0.0.1  netmask 255.0.0.0
        inet6 ::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 0
        TX 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 1500
        inet 172.25.254.50  netmask 255.255.255.0  broadcast 172.25.254.255
        inet6 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 0
        TX 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 65536
        inet 127.0.0.1  netmask 255.0.0.0
        inet6 ::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 0
        TX 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 1500
        inet 192.168.122.1  netmask 255.255.255.0  broadcast 192.168.122.255
        ether 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 0
        TX 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 1500
        inet6 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 0
        TX 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 1500
        inet 172.25.254.127  netmask 255.255.255.0  broadcast 172.25.254.255
        inet6 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 0
        TX 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 1500
        ether 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 0
        TX 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 1500
        ether 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 0
        TX 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 65536
        inet 127.0.0.1  netmask 255.0.0.0
        inet6 ::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 0
        TX 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]#
  • 2
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值