iptables 打开dns访问端口
iptables 打開dns訪問端口
今天在測試本機DNS的時候發現無法解釋域名,經查原因出在iptables上邊。
我立即加了 iptables -t filter -A INPUT -p udp --dport 53 -j ACCEPT 的鏈路,發現還是
不行。一般認為DNS就是通過訪問DNS服務器的53端口進行域名解釋的。本機端口應該是任意的,
可是就是不通。
沒有辦法再添加iptables -t filter -j LOG -p udp --log-prefix "DNS monitor: " 添加一
個日志功能。
添加了以上記錄后,還不能記錄那個功能。還需要再在
/etc/syslog.conf
添加一個記錄,
kern.warning /var/log/iptables.log
kern是設備名,warning 是記錄級別,/var/log/iptables.log 記錄日志文件位置。
其中的具體設置如果大家有興趣可以另外查找一下其它的文檔。
最后重啟一下syslog服務。
service syslog restart
現在就可以了。
使用nslookup www.sina.com.cn
然后我們看一下/var/log/iptables.log文件
:10:db:69:43:50:08:00 SRC=219.141.140.10 DST=192.2.8.185 LEN=169 TOS=0x00 PREC=0x00
TTL=241 ID=63822 DF PROTO=UDP SPT=53 DPT=45623 LEN=149
里面的SPT=53是53,也就是我們需要開放53端口。
iptables -t filter -A INPUT -p udp -m udp -j ACCEPT
nslookup www.sina.com.cn
Server:???????? 219.141.140.10
Address:??????? 219.141.140.10#53
現在再執行nslookup www.sina.com.cn
Non-authoritative answer:
www.sina.com.cn canonical name = jupiter.sina.com.cn.
jupiter.sina.com.cn???? canonical name = hydra.sina.com.cn.
Name:?? hydra.sina.com.cn
Address: 218.30.108.189
Name:?? hydra.sina.com.cn
Address: 218.30.108.190
Name:?? hydra.sina.com.cn
Address: 218.30.108.191
? 最后要單獨說明一下,DNS默認使用端口是UDP53 不是TCP,看下面
[root@ncunicom sysconfig]# iptables -L -n
Chain INPUT (policy ACCEPT)
target???? prot opt source?????????????? destination????????
ACCEPT???? all? --? 0.0.0.0/0??????????? 0.0.0.0/0?????????? state RELATED,ESTABLISHED
ACCEPT???? icmp --? 0.0.0.0/0??????????? 0.0.0.0/0??????????
ACCEPT???? all? --? 0.0.0.0/0??????????? 0.0.0.0/0??????????
ACCEPT???? tcp? --? 0.0.0.0/0??????????? 0.0.0.0/0?????????? state NEW tcp dpt:22
ACCEPT???? tcp? --? 0.0.0.0/0??????????? 0.0.0.0/0?????????? state NEW tcp dpt:21
ACCEPT???? tcp? --? 0.0.0.0/0??????????? 0.0.0.0/0?????????? state NEW tcp dpt:20
ACCEPT???? tcp? --? 0.0.0.0/0??????????? 0.0.0.0/0?????????? state NEW tcp dpt:53
ACCEPT???? udp? --? 0.0.0.0/0??????????? 0.0.0.0/0?????????? udp dpt:53
REJECT???? all? --? 0.0.0.0/0??????????? 0.0.0.0/0?????????? reject-with icmp-host-prohibited
Chain FORWARD (policy ACCEPT)
target???? prot opt source?????????????? destination????????
REJECT???? all? --? 0.0.0.0/0??????????? 0.0.0.0/0?????????? reject-with icmp-host-prohibited
Chain OUTPUT (policy ACCEPT)
target???? prot opt source?????????????? destination????????
起作用的是這條:ACCEPT???? udp? --? 0.0.0.0/0??????????? 0.0.0.0/0?????????? udp dpt:53
總結
以上是生活随笔為你收集整理的iptables 打开dns访问端口的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 关于前端未来发展
- 下一篇: [论文阅读] (24) 向量表征:从Wo