您的位置:首页 > 运维架构 > Linux

解决linux不能连外网

2016-06-01 16:05 447 查看
问题说明:

新分配的服务器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
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  linux 服务器