linux中的高级网络设置

linux中的bridge,bonding,team

bridge:使真机和虚拟机的网卡以直接交换数据,速度快
NAT:虚拟机把数据先转发给真机,真机再通过网卡传输,速度较慢

        通常网络中的数据包从源地址发出直到包要发送的目的地址,整个路径会经过很多不同的连接,一般情况下这些连接不会更改数据包的内容,只是原样转发。如果发出数据包的主机使用的原地址是私用网络地址,该数据包将不能在互联网上传输。要能够使用私有网络访问互联网,就必须要做NAT(网络地址转换)

在真机中的/etc/syscofig/network-scripts/目录下查看文件(注意:ifcfg-br0,ifcfg-enp0s25是网卡文件设置,为了防止以后网络启动不料,先把这两个文件mv到别的地方)

cd /etc/sysconfig/network
mkdir /backup
mv ifcfg-br0 ifcfg-enp0s25 /backup
 

linux中的高级网络设置

nm-connection-edit   删掉已有的以太网及桥接网,发现在新建虚拟机时没有桥接网络

linux中的高级网络设置

vim /etc/sysconfig/network-scripts/ifcfg-br0(网桥文件 type=Bridge)
DEVICE=br0
ONBOOT=yes
BOOTPROTO=none
IPADDR=172.25.254.45
NETMASK=255.255.255.0
TYPE=Bridge

linux中的高级网络设置
vim /etc/sysconfig/network-scripts/ifcfg-enp0s25
DEVICE=enp0s25
ONBOOT=yes
BOOTPROTO=none
BRIDGE=br0     ##将网桥br0文件联系起来

linux中的高级网络设置

 ping172.25.254.245(虚拟机)  ##通了说明网桥搭建没问题
 brctl show                  ##查看网桥

linux中的高级网络设置

在虚拟机中设定
nm-connection-editor    ##清除所有网络设置
ifconfig                ##查看网络设置

linux中的高级网络设置
brctl addbr br0          ##添加网桥br0
ifconfig br0 172.25.254.145/24    ##添加ip地址到网桥上

brctl show ##此时网桥搭建成功但是并没有添加网卡,所以此时网络ping不通
brctl addif br0 eth0 ##添加eth0网卡到br0网桥上,此时可以ping通
brctl show ##查看此时的网桥信息可以发现interfaces对应网卡eth0

linux中的高级网络设置

linux中的高级网络设置

删除eth0网络接口和网桥br0
brctl delif br0 eth0

ifconfig br0 down            ##如果br0还在工作是不能被删除的
brctl delbr br0
brctl show

linux中的高级网络设置

BOND ---链路聚合,最多支持两快网卡,将两块网卡绑定到一个通道,根据不同模式增加宽带或冗余性

先准备好两块网卡(virt-manager -->灯泡-->addstore--->network--->virtio)

linux中的高级网络设置

systemctl status NetworkManager        ##查看NetworkManager服务是否开启

linux中的高级网络设置
   nmcli connection show                  ##查看
   nmcli connection delete "System eth0"
   nmcii connection show

linux中的高级网络设置

nmcli connection add con-name bond0 ifname bond0 type bond active-backup ip4 172.25.254.145/24
  ##添加bond雷ing的bond0并且设定好ip地址。这时候所有网卡信息都存放在/proc/net/bonding/bond0下
watch -n 1 cat /proc/net/bonding/bond0 ##bond0下的网卡工作情况
nmcli connection add con-name eth0 ifname eth0 type-slave master bond0        ##添加eth0网卡到bond0上
nmcli connection add con-name eth1 ifname eth1 type-slave master bond0        ##添加eth1网卡到bond0上

linux中的高级网络设置

ifconfig eth0 down ##模拟eth0这块网卡坏掉
ifconfig eth0 up
ifconfig eth1 down
ifconfig eth0 down

linux中的高级网络设置

linux中的高级网络设置

删除bond0 eth0 eth1

nmcli connection delete bond0

nmcli connection delete eth0

nmcli connection delete eth1

linux中的高级网络设置

TEAM  ##将多块网卡绑定到一起成为一个team,最多可支持8快网卡

 ifconfig
   nmcli connection add con-name team0 ifname team0 type team config '{"runner":{"name":"activebackup"}}' 172.25.254.145/24      ##添加一个team0
   nmcli connection add con-name eth0 ifname eth0 type team-slave master team0     ##添加eth0网卡到team0
   nmcli connection add con-name eth1 ifname eth1 type team-slave master team0     ##添加eth1到team0

linux中的高级网络设置
   ifconfig eth0 down  ##破坏eth0网卡,eth1会接替工作,ping不会中断
   ping 172.25.254.145
   ifconfig eth0 up
   ifconfig eth1 down
   ifconfig eth0 down ##两个网卡都破坏时,ping中断
    
   teamdctl team0 stst      ##查看(可以watch -n 1 实时监控)

linux中的高级网络设置