linux的高级网络配置

一、什么时链路聚合

指将多个物理端口汇聚在一起,形成一个逻辑端口,以实现出/入流量吞吐量在各成员端口的负荷分担,交换机根据用户配置的端口负荷分担策略决定网络封包从 哪个成员端口发送到对端的交换机。当交换机检测到其中一个成员端口的链路发生故障时,就停止在此端口上发送封包,并根据负荷分担策略在剩下的链路中重新计 算报文的发送端口,故障端口恢复后再次担任收发端口。链路聚合在增加链路带宽、实现链路传输弹性和工程冗余等方面是一项很重要的技术。

  二 、链路聚合的作用

   1,提高稳定性;  2.提高网络宽度

  三、链路聚合的方式

    1).bond接口

    2.)选择linux以太网绑定方式

      模式0(平衡轮循),---轮循策略, 所有接口都采用轮循方式在所有 Slave 中传输封包 ; 任何 Slave 都可以接收

      模式1(主动备份),---容错,  一次只能使用一个 Slave 接口, 但是如果该接口出现故障 , 另一个 Slave 将 接替它

      模式2(广播)---容错。所有封包都通过所有 Slave 接口广播。

以下实验以模式1 (主动备份)来实验,实验环境:

   (1).删除原有网卡的所有配置文件

nm-connection-editor  

   (2).添加双网卡

 (3).以命令的方式 创建bond   接口  bond0

[root@localhost ~]#nmcli connection add con-name bond0 ifname bond0 type bond mode active-backup ip4 172.25.254.123/24 创建bond接口

为了更好的观察到实验效果,打开监控

[root@localhost ~]# watch -n 1  cat /proc/net/bonding/bond0

  

      <1>.在bond0 接口上添加网卡  eth0、eth1

[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

   <2.>.关掉其中一个发现还会正常工作(eth1 接替eth0的工作,继续运行)

[root@localhost ~]# ifconfig etho down

开启eth0 之后,eth0 作为替补出现

    <3.> 删除bond0 接口

[root@localhost ~]# nmcli connetction deletet bond0 
[root@localhost ~]# nmcli connetction deletet eth0 
[root@localhost ~]# nmcli connetction deletet eth1

(4). 以文件的方式配置bond接口

[root@localhost ~]# vim /etc/sysconfig/network-scripts/ifcfg-bond0

DEVICE=bond0
ONBOOT=yes
BOOTPROTO=none
IPADDR=172.25.254.123
PREFIX=24
TYPE=Bond
BONDING_OPTS=mode=active-backup
BONDING_MASTER=yes

[root@localhost ~]# vim /etc/sysconfig/network-scripts/ifcfg-eth0

DEVICE=eth0
ONBOOT=yes
BOOTPROTO=none
MASTER=bond0
SLAVE=yes

[root@localhost ~]# vim /etc/sysconfig/network-scripts/ifcfg-eth1

DEVICE=eth1
ONBOOT=yes
BOOTPROTO=none
MASTER=bond0
SLAVE=yes

[root@localhost ~]# systemctl restart network
[root@localhost ~]# systemctl restart NetworkManager


3)、配置team 网络接口

   1. Team和 bond0 功能类似
       Team不需要手动加载相应内核模块
       Team有更强的拓展性
        支持 8块网卡

   2.team的工作方式

   broadcast 广播容错
   roundrobin 平衡轮叫
   activebackup 主备
   loadbalance 负载均衡

  3.用命令的方式设定team接口      (以主备模式为例)

[root@localhost Desktop]# nmcli connection add con-name team0 ifname team0 type team config '{"runner":{"name":"activebackup"}}' ip4 172.25.254.123/24  
[root@localhost Desktop]# nmcli connection add con-name eth0 type team-slave ifname eth1 master team0 
[root@localhost Desktop]# nmcli connection add con-name eth1 type team-slave ifname eth0 master team0

   打开监控 查看

[root@localhost Desktop]# watch -n 1 teamdctl team0 stat

关掉eth0,可以看到team0接口正常工作

开启eth0 ,eth0 就会作为eth1的备用接口出现

4.文件方式创建team接口

[root@localhost Desktop]# cd /etc/sysconfig/network-scripts/
[root@localhost network-scripts]# vim ifcfg-team0 

DEVICE=team0
ONBOOT=yes
BOOTPROTO=none
IPADDR=172.25.254.110
PREFIX=24
TEAM_CONFIG='{"runner":{"name":"activebackup"}}'
TYPE=Team

[root@localhost network-scripts]# vim ifcfg-eth0

DEVICE=eth0
ONBOOT=yes
BOOTPROTO=none
DEVICETYPE=TeamPort
TEAM_MASTER=team0
[root@localhost network-scripts]# vim ifcfg-eth1

DEVICE=eth1
ONBOOT=yes
BOOTPROTO=none
DEVICETYPE=TeamPort
TEAM_MASTER=team0

[root@localhost Desktop]# systemctl restart network
[root@localhost Desktop]# systemctl restart NetworkManager  

二、网络桥接

Linux网桥是一种以同种协议连接两个局域网的产品。可以把它看成是一个决定发送的包是到自己的局域网还是到另一个局域网的设备。linux网桥检查局域网上所有的包,在同一个局域网中传送它,如果不是同一个网中的,就将它发到别的网上。

1.文件配置网络桥接

实验环境:以真机为例:

[root@localhost Desktop]# mv ifcfg-enp0s25 ifcfg-br0 /mnt  //备份br0、enp0s25
[root@localhost Desktop]# nm-connection-editor   //删除掉virbr0 、virbr1 之外的所有接口
[root@localhost Desktop]# reboot  //重启网络 -->  或者执行 systemctl restart network 
[root@localhost Desktop]#  cd /etc/sysconfig/network-scripts/
[root@localhost network-scripts]# vim ifcfg-enp0s25

BOOTPROTO=none
DEVICE=enp0s25
ONBOOT=yes
BRIDGE=br0

[root@localhost network-scripts]# vim ifcfg-br0

TYPE=Bridge
DEVICE=br0
BOOTPROTO=none
IPADDR=172.25.254.10
PREFIX=24
ONBOOT=yes

[root@localhost Desktop]# systemctl restart network
[root@localhost Desktop]# systemctl restart NetworkManager

查看网桥:brctl   show

[root@foundation77 network-scripts]# brctl show
bridge name    bridge id        STP enabled     interfaces
br0         8000.0021ccc1010e   no              enp0s25
virbr0      8000.525400a676d2   yes             virbr0-nic
virbr1      8000.525400c0bf57   yes             virbr1-nic

搭建成功。

2.命令方式搭建网桥

命令解释
brctl    show查看网桥
brctl    addbr添加网桥
brctl    delbr删除网桥
brctl    addif添加网桥接口
brctl     delif删除网桥接口

实验:以下实验对象为虚拟机

[root@localhost ~]# brctl  show
bridge name     bridge id       STP enabled     interfaces

[root@localhost ~]# brctl  addbr  br0
[root@localhost ~]# ifconifg br0 172.25.254.123/24  //给br0 添加一个临时ip ,子网掩码为:255.255.255.0
[root@localhost ~]# brctl  show
bridge name    bridge id       STP enabled     interfaces
br0         8000.5254007ca6f1      no

[root@localhost ~]# ping 172.25.254.77   //ping 不通,因为网桥没有添加网卡
[root@localhost ~]# brctl  addif  br0 eth0   //添加网卡eth0
[root@localhost ~]# brctl  show
bridge name    bridge id       STP enabled     interfaces
br0         8000.5254007ca6f1      no           eth0

[root@localhost ~]# ping 172.25.254.77   //可以ping通

注意:以上实验为临时设置,reboot  重启之后所有设置会失效。

3.网桥的删除

[root@localhost ~]# brctl delif br0 eth0   //删除网桥br0的网卡eth0
[root@localhost ~]# ifconifg br0 down  // 必须关掉网桥,之后在删除,否则无法删除
[root@localhost ~]# brctl delbr br0   //删除网桥

删除成功。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值