iptables destination ip and port
44,670
For the first, do not specify --dport
parameter, this will mean "any port":
iptables -t nat -A PREROUTING -p tcp --jump DNAT --to-destination 129.94.5.88:5000
For the second, change --dport
parameter with -d
parameter for destination host:
iptables -t nat -A PREROUTING -p tcp -d 8.8.8.8 --jump DNAT --to-destination 129.94.5.88:5000
Related videos on Youtube
Author by
sukhvir
Updated on September 18, 2022Comments
-
sukhvir over 1 year
I am looking for a way to forward all traffic(to any port) from a pc to a certain ip.
Looking at the rule below :
iptables -t nat -A PREROUTING -p tcp --dport 443 --jump DNAT --to-destination 129.94.5.88:5000
this tells me all traffic destined for port 443 should be diverted to
129.94.5.88:5000
. How do I change this rule to say :iptables -t nat -A PREROUTING -p tcp --dport "ANY DESTINATION PORT" --jump DNAT --to-destination 129.94.5.88:5000
Also I would like to know how to do redirection based on destination ip not port. So looking this rule again :
iptables -t nat -A PREROUTING -p tcp --dport 8443 --jump DNAT --to-destination 129.94.5.88:5000
How do I change this to redirect based on destintion IP (lets say
8.8.8.8
) rather than port ?-
MadHatter almost 10 years1) Remove the
--dport 443
requirement. 2) Replace--dport 8443
with-d 8.8.8.8
. 3) Read the man page.
-