Linux能ping通IP,ping不通域名

本文记录了一次排查网络中能够Ping通IP地址却Ping不通域名的问题经历。通过检查DNS配置和路由表并未找到原因,最终定位问题为防火墙阻止了DNS请求。文中详细介绍了如何通过配置防火墙规则来解决问题。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

今天碰到个问题, 能ping通IP地址, ping不通域名, 一直以为是 DNS解析服务器的问题, 找了半天, 问题不在这里。


[root@www postfix]# cat /etc/resolv.conf
nameserver 202.96.209.133
options attempts:1 timeout:1 rotate
#nameserver 10.202.72.117
nameserver 10.202.72.118
nameserver 114.114.114.114
nameserver 8.8.8.8
[root@www postfix]# 


看了一下路由表, 问题也不在路由网关上。

[root@www postfix]# netstat -rn
Kernel IP routing table
Destination     Gateway         Genmask         Flags   MSS Window  irtt Iface
115.28.80.0     0.0.0.0         255.255.252.0   U         0 0          0 eth1
10.163.176.0    0.0.0.0         255.255.240.0   U         0 0          0 eth0
169.254.0.0     0.0.0.0         255.255.0.0     U         0 0          0 eth0
169.254.0.0     0.0.0.0         255.255.0.0     U         0 0          0 eth1
192.168.0.0     10.163.191.247  255.255.0.0     UG        0 0          0 eth0
172.16.0.0      10.163.191.247  255.240.0.0     UG        0 0          0 eth0
10.0.0.0        10.163.191.247  255.0.0.0       UG        0 0          0 eth0
0.0.0.0         115.28.83.247   0.0.0.0         UG        0 0          0 eth1
[root@www postfix]# 
[root@www postfix]# 
[root@www postfix]# 
[root@www postfix]# 
[root@www postfix]# route
Kernel IP routing table
Destination     Gateway         Genmask         Flags Metric Ref    Use Iface
115.28.80.0     *               255.255.252.0   U     0      0        0 eth1
10.163.176.0    *               255.255.240.0   U     0      0        0 eth0
link-local      *               255.255.0.0     U     1002   0        0 eth0
link-local      *               255.255.0.0     U     1003   0        0 eth1
192.168.0.0     10.163.191.247  255.255.0.0     UG    0      0        0 eth0
172.16.0.0      10.163.191.247  255.240.0.0     UG    0      0        0 eth0
10.0.0.0        10.163.191.247  255.0.0.0       UG    0      0        0 eth0
default         115.28.83.247   0.0.0.0         UG    0      0        0 eth1

然后再看看 :

[root@www postfix]# grep hosts /etc/nsswitch.conf
#hosts:     db files nisplus nis dns
#hosts:      files dns
hosts:      dns files
我修改为 先 dns,  在  files, 测试了, 也还是不通。

最后发现是防火墙的原因, 我开启了防火墙, 造成了  ping 域名不通。

域名解析用到了53端口, 需要把下面的设置配置到防火墙里即可。

iptables -A INPUT -p udp --sport 53 -j ACCEPT
iptables -A OUTPUT -p udp --dport 53 -j ACCEPT
iptables -A INPUT -p udp --dport 53 -j ACCEPT
iptables -A OUTPUT -p udp --sport 53 -j ACCEPT

这样就可以 ping 通域名了。

评论 3
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

langeldep

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值