可以ping但不能用服务器名称wget
我有个问题。 在这个论坛的人们的帮助下,我设法建立了我的网络。 概括我有两台计算机comp1和comp2这样连接
comp2(eth0) -> comp1(eth1) comp1(eth0) -> network
我的界面看起来像这样:
COMP1:
auto lo iface lo inet loopback auto eth0 iface eth0 inet dhcp auto eth1 iface eth1 inet static address 10.10.0.10 netmask 255.255.255.0
COMP2:
auto eth0 iface eth0 inet static address 10.10.0.20 netmask 255.255.255.0 gateway 10.10.0.10
COMP2
$ route Kernel IP routing table Destination Gateway Genmask Flags Metric Ref Use Iface default 10.10.0.10 0.0.0.0 UG 100 0 0 eth0 10.10.0.0 * 255.255.255.0 U 0 0 0 eth0
COMP1:
$ route Kernel IP routing table Destination Gateway Genmask Flags Metric Ref Use Iface default g128.mp.l 0.0.0.0 UG 100 0 0 eth0 10.10.0.0 * 255.255.255.0 U 0 0 0 eth1 10.128.0.0 * 255.224.0.0 U 0 0 0 eth0
现在:我可以ssh到我的comp2并ping 8.8.8.8然后我得到:
ping 8.8.8.8 PING 8.8.8.8 (8.8.8.8) 56(84) bytes of data. 64 bytes from 8.8.8.8: icmp_req=1 ttl=43 time=42.6 ms 64 bytes from 8.8.8.8: icmp_req=2 ttl=43 time=41.8 ms
但是,如果我尝试wget:
wget -O - 173.194.70.113 | grep google function n(){if(google.timers.load.t){google.timers.load.t.ol=(new Date).getTime();google.timers.load.t.iml=e;google.kCSI.imc=c;google.kCSI.imn=b; google.kCSI.imp=d;void 0!==google.stt&&(google.kCS...
这是好的,但如果我这样尝试:
wget -O - http://www.google.com |grep google --2013-11-21 15:07:35-- http://www.google.com/ Resolving www.google.com (www.google.com)... failed: Temporary failure in name resolution. wget: unable to resolve host address `www.google.com'
这对我来说意味着这是一个DNS服务器问题。
我在comp1上的less /etc/resolv.conf
看起来像这样:
Dynamic resolv.conf(5) file for glibc resolver(3) generated by resolvconf(8) DO NOT EDIT THIS FILE BY HAND -- YOUR CHANGES WILL BE OVERWRITTEN nameserver 127.0.0.1 search xxx.xxx.xxx
xxx并不重要,但在comp2上它看起来像这样:
Dynamic resolv.conf(5) file for glibc resolver(3) generated by resolvconf(8) DO NOT EDIT THIS FILE BY HAND -- YOUR CHANGES WILL BE OVERWRITTEN
如何设置?
在/ etc / network / interfaces中设置静态IP地址时,您负责设置DNS名称服务器。 我建议你修改comp2上的文件来读取:
auto lo iface lo inet loopback auto eth0 iface eth0 inet static address 10.10.0.20 netmask 255.255.255.0 gateway 10.10.0.10 dns-nameservers 8.8.8.8 8.8.4.4
然后让系统重新读取并使用更改:
sudo ifdown eth0 && sudo ifup -v eth0
并测试:
ping -c3 8.8.8.8 ping -c3 www.google.com
我遇到了类似的问题,在我的情况下,ping / dig / nslookup还可以,但是wget / curl和Firefox没有正常工作。 我编辑了/etc/resolv.conf
以使用另一个名称空间,如114.114.115.115,一切正常。 我也尝试在Windows 7中设置相同的DNS,一切都还可以,这让我很困惑。 但是我找到了一篇文章,其中人们讨论了ipv6引起的问题 。 最后,我通过使用sysctl
实用程序在以下步骤中禁用Ubuntu中的IPv6来修复此问题。
# show whether ipv6 is disabled or not sudo sysctl -a | grep disable_ipv6 # disable all the ipv6 sudo sysctl -w net.ipv6.conf.all.disable_ipv6=1 sudo sysctl -w net.ipv6.conf.default.disable_ipv6=1 # also you can check the settings sudo sysctl -a | grep disable_ipv6
在那之后,我可以毫无问题地连接到互联网。 希望它可以帮助你!
顺便说一下,如果你需要永久地进行上述设置,你应该编辑文件/etc/sysctl.conf
并附加以下行:
net.ipv6.conf.all.disable_ipv6=1 net.ipv6.conf.default.disable_ipv6=1