LinuxSir.cn,穿越时空的Linuxsir!

 找回密码
 注册
搜索
热搜: shell linux mysql
查看: 1012|回复: 4

[求助] ping localhost ping 到在外网的IP上了

[复制链接]
发表于 2007-6-14 06:08:04 | 显示全部楼层 |阅读模式
机器连接到路由器(192.168.0.1)。
root:~> ping localhost
PING localhost.zhouslab.com (221.174.16.35) 56(84) bytes of data.
64 bytes from 221.174.16.35: icmp_seq=1 ttl=56 time=46.5 ms
64 bytes from 221.174.16.35: icmp_seq=2 ttl=56 time=209 ms
64 bytes from 221.174.16.35: icmp_seq=3 ttl=56 time=46.5 ms
64 bytes from 221.174.16.35: icmp_seq=4 ttl=56 time=46.9 ms

如果将 /etc/resolv.conf 中 nameserver 192.168.0.1 注释掉
root:~> ping localhost
PING localhost.zhouslab.com (127.0.0.1) 56(84) bytes of data.
64 bytes from 127.0.0.1: icmp_seq=1 ttl=64 time=0.018 ms
64 bytes from 127.0.0.1: icmp_seq=2 ttl=64 time=0.025 ms

可是将 nmaserver 注释掉 就不能上网了,怎么办才能上网,同时 ping localhost ping 的是 127.0.0.1 呢?

root:~> ifconfig
eth0      Link encap:Ethernet  HWaddr 00:0F:B0:F6:03:4F  
          inet addr:192.168.0.31  Bcast:192.168.0.255  Mask:255.255.255.0
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
          RX packets:1412 errors:0 dropped:0 overruns:0 frame:0
          TX packets:1468 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1000
          RX bytes:1243509 (1.1 MiB)  TX bytes:234670 (229.1 KiB)
          Interrupt:11

lo        Link encapocal Loopback  
          inet addr:127.0.0.1  Mask:255.0.0.0
          UP LOOPBACK RUNNING  MTU:16436  Metric:1
          RX packets:103 errors:0 dropped:0 overruns:0 frame:0
          TX packets:103 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:0
          RX bytes:8500 (8.3 KiB)  TX bytes:8500 (8.3 KiB)

root:~> route -n
Kernel IP routing table
Destination     Gateway         Genmask         Flags Metric Ref    Use Iface
192.168.0.0     0.0.0.0         255.255.255.0   U     0      0        0 eth0
127.0.0.0       0.0.0.0         255.0.0.0       U     0      0        0 lo
0.0.0.0         192.168.0.1     0.0.0.0         UG    1      0        0 eth0

root:~> cat /etc/resolv.conf
domain zhouslab.com
search zhouslab.com
nameserver 192.168.0.1

root:~> cat /etc/hosts
#
# hosts                This file describes a number of hostname-to-address
#                mappings for the TCP/IP subsystem.  It is mostly
#                used at boot time, when no name servers are running.
#                On small systems, this file can be used instead of a
#                "named" name server.  Just add the names, addresses
#                and any aliases to this file...
#
# By the way, Arnt Gulbrandsen <agulbra@nvg.unit.no> says that 127.0.0.1
# should NEVER be named with the name of the machine.  It causes problems
# for some (stupid) programs, irc and reputedly talk. :^)
#

# For loopbacking.
127.0.0.1                localhost
192.168.0.31                sxzzsf.zhouslab.com sxzzsf

# End of hosts.

BTW: 我用的是slackware linux 2.6.21.5
发表于 2007-6-14 09:04:58 | 显示全部楼层
/etc/nsswitch.conf里的hosts段是什么?

若想hosts文件优先应该是下面的:
hosts:      files dns
回复 支持 反对

使用道具 举报

发表于 2007-6-14 09:09:06 | 显示全部楼层
把 /etc/hosts 里的 127.0.0.1 localhost 改成 127.0.0.1 localhost localhost.zhouslab.com 应该就可以了
回复 支持 反对

使用道具 举报

 楼主| 发表于 2007-6-14 09:19:22 | 显示全部楼层
Post by lanyao
/etc/nsswitch.conf里的hosts段是什么?

若想hosts文件优先应该是下面的:
hosts:      files dns

Post by tigatron
把 /etc/hosts 里的 127.0.0.1 localhost 改成 127.0.0.1 localhost localhost.zhouslab.com 应该就可以了


现在在公司

晚上回去试试
回复 支持 反对

使用道具 举报

 楼主| 发表于 2007-6-14 18:29:37 | 显示全部楼层
谢谢了 是文件 nsswitch.conf 的损坏了
回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 注册

本版积分规则

快速回复 返回顶部 返回列表