At home I have an OpenVPN server which is at the same time an OpenVPN client. The purpose is to share one foreign IP address between several devices. In the local network everything works fine since I've set up masquerading for local networks. But if the client is trying to connect from the Internet then it gets screwed since the incoming packets are received via one interface (eth0) but the replies are sent through default gateway (tun1). How do I force those packets to be sent through their original gateway (eth0)?
I've tried the following:
echo "101 ovpntraffic">>/etc/iproute2/rt_tables ip rule add fwmark 2 table ovpntraffic ip route add default via 192.168.75.1 dev eth0 table ovpntraffic iptables -t mangle -A OUTPUT -p udp -m udp --sport 1194 -j MARK --set-mark 2
According to my understanding this should mark all the packets outgoing from port 1194 (which is the port used by the OpenVPN server) with mark 2. Then those packets should be routed according to the table ovpntraffic and end up being sent through gateway 192.168.75.1. But the OpenVPN client still can not establish a connection with the server. What is wrong with the configuration above?
At the same time I can explicitly specify a route for a particular client ip to be routed through eth0. In that case everything works as expected: the client can connect to the OpenVPN server.