One-to-one NAT
From DD-WRT Wiki
Revision as of 19:47, 10 April 2009 (edit) Stidem (Talk | contribs) (→PORT FORWARD) ← Previous diff |
Revision as of 19:53, 10 April 2009 (edit) (undo) Stidem (Talk | contribs) (Added examples and cleaned up grammer.) Next diff → |
||
Line 1: | Line 1: | ||
One-to-one NAT (aka Static NAT) is a way to make systems behind a firewall and configured with private IP addresses (those addresses reserved for private use in RFC 1918) appear to have public IP addresses.¹ | One-to-one NAT (aka Static NAT) is a way to make systems behind a firewall and configured with private IP addresses (those addresses reserved for private use in RFC 1918) appear to have public IP addresses.¹ | ||
- | + | These examples have been tested and work with multiple public static IPs. | |
- | + | Tested with: | |
- | + | * WRT54GL v.1.1 with DD-WRT RC6 and it works just fine.² | |
- | + | * DD-WRT v24-sp2 (01/01/09) mega on Linksys WRT 600N V1 | |
__TOC__ | __TOC__ |
Revision as of 19:53, 10 April 2009
One-to-one NAT (aka Static NAT) is a way to make systems behind a firewall and configured with private IP addresses (those addresses reserved for private use in RFC 1918) appear to have public IP addresses.¹
These examples have been tested and work with multiple public static IPs. Tested with:
- WRT54GL v.1.1 with DD-WRT RC6 and it works just fine.²
- DD-WRT v24-sp2 (01/01/09) mega on Linksys WRT 600N V1
Contents |
Setup
Startup
Set up new public static IP on dd-wrt WAN interface vlan1. This must be done for each public static IP and should be save to the Startup script using the Save Statup button.
ifconfig vlan1:1 PUBLIC_IP1 netmask NETMASK broadcast BROADCAST ifconfig vlan1:2 PUBLIC_IP2 netmask NETMASK broadcast BROADCAST
Examples:
ifconfig vlan1:1 173.xxx.xxx.249 netmask 255.255.255.240 broadcast 173.xxx.xxx.255 ifconfig vlan1:2 173.xxx.xxx.250 netmask 255.255.255.240 broadcast 173.xxx.xxx.255
Firewall
SNAT/DNAT
route all packets for the new public ip, to a certain local ip
iptables -t nat -I PREROUTING -i vlan1 -d PUBLIC_IP -j DNAT --to-destination LAN_IP
masquerade returned packets from the local ip to the public ip
iptables -t nat -I POSTROUTING -o vlan1 -s LAN_IP -j SNAT --to-source PUBLIC_IP
translate anything else from the lan to the "main" router ip
iptables -t nat -I POSTROUTING -o vlan1 -s LAN_SUBNET (ex. 192.168.1.0/24) -j SNAT --to-source MAIN_IP
PORT FORWARD
Forward port X to above local IP
iptables -I FORWARD -p tcp -i vlan1 -d LAN_IP --dport X -j ACCEPT
Examples:
iptables -I FORWARD -p tcp -d 192.168.0.20 --dport 21 -j ACCEPT iptables -I FORWARD -p tcp -d 192.168.0.20 --dport 80 -j ACCEPT iptables -I FORWARD -p tcp -d 192.168.0.20 --dport 5900 -j ACCEPT
You could also replace above rule(s) with the following:
iptables -I FORWARD -p all -i vlan1 -d LAN_IP -j ACCEPT
Which instead of forwarding just a single port, will let through all tcp/udp connections on all ports to this public ip-->lan ip.
In other words forwarding all connections would be no firewalling what so ever.
Resources
¹ http://www.shorewall.net/NAT.htm
² http://www.dd-wrt.com/phpBB2/viewtopic.php?t=24555