linux网络链路聚合,网桥

linux网桥链路聚合

它将两个或更多物理网络接口(如以太网口)组合在一起,形成一个逻辑上的高带宽、高可用性的网络通道。这种技术可以提高网络性能,增强数据传输的可靠性,当单个链路故障时,流量可以自动切换到其他链路继续传输。

常用工作模式:

roundrobin: 以轮循的模式传输所有端口的包
activebackup:主备模式这是一个故障迁移程序,监控链接更改并选择活动的端口进行传输
loadbalance: 监控流量并使用哈希函数以尝试在选择传输端口的时候达到完美均衡
broadcast: 广播容错,设备通过所有端口传输数据包

 配置  activebakup工作模式

node1,node2均添加了两块网卡

node1

 node2

 node1:

先将添加到两块网卡删掉

[root@node1 ~]# nmcli connection show 
NAME                UUID                                  TYPE      DEVICE 
ens160              f50e5c5b-e1b2-33d2-bc0d-d2cfe7ed0c05  ethernet  ens160 
lo                  12284601-7c7f-44f1-91be-e3c9db7b1309  loopback  lo     
Wired connection 1  09e37243-523b-3626-819a-3ef2fd1cf457  ethernet  --     
Wired connection 2  328bdbd9-836d-387f-a4bf-a0fe7a5ad912  ethernet  --     
[root@node1 ~]# nmcli connection delete Wired\ connection\ 1
Connection 'Wired connection 1' (09e37243-523b-3626-819a-3ef2fd1cf457) successfully deleted.
[root@node1 ~]# nmcli connection delete Wired\ connection\ 2
Connection 'Wired connection 2' (328bdbd9-836d-387f-a4bf-a0fe7a5ad912) successfully deleted.
[root@node1 ~]# nmcli connection show 
NAME    UUID                                  TYPE      DEVICE 
ens160  f50e5c5b-e1b2-33d2-bc0d-d2cfe7ed0c05  ethernet  ens160 
lo      12284601-7c7f-44f1-91be-e3c9db7b1309  loopback  lo     
[root@node1 ~]#

创建组接口

[root@node1 ~]# nmcli connection add con-name team0 type team ifname team0 config '{"runner":  {"name": "activebackup"}}'
Connection 'team0' (9c409329-4c2f-4254-b83b-dc5c511ecebe) successfully added.

 为team0设置ip地址

[root@node1 ~]# nmcli connection modify team0 ipv4.addresses 192.168.0.1/24 ipv4.method manual connection.autoconnect yes 
[root@node1 ~]# 

将网络接口192,224添加到添加到team0中

[root@node1 ~]# nmcli connection add con-name team0-ens192 ifname ens192 type team-slave master team0 
Connection 'team0-ens192' (aad1367b-6c0a-41d3-a16d-94082d73f2a7) successfully added.
[root@node1 ~]# nmcli connection add con-name team0-ens1224 ifname ens224 type team-slave master team0 
Connection 'team0-ens1224' (361bb99c-b210-44da-8e0e-b4155b7bfa7e) successfully added.


[root@node1 ~]# nmcli connection show            // 查看
NAME           UUID                                  TYPE      DEVICE 
ens160         f50e5c5b-e1b2-33d2-bc0d-d2cfe7ed0c05  ethernet  ens160 
team0          9c409329-4c2f-4254-b83b-dc5c511ecebe  team      team0  
team0-ens1224  361bb99c-b210-44da-8e0e-b4155b7bfa7e  ethernet  ens224 
team0-ens192   aad1367b-6c0a-41d3-a16d-94082d73f2a7  ethernet  ens192 
lo             12284601-7c7f-44f1-91be-e3c9db7b1309  loopback  lo     
[root@node1 ~]# 

使用 ip a 查看

3: ens192: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc fq_codel master team0 state UP group default qlen 1000
    link/ether 00:0c:29:b8:d7:5b brd ff:ff:ff:ff:ff:ff
    altname enp11s0
4: ens224: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc fq_codel master team0 state UP group default qlen 1000
    link/ether 00:0c:29:b8:d7:5b brd ff:ff:ff:ff:ff:ff permaddr 00:0c:29:b8:d7:65
    altname enp19s0
6: team0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc noqueue state UP group default qlen 1000
    link/ether 00:0c:29:b8:d7:5b brd ff:ff:ff:ff:ff:ff
    inet 192.168.0.1/24 brd 192.168.0.255 scope global noprefixroute team0
       valid_lft forever preferred_lft forever
    inet6 fe80::ecb9:d74:31bf:5199/64 scope link noprefixroute 
       valid_lft forever preferred_lft forever

查看team0信息

[root@node1 ~]# teamdctl team0 state
setup:
  runner: activebackup
ports:
  ens192
    link watches:
      link summary: up
      instance[link_watch_0]:
        name: ethtool
        link: up
        down count: 0
  ens224
    link watches:
      link summary: up
      instance[link_watch_0]:
        name: ethtool
        link: up
        down count: 0
runner:
  active port: ens192        // 此时工作的接口是ens192,谁先添加就来谁就是主
[root@node1 ~]# 

node2配置同理

[root@node2 ~]# teamdctl team0 state
setup:
  runner: activebackup
ports:
  ens192
    link watches:
      link summary: up
      instance[link_watch_0]:
        name: ethtool
        link: up
        down count: 0
  ens224
    link watches:
      link summary: up
      instance[link_watch_0]:
        name: ethtool
        link: up
        down count: 0
runner:
  active port: ens192

先用node1 ping node2是否成功

[root@node1 ~]# ping 192.168.0.2
PING 192.168.0.2 (192.168.0.2) 56(84) bytes of data.
64 bytes from 192.168.0.2: icmp_seq=1 ttl=64 time=0.242 ms
64 bytes from 192.168.0.2: icmp_seq=2 ttl=64 time=0.251 ms
64 bytes from 192.168.0.2: icmp_seq=3 ttl=64 time=0.218 ms
^C
--- 192.168.0.2 ping statistics ---
3 packets transmitted, 3 received, 0% packet loss, time 2084ms
rtt min/avg/max/mdev = 0.218/0.237/0.251/0.013 ms
[root@node1 ~]# 

如果在工作的192借口出现故障,那此时ens224就会顶替192来工作

软件网桥

是一个软件层面的网络设备,用于在Linux系统中创建和管理网络桥接。它允许将多个物理或虚拟网络接口连接在一起,以创建一个共享相同网络段的网络。

主要功能:MAC学习,报文转发

 在linux中创建软件网桥

 先将添加到两块网卡删掉

[root@node1 ~]# nmcli connection show 
NAME                UUID                                  TYPE      DEVICE 
ens160              f50e5c5b-e1b2-33d2-bc0d-d2cfe7ed0c05  ethernet  ens160 
team0               9c409329-4c2f-4254-b83b-dc5c511ecebe  team      team0  
team0-ens1224       361bb99c-b210-44da-8e0e-b4155b7bfa7e  ethernet  ens224 
team0-ens192        aad1367b-6c0a-41d3-a16d-94082d73f2a7  ethernet  ens192 
Wired connection 1  f2a01947-cf0c-3007-a8bc-2b5eeaffed13  ethernet  ens256 
Wired connection 2  a9b2aabc-82be-3c8c-bc31-9a90b8e1ae56  ethernet  ens161 
lo                  12284601-7c7f-44f1-91be-e3c9db7b1309  loopback  lo     
[root@node1 ~]# nmcli connection delete Wired\ connection\ 1
Connection 'Wired connection 1' (f2a01947-cf0c-3007-a8bc-2b5eeaffed13) successfully deleted.
[root@node1 ~]# nmcli connection delete Wired\ connection\ 2
Connection 'Wired connection 2' (a9b2aabc-82be-3c8c-bc31-9a90b8e1ae56) successfully deleted.
[root@node1 ~]# nmcli connection show 
NAME           UUID                                  TYPE      DEVICE 
ens160         f50e5c5b-e1b2-33d2-bc0d-d2cfe7ed0c05  ethernet  ens160 
team0          9c409329-4c2f-4254-b83b-dc5c511ecebe  team      team0  
team0-ens1224  361bb99c-b210-44da-8e0e-b4155b7bfa7e  ethernet  ens224 
team0-ens192   aad1367b-6c0a-41d3-a16d-94082d73f2a7  ethernet  ens192 
lo             12284601-7c7f-44f1-91be-e3c9db7b1309  loopback  lo     
[root@node1 ~]# 

定义网桥

[root@node1 ~]# nmcli connection add con-name bridge0 ifname bridge0 type bridge
Connection 'bridge0' (5ec35030-a228-4851-8cb6-7f1b73304faa) successfully added.
[root@node1 ~]# nmcli connection show 
NAME           UUID                                  TYPE      DEVICE  
ens160         f50e5c5b-e1b2-33d2-bc0d-d2cfe7ed0c05  ethernet  ens160  
team0          9c409329-4c2f-4254-b83b-dc5c511ecebe  team      team0   
team0-ens1224  361bb99c-b210-44da-8e0e-b4155b7bfa7e  ethernet  ens224  
team0-ens192   aad1367b-6c0a-41d3-a16d-94082d73f2a7  ethernet  ens192  
bridge0        5ec35030-a228-4851-8cb6-7f1b73304faa  bridge    bridge0 
lo             12284601-7c7f-44f1-91be-e3c9db7b1309  loopback  lo      
[root@node1 ~]# 

设置bridge0

[root@node1 ~]# nmcli connection modify bridge0 ipv4.addresses 192.168.1.1/24 ipv4.method manual connection.autoconnect yes 
[root@node1 ~]# 

给他添加物理网卡

[root@node1 ~]# nmcli connection add con-name bridge0-ens161 ifname ens161 type bridge-slave master bridge0 
Connection 'bridge0-ens161' (54541942-8590-43e3-8f54-2a99c025145a) successfully added.
[root@node1 ~]# nmcli connection add con-name bridge0-ens256 ifname ens256 type bridge-slave master bridge0 
Connection 'bridge0-ens256' (5f9693d0-0355-427a-adf8-3f1a2e18d045) successfully added.

启动一下bridge0

8: ens256: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc fq_codel master bridge0 state UP group default qlen 1000
    link/ether 00:0c:29:b8:d7:6f brd ff:ff:ff:ff:ff:ff
    altname enp27s0
9: ens161: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc fq_codel master bridge0 state UP group default qlen 1000
    link/ether 00:0c:29:b8:d7:79 brd ff:ff:ff:ff:ff:ff
    altname enp4s0
10: bridge0: <NO-CARRIER,BROADCAST,MULTICAST,UP> mtu 1500 qdisc noqueue state DOWN group default qlen 1000
    link/ether 00:0c:29:b8:d7:6f brd ff:ff:ff:ff:ff:ff
    inet 192.168.1.1/24 brd 192.168.1.255 scope global noprefixroute bridge0
       valid_lft forever preferred_lft forever

此时bridge0的MAC地址和ens256是一样的,说明此时工作的是ens256

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值