一般大家想让虚拟机和真机通信的时候都会选择桥接模式,如果想虚拟机上网的时候会选择nat模式(这里不详细讲解nat模式);bond是将两块网卡绑定到一起,如果一块做成负载均衡的模式,或者作为一块网卡的备用网卡来使用;team可以理解成bond的加强版本,将多块网卡绑定到一起成为一个team。
1.bridge桥接
在真机上:
cd /etc/sysconfig/network-scripts/
vim ifcfg-br0 ##虚拟网卡接口
DEVICE=br0
NAME="enp0s25"
ONBOOT=yes
BOOTPROTO=none
IPADDR0=172.25.254.38
TYPE=Bridge
vim ifcfg-enp0s25 ##物理网卡接口
DEVICE=enp0s25
BOOTPROTO=none
BRIDGE=br0
ONBOOT=yes
TYPE=Ethernet
NAME="System enp0s25"
systemctl stop NetworkManager
systemctl restart network
systemctl start NetworkManager
也可用如下命令进行创建和删除:
brctl show ##查看网卡接口
brctl addbr br0 ##添加br0接口
brctl addif br0 eth0 ##把虚拟接口连接到物理接口
ifconfig br0 172.25.254.38 netmask 255.255.255.0
systemctl restart network
ifconfig br0 down ##关闭br0
brctl delif br0 eth0 ##删除br0与eth0的连接
brctl delbr br0 ##删除br0接口
2.网卡绑定
添加两个网卡eth0 eth1
nmcli connection add type bond con-name bond0 ifname bond0 mode active-backup ip4 172.25.254.138/24 ###添加bond
bond添加网卡:
nmcli connection add con-name eth0 ifname eth0 type bond-slave master bond0
nmcli connection add con-name eth1 ifname eth1 type bond-slave master bond0
ifconfig eth0 down ##关闭eth0
nmcli connection delete eth0 ##删除eth0
watch -n 1 cat /proc/net/bonding/bond0 查看bond接口状态
3.team
可以绑定多个网卡
nmcli connection add type team con-name team0 ifname team0 config '{"runner":{"name":"activebackup"}}' ip4 172.25.254.138/24 ##添加team,模式:主备(广播容错,轮询,负载均衡)
添加网卡
nmcli connection add con-name eth0 ifname eth0 type team-slave master team0
nmcli connection add con-name eth1 ifname eth1 type team-slave master team0
ifconfig eth0 down
teamdctl team0 state ##查看team0的状态
systemctl restart network