Iptables block all ports excet the port 53 (udp,,tcp)

636 views Asked by At

my server has 5 IPs (192.168.0.23, 192.168.0.12, 192.168.0.13, 192.168.0.14 and 192.168.0.15).

The IP 192.168.0.23 is real and the others are virtual.

I´d like to block all ports in 192.168.0.12 except port 53 (udp and tcp).

All computers from my network can access all ips from this server but through ip 192.168.0.12 they can access only the port 53 (udp and tcp).

How can use iptables to block all ports in 192.168.0.12 except port 53 udp and tcp?

Thank you.

1

There are 1 answers

0
mHxDave On

you should consider in what chain the rule must be added(INPUT/OUTPUT/FORWARD) but something like this does so:

iptables -A INPUT -p tcp -d 192.168.0.12 -m tcp ! --dport 53 -j DROP
iptables -A INPUT -p udp -d 192.168.0.12 -m udp ! --dport 53 -j DROP