解决linux不能连外网

问题说明:
新分配的服务器ping不通百度,已经申请开通外网访问权限。 提示unknown host www.baidu.com

[root@weixinht ~]# ping -c 3 www.baidu.com 
ping: unknown host www.baidu.com

解决方案 /etc/resolv.conf 中添加nameserver

[root@weixinht ~]#  vi /etc/resolv.conf    
# Generated by NetworkManager

# No nameservers found; try putting DNS servers into your
# ifcfg files in /etc/sysconfig/network-scripts like so:
#
# DNS1=xxx.xxx.xxx.xxx
# DNS2=xxx.xxx.xxx.xxx
# DOMAIN=lab.foo.com bar.foo.com
#添加
nameserver 8.8.8.8
nameserver 8.8.4.4

再测试

[root@weixinht ~]# ping -c 3 www.baidu.com 
PING www.a.shifen.com (14.215.177.38) 56(84) bytes of data.
64 bytes from 14.215.177.38: icmp_seq=1 ttl=54 time=4.60 ms
64 bytes from 14.215.177.38: icmp_seq=2 ttl=54 time=4.52 ms
64 bytes from 14.215.177.38: icmp_seq=3 ttl=54 time=4.48 ms

--- www.a.shifen.com ping statistics ---
3 packets transmitted, 3 received, 0% packet loss, time 21031ms
rtt min/avg/max/mdev = 4.486/4.539/4.608/0.075 ms
[root@weixinht ~]# curl maobo.me


  
    maobo.<span class="hljs-keyword">me</span>
  
  
    

hello world

[root@weixinht ~]#

就OK了

参考这篇文章

和网络有关的配置文件
/etc/resolv.conf
查看网关设置
grep GATEWAY /etc/sysconfig/network-scripts/ifcfg*
增加网关:
route add default gw 192.168.40.1
重启网络
service network restart
查看DNS解析
grep hosts /etc/nsswitch.conf

你可能感兴趣的:(服务器)