分页: 1 / 1

【solved】route命令显示default gateway是localhost

发表于 : 2013-05-07 20:08
dylan_hit
route命令显示default gateway是localhost
route -n显示gateway ip 是 192.168.1.1
我查了一下man route, -n选项表示不解析ip地址到hostname
我查看了/etc/hosts文件,localhost对应的ip是127.0.0.1

我的问题是:route命令显示的localhost到192.168.1.1的对应关系是怎么回事?

下面是命令的执行情况:
dylan@ubuntu:/home/dylan# route
Kernel IP routing table
Destination Gateway Genmask Flags Metric Ref Use Iface
default localhost 0.0.0.0 UG 0 0 0 eth0
192.168.1.0 * 255.255.255.0 U 0 0 0 eth0
dylan@ubuntu:/home/dylan# route -n
Kernel IP routing table
Destination Gateway Genmask Flags Metric Ref Use Iface
0.0.0.0 192.168.1.1 0.0.0.0 UG 0 0 0 eth0
192.168.1.0 0.0.0.0 255.255.255.0 U 0 0 0 eth0
dylan@ubuntu:/home/dylan# cat /etc/hosts
127.0.0.1 localhost

Re: route命令显示default gateway是localhost

发表于 : 2013-05-07 20:30
eexpress
有dnsmasq,不就是这样嘛。正常。
/etc/dnsmasq.conf

Re: route命令显示default gateway是localhost

发表于 : 2013-05-07 22:01
dylan_hit
eexpress 写了:有dnsmasq,不就是这样嘛。正常。
/etc/dnsmasq.conf
感谢你的回复。

我的系统是ubuntu server 1204,没有找到这个文件。
我搜索了一下dnsmasq,了解到这是一个提供简单的dns服务的程序。
我的系统上没有安装这个程序。

dylan@ubuntu:~$ sudo find /etc -name dnsmasq.conf
dylan@ubuntu:~$ dnsmasq
The program 'dnsmasq' is currently not installed. You can install it by typing:
sudo apt-get install dnsmasq-base
dylan@ubuntu:~$

Re: route命令显示default gateway是localhost

发表于 : 2013-05-08 11:26
dylan_hit
知道原因了。

route不使用-n选项时,会使用通过dns服务器将ip地址反解析成主机名。

由于网通默认的dns服务器提供的反解析将192.168.1.1对应成了localhost,才出现的这种情况。
使用8.8.8.8反解析,没有这个问题。

dylan@ubuntu:~$ nslookup 192.168.1.1
Server: 202.106.46.151
Address: 202.106.46.151#53

1.1.168.192.in-addr.arpa name = localhost.

dylan@ubuntu:~$ nslookup 192.168.1.1 8.8.8.8
Server: 8.8.8.8
Address: 8.8.8.8#53

** server can't find 1.1.168.192.in-addr.arpa.: NXDOMAIN