首先在VMware菜单中点击编辑-->虚拟网卡编辑器,查看NAT网段(子网掩码、网关、起止IP地址)
1.用nmcli命令配置IP地址
[root@Core ~]# nmcli connection show
NAME UUID TYPE DEVICE
ens33 3a90c11e-a36f-401e-ba9d-e7961cea63ca ethernet ens33
[root@Core ~]# nmcli connection modify ens33 ipv4.method manual ipv4.addresses 192.168.181.20/24 ipv4.gateway 192.168.181.2 ipv4.dns 114.114.114.114 autoconnect yes
验证:
[root@Core ~]# nmcli connection up ens33
[root@Core ~]# ifconfig
ens33: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500
inet 192.168.181.20 netmask 255.255.255.0 broadcast 192.168.181.255
[root@Core ~]# ping -c 3 g.cn
PING g.cn (203.208.50.63) 56(84) bytes of data.
64 bytes from g.cn (203.208.50.63): icmp_seq=1 ttl=128 time=40.8 ms
64 bytes from g.cn (203.208.50.63): icmp_seq=2 ttl=128 time=41.6 ms
64 bytes from g.cn (203.208.50.63): icmp_seq=3 ttl=128 time=41.6 ms
2.修改配置文件的方式修改IP地址
[root@Core ~]# sed -i 's/dhcp/static/' /etc/sysconfig/network-scripts/ifcfg-ens33
[root@Core ~]# sed -i '$a IPADDR="192.168.181.21"' /etc/sysconfig/network-scripts/ifcfg-ens33
[root@Core ~]# sed -i '$a PREFIX="24"' /etc/sysconfig/network-scripts/ifcfg-ens33
[root@Core ~]# sed -i '$a GATEWAY="192.168.181.2"' /etc/sysconfig/network-scripts/ifcfg-ens33
[root@Core ~]# sed -i '$a DNS1="114.114.114.114"' /etc/sysconfig/network-scripts/ifcfg-ens33
[root@Core ~]# systemctl restart network
验证:
[root@Core ~]# ifconfig
ens33: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500
inet 192.168.181.21 netmask 255.255.255.0 broadcast 192.168.181.255
[root@Core ~]# ping -c 3 g.cn
PING g.cn (203.208.50.55) 56(84) bytes of data.
64 bytes from g.cn (203.208.50.55): icmp_seq=1 ttl=128 time=46.9 ms
64 bytes from g.cn (203.208.50.55): icmp_seq=2 ttl=128 time=46.8 ms
64 bytes from g.cn (203.208.50.55): icmp_seq=3 ttl=128 time=66.3 ms
来源:https://www.cnblogs.com/guarding/p/12308564.html