红联Linux门户
Linux帮助

解决linux不能连外网

发布时间:2016-07-02 10:38:13来源:linux网站作者:波子汽水yeah
问题说明:
新分配的服务器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
<html>
<head>
<title>maobo.me</title>
</head>
<body>
<h1> hello world </h1>
</body>
</html>
[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
 
本文永久更新地址:http://www.linuxdiyf.com/linux/21993.html