1. 添加一张网卡
2. 重写一个网卡配置文件
[root@localhost ~]# cd /etc/NetworkManager/system-connections/
[root@localhost system-connections]# ls
ens160.nmconnection
[root@localhost system-connections]# vim ens224.connection
[root@localhost system-connections]# cat ens224.connection
[connection]
id=ens224
type=ethernet
interface-name=ens224
[ipv4]
method=manual
address1=172.25.254.10/24,172.25.254.2
dns=114.114.114.114
[root@localhost system-connections]# chmod 600 ens224.connection
[root@localhost system-connections]# nmcli connection reload
[root@localhost system-connections]# nmcli connection up ens224
Connection successfully activated (D-Bus active path: /org/freedesktop/NetworkManager/ActiveConnection/4)
3. 编写脚本执行网络的设定
[root@localhost system-connections]# vim /usr/local/bin/vmset.sh
[root@localhost bin]# cat vmset.sh
#!/bin/bash
cat > /etc/NetworkManager/system-connections/$1.connection <<EOF
[connection]
id=$1
type=ethernet
interfce-name=$1
[ipv4]
method=manual
address1=$2/24,172.25.254.2
dns=114.114.114.114;
EOF
chmod 600 /etc/NetworkManager/system-connections/$1.connection
nmcli connection reload
nmcli connection up $1
[root@localhost system-connections]# chmod +x /usr/local/bin/vmset.sh
[root@localhost system-connections]# vmset.sh ens224 172.25.254.200
Connection successfully activated (D-Bus active path: /org/freedesktop/NetworkManager/ActiveConnection/5)