实际应用当中,单个网卡可能出现问题。但是像双十一这种,硬件资源是不可以挂掉的,否则会造成重大损失。单个网卡的数据流量是一定的,如何使得多块网卡相互配合,其中一块网卡挂掉,其他网卡可以顶替它的工作,而不至于影响整体的网络状况。这就需要用到高级网络控制!
链路聚合接口-bond
实验1:一块网卡挂掉,备用网卡开始工作。两块网卡交替使用
1.添加两块网卡
2.把之前的网卡信息删除
3.设置链路聚合接口信息
nmcli connection add con-name bond0 ifname bond0 type bond mode active-backup ip4 172.25.254.117/24
4.把eth0物理设备添加到链路聚合接口上
nmcli connection add con-name eth0 ifname eth0 type bond-slave master bond0
监控窗口可以看到正在使用的是网卡eth0
5.把eth1物理设备添加到链路聚合接口上
nmcli connection add con-name eth1 ifname eth1 type bond-slave master bond0
查看监控发现正在使用的网卡是eth0
6.ifconfig eth0 down ##eth0网卡挂掉
监控窗口可以看到正在使用的是网卡变成了eth1,因为eth0网卡挂掉
7.ifconfig eth0 up ##eth0网卡恢复正常
监控窗口可以看到正在使用的是网卡还是eth1
8.ifconfig eth1 down ##eth1网卡挂掉
监控窗口可以看到正在使用的网卡变成了eth0
以上用到的监控命令 :
watch -n 1 cat /proc/net/bonding/bond0
如何删除:
nmcli connection delete bond0 ##删除bond0
nmcli connection delete eth0 ##删除网卡eth0
nmcli connection delete eth1 ##删除网卡eth1
nmcli connection show ##查看网卡
2.链路聚合接口-bond-文件方式
实验2
1.
cd /etc/sysconfig/network-scripts
2.设置链路聚合接口
vim ifcfg-bond0 ##设置链路聚合接口
DEVICE=bond0
ONBOOT=yes
BOOTPROTO=none
IPADDR=172.25.254.117
NETMASK=255.255.255.0
TYPE=Bond
BONDING_OPTS=mode=active-backup
systemctl restart network ##重启网络服务
3.把eth0加到链路聚合接口
vim ifcfg-eth0
DEVICE=eth0
ONBOOT=yes
BOOTPROTO=none
MASTER=bond0
systemctl restart network
4.把eth1加到链路聚合接口
vim ifcfg-eth1
DEVICE=eth1
ONBOOT=yes
BOOTPROTO=none
MASTER=bond0
systemctl restart network
5.查看设置信息
cat ifcfg-bond0 ##查看bond0网络设置
cat ifcfg-eth0 ##查看网卡eth0网卡信息
cat ifcfg-eth1 ##查看网卡eth1网卡信息
3.链路聚合接口-高级方式 Team
实验3
1.图形化界面把之前做实验的bood0,eth0,eth1删除
2.设置team链路聚合接口
nmcli connection add con-name team0 ifname team0 type team config '{"runner":{name:"activebackup"}}' ip4 172.25.254.117/24
命令窗口查看
3.把eth0,eth1物理设备添加到链路聚合接口上
nmcli connection add con-name eth1 ifname eth1 type team-slave master team0
nmcli connection add con-name eth0 ifname eth0 type team-slave master team0
4.重启网络
systemctl restart network
5.显示网卡信息
nmcli connection show
监控窗口发现正使用的是eth0
6.
ifconfig eth0 down
eth0挂掉,监控发现使用eth1
7.ifconfig eth0 up
eth0开启,监控发现依然使用eth1
8.ifconfig eth1 down
eth1挂掉,监控发现现在使用eth0
9.ifconfig eth1 up
eth1开启,监控发现依然使用eth0
以上实验用到监控命令:
watch -n 1 teamdctl team0 stat
4.链路聚合接口-高级方式 Team-文本方式
实验4:
1
cd /etc/sysconfig/network-scripts
2.设置链路聚合接口
vim ifcfg-team0
DEVICE=team0
TEAM_CONFIG="{\"runner\":{\"name\":\"activebackup\"}}"
DEVICETYPE=Team
BOOTPROTO=none
IPADDR0=172.25.254.117
PREFIX0=24
NAME=team0
ONBOOT=yes
systemctl restart network
3.把eth0加到链路聚合接口
vim ifcfg-eth0
BOOTPROTO=none
DEVICE=eth0
ONBOOT=yes
TEAM_MASTER=team0
DEVICETYPE=TeamPort
systemctl restart network
4.把eth1加到链路聚合接口
vim ifcfg-eth1
BOOTPROTO=none
DEVICE=eth1
ONBOOT=yes
TEAM_MASTER=team0
DEVICETYPE=TeamPort
systemctl restart network
5.显示网卡信息
nmcli connection show
6.ifconfig eth0 down
eth0挂掉,监控发现使用eth1
7.ifconfig eth0 up
eth0开启,监控发现依然使用eth1
8.ifconfig eth1 down
eth1挂掉,监控发现现在使用eth0
9.ifconfig eth1 up
eth1开启,监控发现依然使用eth0
监控命令:watch -n 1 teamdctl team0 stat
删除:
nmcli connection delete team0 ##删除链路聚合接口team0
nmcli connection delete eth0 ##删除网卡eth0
nmcli connection delete eth1 ##删除网卡eth1
nmcli connection show ##显示网卡信息
5.桥接
桥接作用:连接两个不同直接通信的接口
实验5:
1.真机里切换到root用户
把所有网卡删除
nm-connection-editor ##图形化界面设置网络
cd /etc/sysconfig/network-scripts/
vim /etc/sysconfig/network-scripts/ifcfg-enp7s0
桥接安装虚拟机要比没有桥接快
安装完成后没有桥接时网卡
kvm虚拟化功能
内核控制网卡
虚拟机信息要发出去经过过程
虚拟主机内核>虚拟主机接口>真实主机内核>真实主机接口再出去
1.设置物理网卡enp0s25
vim ifcfg-enp0s25
DEVICE=enp0s25
ONBOOT=yes
BOOTPROTO=none
BRIDGE=br0
2.设置br0
vim ifcfg-br0
DEVICE=br0
ONBOOT=yes
BOOTPROTO=none
IPADDR=172.25.254.17
NETMASK=255.255.255.0
TYPE=Bridge
systemctl restart network
brctl show
桥接之后安装虚拟机变快
Send Key F2
ifconfig
桥接之后会分配新建的虚拟机的一个和真机IP同网段的IP
查看新安装的虚拟机网卡
实验6:
虚拟机desktop中
brctl addbr br0 ##增加桥接网卡br0
ifconfig ##可以看到新增的br0
ifconfig br0 172.25.254.117/24 ##临时设置br0的IP
ifconfig ##可以看到设置成功
ping 172.25.254.17 ##ping不通
brctl show ##显示
brctl addif br0 eth0 ##把桥接网卡插到物理网卡上
brctl show
ping 172,25,254,17 ##可以ping通了
删除:
ifconfig br0 down
ifconfig
brctl show
brctl delif br0 eth0 ##把桥接网卡从物理网卡上拔下来
brctl show
brctl delbr br0
brctl show