Archive for the ‘ IPtables ’ Category

Port Forwarding with Iptables

You can use port forwarding in iptables, to forward a port to private ip , here is how you can do that :

iptables -t nat -I PREROUTING -p tcp -d <listenip> --dport 22 -j DNAT --to <ipToForwardTo>:22
iptables -I FORWARD -p tcp -d <ipToForwardTo> --dport 22 -j ACCEPT

Delete Rules in Iptables

iptables -D (Chain Name) ( RuleNum)

eg.

iptables -D FORWARD 1

You can delete all rules from filter chain by typing :

iptables -F

or from nat table

iptables -F -t nat

Redirecting Ports in Iptables

Redirect ports in iptables

iptables -t nat -A PREROUTING -i eth0 -p tcp –dport $srcPortNumber -j REDIRECT –to-port $dstPortNumbe