zl程序教程

您现在的位置是:首页 >  系统

当前栏目

centos环境更换IP地址为静态并且正常联网

centos静态 环境 IP地址 联网 正常 更换 并且
2023-06-13 09:13:12 时间

更换IP

版本信息

[root@localhost ~]# cat /etc/redhat-release 
CentOS Linux release 7.6.1810 (Core)

查看ip

[root@localhost ~]# ip a
2: ens33: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP group default qlen 1000
    link/ether 00:0c:29:5b:e7:2e brd ff:ff:ff:ff:ff:ff
    inet 192.168.1.132/24 brd 192.168.1.255 scope global noprefixroute dynamic ens33
       valid_lft 1597sec preferred_lft 1597sec
    inet6 fe80::ba16:18eb:ff2a:62f0/64 scope link noprefixroute 
       valid_lft forever preferred_lft forever

修改IP为静态并指定IP

[root@localhost ~]# vim /etc/sysconfig/network-scripts/ifcfg-ens33 

原文件:

修改后:

重启网络

[root@localhost ~]# systemctl restart network

验证:

[root@localhost ~]# ip a
2: ens33: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP group default qlen 1000
    link/ether 00:0c:29:5b:e7:2e brd ff:ff:ff:ff:ff:ff
    inet 192.168.1.60/24 brd 192.168.1.255 scope global noprefixroute ens33
       valid_lft forever preferred_lft forever
    inet6 fe80::ba16:18eb:ff2a:62f0/64 scope link noprefixroute 
       valid_lft forever preferred_lft forever

联网问题

我这个是自己创建的VMware虚拟机 已经通过网络连接连接到主机网络

但是依旧不能ping外网

[root@localhost ~]# ping www.baidu.com
ping: www.baidu.com: Name or service not known

修改/etc/resolv.conf文件 添加:

nameserver 114.114.114.114
nameserver 8.8.8.8

重启网卡

[root@localhost ~]# systemctl restart network

验证

[root@localhost ~]# ping www.baidu.com
PING www.a.shifen.com (110.242.68.4) 56(84) bytes of data.
64 bytes from 110.242.68.4 (110.242.68.4): icmp_seq=1 ttl=128 time=9.95 ms
64 bytes from 110.242.68.4 (110.242.68.4): icmp_seq=2 ttl=128 time=11.0 ms
64 bytes from 110.242.68.4 (110.242.68.4): icmp_seq=3 ttl=128 time=9.81 ms
64 bytes from 110.242.68.4 (110.242.68.4): icmp_seq=4 ttl=128 time=10.0 ms
64 bytes from 110.242.68.4 (110.242.68.4): icmp_seq=5 ttl=128 time=10.8 ms
64 bytes from 110.242.68.4 (110.242.68.4): icmp_seq=6 ttl=128 time=12.1 ms
64 bytes from 110.242.68.4 (110.242.68.4): icmp_seq=7 ttl=128 time=10.7 ms
64 bytes from 110.242.68.4 (110.242.68.4): icmp_seq=8 ttl=128 time=10.6 ms
^C