OpenWrt Forum Archive

Topic: Route multiple WAN IPs to internal hosts

The content of this topic has been archived on 8 Feb 2018. There are no obvious gaps in this topic, but there may still be some posts missing at the end.

Hi everyone,

I'm trying to set up OpenWRT with multiple external WAN IPs. I have set them as aliases to the WAN interface.

The problem lies when I need to route traffic coming to a particular WAN IP to an internal host, but with a specific port.

For example:
Internet -> 1.1.1.1:80 >-mapto-> 192.168.1.2:80
Internet -> 1.1.1.2:80 >-mapto-> 192.168.1.3:80

I was hoping someone would be graciously able to help me achieve this. I've already bricked the router once trying to do this. :-(

Thanks!

You could probably use the firewall redirect

config 'redirect'
    option '_name' 'example'
    option 'src' 'wan'
    option 'proto' 'tcp'
    option 'dest_ip' '192.168.1.2'
    option 'dest_port' '80'
    option 'target' 'DNAT'
    option 'dest' 'lan'
    option 'src_dip' '1.1.1.1'
    option 'src_dport' '80'

Thanks for the reply. smile

I did end up working it out by using DNAT and SNAT - I just didn't understand them enough when I started. smile

You can add firewall rules directly:
iptables -t nat -A PREROUTING -d 1.1.1.1 -p tcp --dport 80 -j DNAT --to 192.168.1.2:80

The discussion might have continued from here.