(一)将虚拟机的网卡命名规则永久修改为ethx(基于openeuler系统)
①vim /etc/default/grub打开该文件
②在GRUB_CMDLINE_LINUX这一行的末尾添加net.ifnames=0 biosdevname=0
③执行命令grub2-mkconfig -o /boot/grub2/grub.cfg
④reboot重启系统
(二)列出当前系统的ipv4地址、mac地址、dns地址和路由
ifconfig #查看ip地址和mac地址
ip addr show #同样也可以查看ip地址及mac地址
cat /etc/resolv.conf #查看dns地址
ip route #查看路由
(三)根据自己的虚拟机网络模式,将虚拟机的eth0网卡的ip地址修改为xxx.xxx.xxx.100/24,DNS为xxx.xxx.xxx.2,网关地址为xxx.xxx.xxx.2,实现网络开机自启动,对应的connection的名字为config-etho
nmcli connection add type ethernet ifname eth0 con-name config-eth0 ipv4.method manual ipv4.addresses 192.168.16.100/24 ipv4.dns 192.168.16.2 ipv4.gateway 192.168.16.2 autoconnect yes
#nmcli connection 对链接进行配置
#add 添加
#type ethernet 类型
#ifname eth0 网卡设备名
#con-name config-eth0 连接的名字
#ipv4.method manual 获取ipv4地址的方式 manual表示管理员手动分配
#ipv4.addresses ipv4地址
#ipv4.dns dns地址
#ipv4.gateway 网关地址
#autoconnect yes 是否开机自启 默认情况不写也是开机自启
(四)额外给虚拟机添加一张同网络模式的网卡,为eth0和eth1配置网络bond,bond级别为主备,eth0为主网卡,eth1为备网卡,虚拟网卡名称为bond1,对应的connection名称为config-bond1,虚拟网卡bond1的ip地址为xxx.xxx.xxx.200/24,查看bond的网络状态并断开其中
一张网卡进行测试
①清空所有的物理网卡对应的connection连接
nmcli connection delete config-eth0
②创建一个虚拟网卡bond1
nmcli connection add type bond ifname bond1 con-name bond1 mode active-backup
③将两张物理网卡加入到bond1虚拟网卡中
nmcli connection add type bond-slave ifname eth0 con-name bond1-eth0 master bond1
nmcli connection add type bond-slave ifname eth1 con-name bond1-eth1 master bond1
④配置bond1虚拟网卡的网络地址
nmcli connection modify bond1 ipv4.method manual ipv4.addresses 192.168.16.200/24 ipv4.dns 192.168.16.2 ipv4.gateway 192.168.16.2 autoconnect yes
nmcli connection up bond1
⑤查看bond的状态
cat /proc/net/bonding/bond1