linux 设置静态ip 及解决相关问题
2012-12-22 13:15
288 查看
vi /etc/sysconfig/network-scripts/ifcfg-eth0 #编辑配置文件
一般配上这个,内网ping可能没有什么问题。但是ping www.baidu.com可能就有问题了
解决linux ping: unknown host www.baidu.com
"ping: unknown host www.baidu.com"
解决方案:
如果某台Linux服务器ping不通域名, 如下提示:
[root@localhost ~]# ping www.baidu.com
ping: unknown host www.baidu.com
首先确定已经连接上路由器,并且路由器能够访问外网,可以通过访问网关进行确定
[root@localhost ~]# ping 192.168.1.1
PING 192.168.1.1 (192.168.1.1) 56(84) bytes of data.
64 bytes from 192.168.1.1: icmp_seq=1 ttl=64 time=2.96 ms
64 bytes from 192.168.1.1: icmp_seq=2 ttl=64 time=1.75 ms
如果确定网络没问题的情况下, 可以通过如下步骤寻找解决办法:
1) 确定设置了域名服务器, 没有的话, 建议设置Google的公共DNS服务, 它应该不会出问题的
[root@localhost ~]# cat /etc/resolv.conf
search localdomain
因为我的DNS没有设置所以导致了ping外网ping不通。将dns添加到该文件中
[root@localhost ~]# vi /etc/resolv.conf
search localdomain
nameserver 202.98.96.68
nameserver 61.139.2.69
~
2) 确保网关已设置
# grep GATEWAY /etc/sysconfig/network-scripts/ifcfg*
-------------------------------------------------------------------
/etc/sysconfig/network-scripts/ifcfg-eth0:GATEWAY=192.168.40.1
-------------------------------------------------------------------
如果未设置, 则通过如下方式增加网关:
# route add default gw 192.168.40.1
或者手工编写/etc/sysconfig/network-scripts/ifcfg*文件后, 重启network服务:
# service network restart
3) 确保可用dns解析
# grep hosts /etc/nsswitch.conf
-------------------------------------------------------------------
hosts: files dns
-------------------------------------------------------------------
如果以上哪个有问题, 修正后, 再测试, 应该就没问题了:
#ping -c 3 www.baidu.com
PING www.a.shifen.com (220.181.6.175) 56(84) bytes of data.
64 bytes from 220.181.6.175: icmp_seq=0 ttl=50 time=9.51 ms
64 bytes from 220.181.6.175: icmp_seq=1 ttl=50 time=8.45 ms
64 bytes from 220.181.6.175: icmp_seq=2 ttl=50 time=8.97 ms
--- www.a.shifen.com ping statistics ---
3 packets transmitted, 3 received, 0% packet loss, time 2002ms
rtt min/avg/max/mdev = 8.450/8.977/9.511/0.446 ms, pipe 2
DEVICE=eth0 BOOTPROTO=static ONBOOT=yes HWADDR=00:0C:29:31:B3:D3 IPADDR=192.168.1.206 GATEWAY=192.168.1.1 NETMASK=255.255.255.0 TYPE=Ethernet
一般配上这个,内网ping可能没有什么问题。但是ping www.baidu.com可能就有问题了
解决linux ping: unknown host www.baidu.com
"ping: unknown host www.baidu.com"
解决方案:
如果某台Linux服务器ping不通域名, 如下提示:
[root@localhost ~]# ping www.baidu.com
ping: unknown host www.baidu.com
首先确定已经连接上路由器,并且路由器能够访问外网,可以通过访问网关进行确定
[root@localhost ~]# ping 192.168.1.1
PING 192.168.1.1 (192.168.1.1) 56(84) bytes of data.
64 bytes from 192.168.1.1: icmp_seq=1 ttl=64 time=2.96 ms
64 bytes from 192.168.1.1: icmp_seq=2 ttl=64 time=1.75 ms
如果确定网络没问题的情况下, 可以通过如下步骤寻找解决办法:
1) 确定设置了域名服务器, 没有的话, 建议设置Google的公共DNS服务, 它应该不会出问题的
[root@localhost ~]# cat /etc/resolv.conf
search localdomain
因为我的DNS没有设置所以导致了ping外网ping不通。将dns添加到该文件中
[root@localhost ~]# vi /etc/resolv.conf
search localdomain
nameserver 202.98.96.68
nameserver 61.139.2.69
~
2) 确保网关已设置
# grep GATEWAY /etc/sysconfig/network-scripts/ifcfg*
-------------------------------------------------------------------
/etc/sysconfig/network-scripts/ifcfg-eth0:GATEWAY=192.168.40.1
-------------------------------------------------------------------
如果未设置, 则通过如下方式增加网关:
# route add default gw 192.168.40.1
或者手工编写/etc/sysconfig/network-scripts/ifcfg*文件后, 重启network服务:
# service network restart
3) 确保可用dns解析
# grep hosts /etc/nsswitch.conf
-------------------------------------------------------------------
hosts: files dns
-------------------------------------------------------------------
如果以上哪个有问题, 修正后, 再测试, 应该就没问题了:
#ping -c 3 www.baidu.com
PING www.a.shifen.com (220.181.6.175) 56(84) bytes of data.
64 bytes from 220.181.6.175: icmp_seq=0 ttl=50 time=9.51 ms
64 bytes from 220.181.6.175: icmp_seq=1 ttl=50 time=8.45 ms
64 bytes from 220.181.6.175: icmp_seq=2 ttl=50 time=8.97 ms
--- www.a.shifen.com ping statistics ---
3 packets transmitted, 3 received, 0% packet loss, time 2002ms
rtt min/avg/max/mdev = 8.450/8.977/9.511/0.446 ms, pipe 2
相关文章推荐
- linux下,matplotlib遇到的相关问题以及解决方法
- linux 设置固定ip 并且解决ping www.baidu.com不通问题
- linux下oracle的安装与卸载及相关问题解决方案
- Linux下Apache服务器网页密码设置过程问题及解决方法
- 安装Ubuntu版本linux过程中没有提示设置root用户密码问题的解决办法
- 远程操作linux网络设置(五)-ssh登录慢有延迟问题的解决
- Linux相关问题-解决Ubuntu12.04下无法使用中文输入法
- Linux相关问题-Ubuntu 12.04下解决Tomcat自启动问题
- 安装Ubuntu版本linux过程中没有提示设置root用户密码问题的解决办法
- Linux相关问题-CentOS6.5 x64版本号下Tomcat无法自启动的解决的方法
- Ubuntu设置静态IP,解决重启后需要重新设置的问题。
- weblogic 域乱码问题解决------linux 设置中文字符集
- linux下oracle的安装与卸载及相关问题解决方案
- linux Apache设置https访问以及加载mod_ssl.so模块以及问题解决
- Linux-2.6.32 下 块设备驱动的编写 与 相关问题解决
- ssh免密码登录【遇到的问题: linux下设置了SSH免密码登录但还是需要输入密码的解决办法 】
- Linux下Chrome字体设置和启用OpenGL、GPU显卡加速解决Flash CPU占用过高的问题
- Linux下升级相关组件的问题解决
- 转:linux下svn服务器搭建以及相关问题解决方案
- 解决Linux安装Python相关包的_sqlite3.so及sqlite3相关问题