一、bond网络接口
1.什么是bond
Red Hat Enterprise Linux 允许管理员使用,bonding内核模块和称为通道绑定接口的特殊网络接口将多个网络接口绑定到一个通道上。根据选择的绑定模式,通道绑定使两个或更多个网络接口作为一个网络接口,从而增加带宽和,提供冗余性。
2.选择linux以太网绑定模式
目前网卡绑定mode共有七种(0~6):bond0、bond、bond1、bond2、bond3、bond4、bond5、bond6
模式0(平衡轮循):轮循策略。所有接口都采用轮循方式在所有 Slave 中传输封包;任何 Slave 都可以接收。
模式1(主动备份):容错。一次只能使用一个 Slave 接口,但是如果该接口出现故障,另一个 Slave 将接替它。
模式3(广播):容错。所有封包都通过所有 Slave 接口广播。
3.配置bond网络接口
1.添加双网卡
在真机上:
[root@foundation60 ~]# virt-manager #配置虚拟机
双击desktop(注意:desktop是关闭状态)
点击灯泡图案
点击左边的NIC:00:3c:0a--->点击左下角 add hardware
点击左边的network--->选择bridge br0--->选择virto--->finish
2.配置bond接口
(1)用命令配置bond接口
在desktop虚拟机:
终端1:
ifconfig #查看网络配置
如果显示ip,网关已配置应当删除
nmcli connection delete eth0 #清空网卡
nmcli connection add con-name bond0 ifname bond0 type bond mode active-backup ip4 172.25.254.102/24
#配置bond网络接口,ip为172.25.254.102
开启终端2:监控:watch -n 1 cat /proc/net/bonding/bond0 #查看网络接口bond0的信息
currently active slave:none ##没有可用网络接口,此时ping不通
开启终端3:ping 真机id
nmcli connection add con-name eth0 ifname eth0 type bond-slave master bond0 #添加网络接口eth0
成功添加网络接口后网可以ping通
nmcli connection add con-name eth1 ifname eth1 type bond-slave master bond0 #添加第二个网络接口eth1
eth0,eth1均为开启状态。eth0为工作接口,eth1为备用接口。当eth0不工作时,eth1会立即代替eth0工作
ifconfig eth0 down #使eth0停止工作
关闭eth0后eth1立即工作,网络不受到影响
ifconfig eth0 up #开启eth0网络接口
eth0处于备用状态
添加bond网络接口成功!
(2)建立配置文件配置bond网络接口
cd /etc/sysconfig/network-scripts/
vim ifcfg-bond0 #编辑bond网络接口文件
vim ifcfg-eth0 #编辑eth0网络接口文件(eth1同)
3.删除bond网络接口
nmcli connection delete bond0 #删除绑定接口bond0
nmcli connection delete eth0 #删除网络接口eth0
nmcli connection delete eth1 #删除网络接口eth1
删除dond网络接口成功!
二、team网络接口
1.什么是team
- Team 和 bond0 功能类似
- Team 不需要手动加载相应内核模块
- Team 有更强的扩展性
- 支持8块网卡
- Team 的种类:
broadcast 广播容错
roundrobin 平衡轮叫:(不管任务量大小难度,一人一个任务,比较机械)
activebackup 主动备份
loadbalance 负载均衡:(将任务平衡分配,每个人任务量相同)
2.配置team网络接口
终端1:
nmcli connection add con-name team0 ifname team0 type team config '{"runner":{:name":"activebackup"}}' ip4 172.25.254.102/24
#添加team网络接口
开启终端二:监控:watch -n 1 teamdctl team0 stat
active port: #没有可用网络接口,所以网ping不通
nmcli connnection add con-name eth0 ifname eth0 type team-slave master team0 #添加网络接口eth0
成功添加网络接口后可以ping通
nmcli connnection add con-name eth1 ifname eth1 type team-slave master team0 #添加网络接口eth1

eth0,eth1均为开启状态。eth0为工作接口,eth1为备用接口。当eth0不工作时,eth1会立即代替eth0工作
ifconfig eth0 down #使eth0停止工作
关闭eth0后eth1立即工作,网络不受到影响
ifconfig eth0 up #开启eth0网络接口

eth0处于备用状态
nmcli connection show #查看网络连接
建立team网络接口成功!
3.删除team网络接口
nmcli conneation delete team0 #删除team网络接口team0
nmcli conneation delete eth0 #删除网络接口eth0
nmcli conneation delete eth1 #删除网络接口eth1
删除team网络接口成功!
三、网络桥接
1.什么是网络桥接
网络桥接用网络桥实现共享上网
主机和客户机除了利用软件外,还可以用系统自带的网络桥接建立连接用双网卡的机器做主机
2.测试有无桥接的区别:
在真机上
[root@foundation60 ~]# cd /etc/sysconfig/network-scripts/
[root@foundation60 network-scripts]# mv ifcfg-br0 ifcfg-enp0s25 /opt/ #备份
[root@foundation60 network-scripts]# nm-connection-editor #修改网络配置
删除只剩下virbr0--->add
点击create..
将connection name改为enp0s25--->device选择enp0s25--->点击ipv4 setings
method:manual--->点击右边add--->address:172.25.254.60--->netmask:24--->gateway:点击一下就行--->save
建立网桥
[root@foundation60 ~]# cd /etc/sysconfig/network-scripts/
[root@foundation60 network-scripts]# ls
[root@foundation60 network-scripts]# vim ifcfg-enp0s25
DEVICE=enp0s25
ONBOOT=yes
BOOTPROTO=none
BRIDGE=br0
[root@foundation60 network-scripts]# vim ifcfg-br0
DEVICE=br0
ONBOOT=yes
BOOTPROTO=none
IPADDR=172.25.254.60
NETMASK=255.255.255.0
TYPE=Bridge
ifcfg-enp0s25, ifcfg-br0 均为测试配置文件
[root@foundation60 network-scripts]# systemctl stop NetworkManager.service #关闭网络服务
[root@foundation60 network-scripts]# systemctl restart network #重启网络
[root@foundation60 network-scripts]# brctl show
[root@foundation60 ~]# virt-manager #管理虚拟机
点击带灯泡的电视图标
下面的network selection分别两次选择virtual network 'default' :NAT和host device enp0s25:macvtap,前者为无桥接,后者为有桥接。
开启非图形界面,给两者同时上传一个大文件,会发现后者等待时间较少。
测试完后:
[root@foundation60 network-scripts]# rm -fr ifcfg-br0 ifcfg-enp0s25 #删除测试配置文件
[root@foundation60 network-scripts]# mv /opt/ifcfg-* . #恢复网络配置
[root@foundation60 network-scripts]# systemctl restart network #重启网络
3.配置网络桥接(虚拟机)
brctl addbr br0 #添加网桥连接
brctl show #显示网桥连接
ifconfig br0 172.25.254.102/24 #添加网桥信息
ping 172.25.254.60 #ping真机
ping不同,因为没有添加网卡
brctl addif br0 eth0 #添加网卡的物理接口
ping通,添加网络桥接成功!
4.删除网桥
brctl delif br0 eth0 #断开网络桥接
ifconfig br0 down #关闭网络桥接
brctl delbr br0 #删除网络桥接
删除网桥成功!