Redirect traffic from 127.0.0.1 to 127.0.0.1 on port 53 to port 5300 with iptables
Posted
by
Zagorax
on Server Fault
See other posts from Server Fault
or by Zagorax
Published on 2012-06-22T20:58:31Z
Indexed on
2012/06/23
9:19 UTC
Read the original article
Hit count: 144
iptables
I'm running a local dns server on port 5300 to develop a software. I need my machine to use that dns but I wasn't able to tell /etc/resolv.conf to check on a different port. I searched a bit on google and I didn't find a solution.
I set 127.0.0.1 as nameserver on /etc/resolv.conf. This is my whole /etc/resolv.conf:
nameserver 127.0.0.1
Could you please tell me how can I redirect outbound traffic on port 53 to another port?
I tried the following but it didn't work:
iptables -t nat -A PREROUTING -p tcp --dport 53 -j DNAT --to 127.0.0.1:5300
iptables -t nat -A PREROUTING -p udp --dport 53 -j DNAT --to 127.0.0.1:5300
Here is the output of iptables -t nat -L -v -n
(with suggested rules):
Chain PREROUTING (policy ACCEPT 0 packets, 0 bytes)
pkts bytes target prot opt in out source destination
0 0 REDIRECT tcp -- * * 0.0.0.0/0 0.0.0.0/0 tcp dpt:53 redir ports 5300
0 0 REDIRECT udp -- * * 0.0.0.0/0 0.0.0.0/0 udp dpt:53 redir ports 5300
Chain POSTROUTING (policy ACCEPT 302 packets, 19213 bytes)
pkts bytes target prot opt in out source destination
Chain OUTPUT (policy ACCEPT 302 packets, 19213 bytes)
pkts bytes target prot opt in out source destination
© Server Fault or respective owner