I have a gateway machine on my network running a VPN which routes outgoing traffic through a router, but the masquerading rules prevent the machines on the network from connecting directly to the router, as the masquerading rules route the outgoing traffic through the VPN .
These are the masquerading rules on the gateway machine:
iptables -t nat -A POSTROUTING -s 192.168.1.0/24 -o tunGateway01 -j MASQUERADE iptables -A FORWARD -s 192.168.1.0/24 -o eth0 -j ACCEPT iptables -A FORWARD -d 192.168.1.0/24 -m state --state ESTABLISHED,RELATED -i eth0 -j ACCEPT
iptables rules seems to be this one
iptables -t nat -A POSTROUTING -s 192.168.1.0/24 -o tunGateway01 -j MASQUERADE
The router itself has the IP address
192.168.4.1 but the masquerading rule sends out all packets from the machines through
10.8.0.1 which is the subnet used by the
tunGateway01 device, so I need a rule which checks if the destination is
192.168.4.1 and will route it directly to the router.
Is there an
iptables masquerading syntax that includes changing the route based on the packet's destination, eg something along the lines of
iptables -t nat -A POSTROUTING -s 192.168.1.0/24
-d 192.168.4.0/24 is the destination rule that makes out the target to be the wan device and I have changed and the
-o wan01 changes the target of the packet the router itself.