配置网卡bonding
- 配置bond0模式,两块网卡使用同一个IP地址,当一个网卡故障时,不影响使用
1 . 先关闭NetworkManager服务
service NetworkManger stop
2 . vim /etc/sysconfig/network-scripts/ifcfg-bond0 编辑bond0配置文件,DEVICE=bond0为配置bond0模式,bond3为选择bond模式3工作模式
3 . 修改网卡配置文件
vim /etc/sysconfig/network-scripts/ifcfg-eth0
vim /etc/sysconfig/network-scripts/ifcfg-eth1
4 . service network restart 重启网卡
5 . ping测试
修改Centos7网卡的命名方式为传统命名方式,eg eth0
方式一
(1)编辑/etc/default/grub 配置文件
GRUB_CMDLINE_LINUX ="rhgb quiet net.ifnames=0"
(2)为grub2 生成其配置文件
grub2-mkconfig -o /etc/grub2.cfg
(3)重启系统
方式二
(1)编辑/boot/grub2/grub.cfg文件
GRUB_CMDLINE_LINUX ="rhgb quiet net.ifnames=0"
(2)重启生效
vim /boot/grub2/grub.cfg
卸载虚拟网卡
rpm -q libvirt*
yum remove libvirt-daemon 移除libvirt-daemon程序包
nmcli实现bonding
1 . 新建bond0配置文件
nmcli connection add type bond con-name bond0 ifname bond0 mode active-backup
type指定bond类型,con-name为配置文件连接名,ifname为指定接口,mode为选定bond工作模式
2 . bond0添加IP地址
nmcli connection modify bond0 ipv4.method manual ipv4.addresses 192.168.198.134/24 ipv4.gateway 192.168.198.1
ipv4.method为指定动态IP或手动设置IP,ipv4.gateway为设置网关
3 . bond0添加物理网卡
nmcli connection add type bond-slave ifname ens34 master bond0
type类型为bond-slave,bond的从属设备,ifname指定接口为ens34,master为指定bond主设备为bond0
nmcli connection add type bond-slave ifname ens33 master bond0
nmcli connection show 显示网卡设备,bond还未关联ens33、ens34网卡设备
4 . 启用bond-slave网卡
nmcli connection up bond-slave-ens33
nmcli connection up bond-slave-ens34
5 . nmcli connection show 查看网卡的关联
6 . cat /proc/net/bonding/bond0 监控bond0的状态
卸载bond0
1 . 将bond0设备down
nmcli connection down bond0
2 . 删除bond0的相关配置文件
nmcli connection delete bond0
nmcli connection delete bond-slave-ens34
nmcli connection delete bond-slave-ens33
nmcli实现team
1 . 创建team0
nmcli connection add type team con-name team0 ifname team0 config '{"runner":{"name":"activebackup"}}'
nmcli connection modify team0 ipv4.method manual ipv4.addresses 192.168.198.135/24
也可合并为
nmcli connection add type team con-name team0 ifname team0 ipv4.method manual ipv4.addressses 192.168.198.135/24 config '{"runner":{"name":"activebackup"}}'
type指定类型为team,con-name指定连接名,ifname为接口名,ipv4.method指定手动配置IP。ipv4.addresses指定IP
2 . 将ens33、ens34网卡关联到team0
nmcli connection add type team-slave ifname ens34 con-name team-slave-ens34 master team0
nmcli connection add type team-slave ifname ens33 con-name team-slave-ens33 master team0
type指定类型为team-slave,ifname指定网卡接口,con-name指定连接名,master指定主设备为team0
3 . 启用team-slave-ens34和ens33网卡
nmcli connection up team-slave-ens33
nmcli connection up team-slave-ens34
nmcli connection up team0 启用team0网络组
4 . teamdctl team0 state 查看team0的状态
卸载team0
1 . down关闭team0
nmcli connection down team0
2 . 删除team0相关文件
nmcli connection delete team0
nmcli connection delete team-slave-ens33
nmcli connection delete team-slave-ens34
配置网桥
1 . 创建br0
nmcli connection add type bridge con-name br0 ifname br0 ipv4.method manual ipv4.addresses 192.168.198.100/24 con-name连接名为br0,type类型为bridge
2 . br0关联网卡
nmcli connection add type bridge-slave ifname ens34 master br0
nmcli connection add type bridge-slave ifname ens33 master br0
3 . 启用bridge-slave-ens33和ens34设备
nmcli connection up bridge-slave-ens34
nmcli connection up bridge-slave-ens33
4 . brctl show 查看bridge的信息
STP为生成树协议,防止交换机的回环
5 . 查看相关配置文件
cat /etc/sysconfig/network-scripts/ifcfg-br0
cat /etc/sysconfig/network-scripts/ifcfg-bridge-slave-ens33
cat /etc/sysconfig/network-scripts/ifcfg-bridge-slave-ens37
卸载bridge网桥
1 . 禁用br0网桥
nmcli connection down br0
2 . 删除bridge配置文件
nmcli connection delete br0
nmcli connection delete bridge-slave-ens33
nmcli connection delete bridge-slave-ens37
nmcli connection reload