centos-Linux静态IP地址配置

一个人想着一个人 提交于 2020-03-02 06:10:18

首先在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

 

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!