连接到 IPV4 路由器时无法解析名称,但可以 ping 地址,在 IPV6 路由器上一切正常

连接到 IPV4 路由器时无法解析名称,但可以 ping 地址,在 IPV6 路由器上一切正常

我家有一个路由器,可以为我提供 IPV4 地址。我的 Gentoo PC 工作正常,但我的 Gentoo 笔记本电脑停止解析名称。我拜访了我的父母并尝试连接到他们的路由器,这给了我一个 IPV6 地址,然后一切都恢复正常(我将我的名称服务器的 IPV6 等效项添加到 /etc/resolv.conf)。然后我尝试了我父母网络中的另一台路由器,它位于 IPV6 路由器后面,但它给了我一个 IPV4 地址,然后我再次无法解析名称(尽管如果我启动 Gentoo LiveCD 就可以,所以这是一个配置问题)我的笔记本电脑并与 IPV4 相关)(我将 IPV4 地址重新添加回 /etc/resolv.conf,并且我还尝试保留 IPV6 地址)。我可以很好地 ping 地址,但无法解析名称。可能是什么原因造成的?我该如何解决?

我的resolv.conf(IPV4,过去曾经工作过):

# dnsmasq
nameserver 127.0.0.1
# OpenNIC
nameserver 31.171.155.107
nameserver 79.133.43.124

IPV6(工作在IPV6路由器中):

# dnsmasq
nameserver ::1
# OpenNIC
nameserver 2a05:dfc7:5::53
nameserver 2001:19f0:7001:929:5400:00ff:fe30:50af

请注意,IPV4 路由器曾经在 IPV4 路由器上工作,但未经我修改它就停止工作了。其他内容被修改,名称解析停止工作。我的整个 /etc 文件夹(除了 ssl、shadow 等)都可以找到 这里

我刷新了所有 iptables 规则并将所有策略设置为接受。除了 dnsmasq 之外,没有任何与网络相关的服务正在运行(我尝试禁用它并从 resolv.conf 中删除 localhost 行,但无济于事)。我使用裸 wpa_supplicant 和 ip 连接到互联网,它工作得很好,只是名称解析没有(即使使用 Gentoo 的 rc 脚本通过有线接口连接时也没有)。两者iptables -Lip6tables -L返回:

 Chain INPUT (policy ACCEPT)
 target     prot opt source               destination         

 Chain FORWARD (policy ACCEPT)
 target     prot opt source               destination         

 Chain OUTPUT (policy ACCEPT)
 target     prot opt source               destination

一些测试及其结果(全部在无线连接的 IPV4 路由器上进行,尽管结果与有线连接相同):

$ nslookup google.com 8.8.8.8 
;; connection timed out: no servers could be reached.

...

$ dig @8.8.8.8 gentoo.org
;; connection timed out: no servers could be reached.

tcpdump 在尝试 ping 主机名(例如 google.com)时未注册任何内容,但在 ping IP 地址时成功注册 ICMP 回显:

$ ping gentoo.org
ping: unknown host gentoo.org 
$ 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_seq=1 ttl=48 time=74.0 ms
64 bytes from 8.8.8.8: icmp_seq=2 ttl=48 time=73.7 ms
64 bytes from 8.8.8.8: icmp_seq=3 ttl=48 time=73.7 ms
^C
--- 8.8.8.8 ping statistics ---
3 packets transmitted, 3 received, 0% packet loss, time 2002ms
rtt min/avg/max/mdev = 73.708/73.810/74.012/0.344 ms 

tcp转储:

$ tcpdump -i wlp3s0 port 53
dropped privs to tcpdump
tcpdump: verbose output suppressed, use -v or -vv for full protocol decode
listening on wlp3s0, link-type EN10MB (Ethernet), capture size 262144 bytes
^C
0 packets captured
0 packets received by filter
0 packets dropped by kernel 
$ tcpdump -i wlp3s0
dropped privs to tcpdump
tcpdump: verbose output suppressed, use -v or -vv for full protocol decode
listening on wlp3s0, link-type EN10MB (Ethernet), capture size 262144 bytes
07:05:55.807483 IP 192.168.25.11 > 8.8.8.8: ICMP echo request, id 5903, seq 1, length 64
07:05:55.881446 IP 8.8.8.8 > 192.168.25.11: ICMP echo reply, id 5903, seq 1, length 64
07:05:56.808617 IP 192.168.25.11 > 8.8.8.8: ICMP echo request, id 5903, seq 2, length 64
07:05:56.882287 IP 8.8.8.8 > 192.168.25.11: ICMP echo reply, id 5903, seq 2, length 64
07:05:57.810421 IP 192.168.25.11 > 8.8.8.8: ICMP echo request, id 5903, seq 3, length 64
07:05:57.884089 IP 8.8.8.8 > 192.168.25.11: ICMP echo reply, id 5903, seq 3, length 64
^C
6 packets captured
6 packets received by filter
0 packets dropped by kernel 

ipv4 路由器上的 ifconfig:

 wlp3s0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500                   
    inet 192.168.25.11  netmask 255.255.255.0  broadcast 192.168.25.255     
    inet6 fe80::16ec:71f7:dcc5:f175  prefixlen 64  scopeid 0x20<link>       
    ether 00:07:c8:82:a2:96  txqueuelen 1000  (Ethernet)                   
    RX packets 6  bytes 568 (568.0 B)                                       
    RX errors 0  dropped 0  overruns 0  frame 0                             
    TX packets 24  bytes 4038 (3.9 KiB)                                     
    TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0             

IP路由:

$ ip route
default via 192.168.25.1 dev wlp3s0
169.254.0.0/16 dev wlp3s0  proto kernel  scope link  src 169.254.144.184  metric 304
192.168.25.0/24 dev wlp3s0  proto kernel  scope link  src 192.168.25.11

nsswitch:

# /etc/nsswitch.conf:                                                           
# $Header: /var/cvsroot/gentoo/src/patchsets/glibc/extra/etc/nsswitch.conf,v 1.1 2006/09/29 23:52:23 vapier Exp $

passwd:      compat                                                             
shadow:      compat                                                             
group:       compat                                                             

# passwd:    db files nis                                                       
# shadow:    db files nis                                                       
# group:     db files nis                                                       

hosts:       files dns                                                         
networks:    files dns                                                         

services:    db files                                                           
protocols:   db files                                                           
rpc:         db files                                                           
ethers:      db files                                                           
netmasks:    files                                                             
netgroup:    files                                                             
bootparams:  files                                                             

automount:   files                                                             
aliases:     files 

我也运行了strace -e open dig @8.8.8.8 gentoo.org,它所做的最后一件事是打开/etc/resolv.conf(成功)。

答案1

iptables -L给出不完整的视图;特别是,它不显示 NAT 或 mangle 表,这些表可以而且确实会影响数据包的流动方式。为了完成调试,还需要检查这些不同的表

iptables -t nat -n -L

或转储整个防火墙规则集,例如

iptables-save

相关内容