Search code examples
network-programmingroutesiptablesopenwrt

Forwarding within local network to same network


I have X-Wrt based on OpenWrt 8.09 on my router

I have home LAN of few computers on which I have some network servers (SVN, web, etc). For each of service I made forwarding on my router (Linksys wrt54gl) to access it from the Internet (<my_external_ip>:<external_port> -> <some_internal_ip>:<internal_port>)

But within my local network this resources by above request is unreachable (so I need make some reconfiguration <some_internal_ip>:<internal_port> to access).

I added some line to my /etc/hosts
<my_external_ip> localhost

So now all requests from local network to <my_external_ip> forwards to my router but further redirection to appropriate port not works.

Advise proper redirection please.


Solution

  • You need to install an IP redirect for calls going out of the internal network and directed to the public IP. Normally these packets get discarded. You want to reroute them, DNATting to the destination server, but also masqueraded so that the server, seeing as you, its client, are in its same network, doesn't respond directly to you with its internal IP (which you, the client, not having sent the packet there, would discard).

    I found this on OpenWRT groups:

    iptables -t nat -A prerouting_rule -d YOURPUBLICIP -p tcp --dport PORT -j DNAT --to YOURSERVER
    iptables -A forwarding_rule -p tcp --dport PORT -d YOURSERVER -j ACCEPT
    iptables -t nat -A postrouting_rule -s YOURNETWORK -p tcp --dport PORT -d YOURSERVER -j MASQUERADE
    

    https://forum.openwrt.org/viewtopic.php?id=4030