问题描述:修改linux ip 有dchp 动态修改为static ip
环境centos7
ping: www.baidu.com: Name or service not known
第一步:修改红色四处,此处有个坑,就是最近中美华为贸易原因,谷歌DNS失效,老实国内呆着吧,推荐DNS国内
北京联通 202.106.0.20 202.106.196.115 阿里 223.5.5.5 223.6.6.6 114 114.114.114.114 南方电信 180.153.225.136 百度 180.76.76.76 360 101.226.4.5
vi /etc/sysconfig/network-scripts/ifcfg-ens33
[root@hostuser network-scripts]#
TYPE="Ethernet"
PROXY_METHOD="none"
BROWSER_ONLY="no"
BOOTPROTO="static"
DEFROUTE="yes"
IPV4_FAILURE_FATAL="no"
IPV6INIT="yes"
IPV6_AUTOCONF="yes"
IPV6_DEFROUTE="yes"
IPV6_FAILURE_FATAL="no"
IPV6_ADDR_GEN_MODE="stable-privacy"
NAME="ens33"
UUID="bfee91f7-4651-4860-91e4-12f209c214f8"
DEVICE="ens33"
ONBOOT="yes"
IPADDR=192.168.110.151
DNS1=114.114.114.114
GATEWAY=192.168.110.2
[root@hostuser network-scripts]#
本地vm8适配器修改:
windows本地配置如下
重启网络适配器:
service network restart
ping 百度问题解决:
[root@hostuser network-scripts]# ping www.baidu.com
PING www.a.shifen.com (14.215.177.39) 56(84) bytes of data.
64 bytes from 14.215.177.39 (14.215.177.39): icmp_seq=1 ttl=128 time=9.50 ms
64 bytes from 14.215.177.39 (14.215.177.39): icmp_seq=2 ttl=128 time=8.94 ms
64 bytes from 14.215.177.39 (14.215.177.39): icmp_seq=3 ttl=128 time=1557 ms
64 bytes from 14.215.177.39 (14.215.177.39): icmp_seq=4 ttl=128 time=989 ms
64 bytes from 14.215.177.39 (14.215.177.39): icmp_seq=5 ttl=128 time=7.67 ms
问题解决!!DNS的坑整了很久,之前谷歌8.8.8.8 一直是可以用的,真是搞不懂为啥,国际关系还要办 DNS
最后拓展一下一些小知识:
如何设置永久默认网关添加GATEWAY
[root@bogon sysconfig]# vi /etc/sysconf/network
NETWORKING=yes
HOSTNAME=bogon
GATEWAY=192.168.229.2
然后重启网络适配器:service network restart
检查route 路由网关:route
[root@bogon etc]# route ,default 开头是默认网关Gateway
Kernel IP routing table
Destination Gateway Genmask Flags Metric Ref Use Iface
192.168.229.0 * 255.255.255.0 U 1 0 0 eth0
default bogon 0.0.0.0 UG 0 0 0 eth0
ping www.baidu.com 检查如下成功:
[root@bogon etc]# ping www.baidu.com
PING www.a.shifen.com (163.177.151.110) 56(84) bytes of data.
64 bytes from 163.177.151.110: icmp_seq=1 ttl=128 time=11.1 ms
64 bytes from 163.177.151.110: icmp_seq=2 ttl=128 time=10.5 ms
64 bytes from 163.177.151.110: icmp_seq=3 ttl=128 time=11.0 ms
注意如果你centos7 不是6修改完网卡后要重启网卡比如centos7 的ens33网卡:
[root@hostuser network-scripts]# ifdown ens33
成功断开设备 'ens33'。
[root@hostuser network-scripts]#
[root@hostuser network-scripts]# ifup ens33
连接已成功激活(D-Bus 活动路径:/org/freedesktop/NetworkManager/ActiveConnection/5)
验证修改效果
[root@hostuser network-scripts]# route -n
Kernel IP routing table
Destination Gateway Genmask Flags Metric Ref Use Iface
0.0.0.0 192.168.81.2 0.0.0.0 UG 100 0 0 ens33
192.168.81.0 0.0.0.0 255.255.255.0 U 100 0 0 ens33
192.168.122.0 0.0.0.0 255.255.255.0 U 0 0 0 virbr0
[root@hostuser network-scripts]#