I am running a Debian 10 server which has multiple network interfaces. Can I create rules that will route all network traffic coming in to one IP address on one of the interfaces from the outside (i.e. from other devices on the network), to another IP address not on the same machine but elsewhere on the network? Similarly to WAN-to-LAN routing.
I know how to do it on e.g pfSense but I am quite lost with iptables..
Non-iptables solutions are also welcome.
Quick examples for forwarding traffic coming from outside and interfaces within the same machine from address original to another address for ip versions 4 and 6 (possibly excluding ipsec traffic with an endpoint on the original address and existing connections at point of execution). This also does NOT redirect traffic generated by locally executing programs, for that you need the OUTPUT chain.
If you want to limit the forwarding to only packets from outside you have to modify the rules, either add a
-i interface
naming the interface where they come in or match everything that did not originate from a local address-m addrtype ! --src-type LOCAL
. You could further exclude broadcast and multicast traffic by using-m addrtype --dst-type UNICAST --src-type UNICAST
. You should also check that the default policy for the FORWARD chain is ACCEPT or add specific rules in that chain.Dumping the existing
filter
andnat
tables can be done withiptables -S -t filter
andiptables -S -t nat
. Thefilter
table is where you configure the FORWARD rules if there is a DROP policy.The-A
before PREROUTING/POSTROUTING means Append. If you need to insert the rule, because there is a DROP at the end, you have to use-I
and put a number behind the chain name.