基于linux下的高级网络配置

bond和team网络接口配置

网卡是一种物理硬件;如果将多块网卡连接起来,当一块网卡损坏,网络依旧可以正常运行,可以有效的防止因为网卡损坏带来的损失,为用户提供不间断的网络服务,同时也可以提高网络访问速度,实现网络链路聚合方式有”bond”和”team”两种,”bond”模式最多可以添加两块网卡,”team”模式最多可以添加八块网卡。


1、bond网络接口的配置

a . 准备环境

[root@desktop Desktop]#nmcli connection delete eth0  //删除eth0网卡,清除虚拟机之前的配置

virt-manager //打开虚拟机管理,再添加一块网卡eth1

[root@desktop Desktop]# nmcli connection add con-name bond0 ifname bond0 type bond mode active-backup ip4 172.25.254.174/24  //新建bond接口
Connection 'bond0' (d6e89693-492b-436b-a759-aa8811384309) successfully added.

这里写图片描述
b . 打开监控

[root@desktop Desktop]# watch -n 1 cat /proc/net/bonding/bond0  //bond0当前的状态

监控效果如图所示:
这里写图片描述
c .第一次 ping 测试

[root@desktop Desktop]# ping 172.25.254.74 //查看当前网络是否可以连接,检测之后发现网络是不通,因为此时并没有给bond添加网络接口
这里写图片描述
这里写图片描述
d . 添加eth0和eth1网卡作为bond网络接口

[root@desktop Desktop]# nmcli connection add con-name eth0 ifname eth0 type bond-slave master bond0 //添加eth0作为bond0的网络接口
Connection 'eth0' (7521ff17-5cc8-4f82-9acb-975a626c8ebb) successfully added.
[root@desktop Desktop]# nmcli connection add con-name eth1 ifname eth1 type bond-slave master bond0//添加eth1作为闲置网卡,一旦eth0发生故障,eth1将会顶替eth0继续工作 
Connection 'eth1' (888a81a8-bae2-4ebc-8232-18a36224b1ea) successfully added.

这里写图片描述
e . 第二次 ping 测试

[root@desktop Desktop]# ping 172.25.254.74 //检查网络是否通畅
这里写图片描述
f . 断开eth0,检测网络是否通畅

[root@desktop Desktop]# ifconfig eth0 down  //关闭eth0网卡
[root@desktop Desktop]# ping 172.25.254.74
[root@desktop Desktop]#ifconfig eth0 up    // 激活网卡eth0,此时的eth0将作为闲置网卡,一旦eth1损坏之后,eth0将会代替工作

关闭eth0后,ping 172.25.254.74主机,发现网络并未断开
这里写图片描述


2、team网络接口配置

首先,清除上个实验的结果;

nmcli connection delete bond0 //删除bond0接口
nmcli connection delete eth0 //删除eth0网卡
nmcli connection delete eth1 //删除eth1网卡

这里写图片描述
建立网络接口

[root@desktop Desktop]# nmcli connection add con-name team0 ifname team0 type team config '{"runner":{"name":"activebackup"}}' ip4 172.25.254.174/24  //新建team0接口
Connection 'team0' (e057d6dd-0cf1-4957-89d8-8810a299f817) successfully added.
[root@desktop Desktop]# nmcli connection add con-name eth0 ifname eth0 type team-slave master team0  //设定eth0网卡作为team0网络接口
Connection 'eth0' (9b7b4304-c948-4669-b3bf-962d9f15d32b) successfully added.
[root@desktop Desktop]# nmcli connection add con-name eth1 ifname eth1 type team-slave master team0  //设定eth1网卡作为team0网络接口,但此时活跃的是eth0,eth1作为备份
Connection 'eth1' (40a8ad96-58b2-40e0-ac6f-8a664d678f00) successfully added.

打开监控

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

这里写图片描述
检测网络
ping 主机,网络是通的。
这里写图片描述
关闭eth0,进行ping测试

[root@desktop Desktop]# ifconfig eth0 down  //断开eth0网络接口
[root@desktop Desktop]# ping 172.25.254.74  //网络依旧可以连通,因为eth1代替了eth0接口处于工作状态

这里写图片描述
这里写图片描述


网络桥接

网络桥接用网络桥实现共享上网主机和客户机除了利用软件之外,还可以用系统自带的网络桥建立连接用双网卡的机器做主机

1、配置网络桥接(真机)

[root@foundation74 ~]$cd /etc/sysconfig/network-scripts/
[root@foundation74 network-scripts]# mv ifcfg-br0 ifcfg-enp0s25 /opt  //备份网络配置文件
[root@foundation74 network-scripts]# nm-connection-editor  //手动删除ethernet、wifi所有的选项以及bridge中的enp0s25,新建westos
[root@foundation74 network-scripts]# systemctl restart network  //重启网络
[root@foundation74 network-scripts]# vim ifcfg-westos  //编辑网卡配置文件ifcfg-westos
   //文件内容
   DEVICE=enp0s25
   ONBOOT=yes
   BOOTPROTO=none
   BRIDGE=br0
[root@foundation74 network-scripts]# vim ifcfg-br0  //编辑桥接配置文件
   //文件内容
   DEVICE=br0
   ONBOOT=yes
   BOOTPROTO=none
   IPADDR=172.25.254.74
   NETMASK=255.255.255.0
   TYPE=Bridge
[root@foundation74 network-scripts]# systemctl stop NetworkManager.service //关闭网络管理服务
[root@foundation74 network-scripts]# systemctl restart network //重启网络
[root@foundation74 network-scripts]# brctl show  //查看桥接接口是否存在

文件/etc/sysconfig/network-scripts/ifcfg-westos,内容为:

这里写图片描述
文件/etc/sysconfig/network-scripts/ifcfg-br0,内容为:
这里写图片描述
这里写图片描述
检测网络桥接的影响:
安装2个虚拟机(一种网络连接设置为bridge方式;另一种网络连接设置为NAT方式)
同时执行命令ping 172.25.254.74,比较两者的时间;(网桥连接的网络连接较快)


2、临时桥接接口设置(虚拟机)
首先,清除上一步的实验操作;
这里写图片描述

//新建桥接接口
[root@desktop Desktop]# brctl show
bridge name bridge id       STP enabled interfaces
[root@desktop Desktop]# brctl addbr br0   //建立桥接接口
[root@desktop Desktop]# brctl show
bridge name bridge id       STP enabled interfaces
br0     8000.000000000000   no      

这里写图片描述

[root@desktop Desktop]# ifconfig br0 172.25.254.174/24 //配置br0
[root@desktop Desktop]# ping 172.25.254.74
//ping 172.25.254.74查看网络是否通畅,br0是没有网络接口的,所以ping不通 

这里写图片描述

//配置桥接接口的网卡信息
[root@desktop Desktop]# brctl addif br0 eth0
[root@desktop Desktop]# brctl show
bridge name bridge id       STP enabled interfaces
br0     8000.5254007ca6f1   no      eth0

//检测网络是否通
[root@desktop Desktop]# ping 172.25.254.74

这里写图片描述
注:若是reboot之后,临时设置会失效

//删除桥接接口的网卡
[root@desktop Desktop]# brctl delif br0 eth0
[root@desktop Desktop]# brctl show
bridge name bridge id       STP enabled interfaces
br0     8000.000000000000   no      
//停止桥接接口工作
[root@desktop Desktop]# ifconfig br0 down
//删除桥接接口
[root@desktop Desktop]# brctl delbr br0
[root@desktop Desktop]# brctl show
bridge name bridge id       STP enabled interfaces

这里写图片描述

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

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值