Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

Scenario:

Using DDwrt on a linksys router. I want to port forward a specific public IP address to internal IP 192.168.0.20 port 80 using IPtables. Not sure how to do this any help would be appreciated.

share|improve this question
    
Try this: serverfault.com/a/140626/117969 –  klocek Aug 13 '12 at 17:51

1 Answer 1

Something like:

iptables -t nat -A PREROUTING -d <public-ip> -i <wan-interface> -j DNAT --to 192.168.0.20

should work. If you want to forward only TCP port 80 on the public IP, you can do:

iptables -t nat -A PREROUTING -p tcp --dport 80 -d <public-ip> -i <wan-interface> -j DNAT --to 192.168.0.20:80
share|improve this answer
    
Something like iptables -t nat -A PREROUTING -d <public-ip> -d <wan-interface> -p tcp --dport 80 -j DNAT --to-destination 192.168.0.20 to specify only port 80 traffic, otherwise that 192.168.0.20 will become the recipient of all traffic to the public IP. –  cjc Aug 13 '12 at 17:53
    
Does'nt -d specify a destination address? Shouldn't that part be -s for the source address? –  Munky Aug 13 '12 at 17:55
    
Nope. From the NAT's perspective, the destination is the NAT box. NAT in this case needs to change the destination to the host behind the NAT. This all happens before the packet is routed. –  Falcon Momot Aug 13 '12 at 17:58
    
So the answer provided will get any port 80 traffic coming from public ip forwarded to my private one? –  Munky Aug 13 '12 at 18:01
    
The second command in my answer will. –  Falcon Momot Aug 13 '12 at 18:04

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.