問題描述:修改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]#