网络桥接及链路聚合

来源:互联网 发布:树莓派gpio python 编辑:程序博客网 时间:2024/06/07 00:02

1. 在真机中添加网桥

目的:使在一个局域网中的主机能够直接进行数据传输

    cd /etc/sysconfig/network-script/

    vim ifcfg-br0                                                                    ##配置网桥


    vim ifcfg-en4ps0                                                             ##配置物理网卡

    systemctl restart  network

建立完网桥后,创建虚拟机时就会在选择网络中有所创建的网桥


2. 网桥连接

    brctl show                                                                         ##显示网桥

    brctl addbr  br0                                                                 ##添加网桥br0

    ifconfig br0 172.25.254.190 netmask 255.255.255.0       ##给网桥ip和子网掩码

    brctl addif br0 eth0                                                           ##添加网桥连接

    ifconfig br0 down                                                              ##关闭网桥

    brctl delif br0 eth0                                                             ##删除网桥连接

    brctl delbr br0                                                                    ##删除网桥



 


3. 链路聚合

   目的:将两个网卡进行链路绑定,当一个网卡突然坏掉时,绑定的另一个网卡即能及时替补上去,从而让主机能够继续正常运行。



a. bonding链路聚合

   创建bond链接

    nmcli connection add con-name bond0 ifname bond0 type bond mode active-backup ip4 172.25.254.190/24


    测试:ping 172.25.254.90


    发现虽然bond0上面给了ip,但ping不通。是因为bond0上面缺少物理网卡的支持

    在bond链接中加入两个网卡eth0与eth1

    nmcli connection add con-name eth0 ifname eth0 type bond-slave master bond0

    nmcli connection add con-name eth1 ifname eth1 type bond-slave master bond0


    测试:ping 172.25.254.90 (即可以ping通)


    ifconfig  eth1 down                                             ##关闭eth1这个网卡

    ping 172.25.254.90 (依然可以Ping通)  是因为eth0网卡立即上去替换了eth1



    ifconfig  eth1 up                                                 ##开启eth0这个网卡

    发现工作的依旧是eth0,说明这两个网卡之间并不存在优先级

    nmcli connection delete eth1                              ##删除eth1这个网卡



bonding链路聚合可以有效的控制两个网卡,让其进行多模式的工作,但是他限制了最多添加的网卡为两块.



注意:可以watch -n 1 cat /proc/net/bonding/bond0 来监控哪个网卡正在被使用


b. team链路聚合

    *team的种类

      broadcast                                                          ##广播容错

      roundrobin                                                         ##平衡轮叫

      activebackup                                                     ##主备

      loadbalance                                                       ##负载均衡

    创建team链路

    nmcli connection add con-name team0 ifname team0 config'{"runner":{"name":"activebackup"}}' ip4 172.25.254.190/24

    teamdctl team0 state                                          ##查看team链路的状态


    添加网卡到team链路

    nmcli connection add con-name eth0 ifname eth0 type team-slave master team0

    nmcli connection add con-name eth1 ifname eth1 type team-slave master team0

    测试可以和bonding链路的形式一样


注意:删除一个网卡上的ip时可以使用命令 ip address del ip号 dev eth0











    


     

   

原创粉丝点击