I have openvpn client running in my centos box which I use as a router for my internal network. I have two interfaces for reach outside world.
eth0 - normal internet
tun0 - openvpn tunnel
I disable the opevpn auto route pulling by putting "route-noexec " option and I handle all the routes manually now. after I up the openvpn tunnel my routing table is like this.
Kernel IP routing table
Destination Gateway Genmask Flags Metric Ref Use Iface
192.168.80.0 0.0.0.0 255.255.255.0 U 0 0 0 eth1
10.8.0.0 0.0.0.0 255.255.255.0 U 0 0 0 tun0
192.168.44.0 0.0.0.0 255.255.255.0 U 0 0 0 eth0
192.168.11.0 0.0.0.0 255.255.255.0 U 0 0 0 dummy0
169.254.0.0 0.0.0.0 255.255.0.0 U 1002 0 0 eth0
169.254.0.0 0.0.0.0 255.255.0.0 U 1003 0 0 eth1
0.0.0.0 192.168.44.1 0.0.0.0 UG 0 0 0 eth0
Now I have internal host who connected to interface 192.168.80.0 on my centos box
192.168.80.50
I need to route all traffic from this user through interface tun0 and all other traffic through eth0
I tried adding POSTROUTING rules like this
iptables -t nat -A POSTROUTING -s 192.168.80.50 -o tun0 -j MASQUERADE
iptables -t nat -A POSTROUTING -o eth0 -j MASQUERADE
but all the clients go through only eth0 including 192.168.80.50. how can I achieve this ?