I have a php / bash application on top of a Linux machine with 1 physical interface connecting to e.g., outbound webserver 123.123.123.123 :80. I do this via several openvpn providers. I have both tun and tap providers, but my favorite provider uses tun.
Actually I'm perfectly able to serially:
- open the vpn
sudo route add 123.123.123.123 tun0
- send traffic to 123.123.123.123 :80
- close the vpn
sudo route del 123.123.123.123
I use the "route-nopull" option inside the .ovpn config file in order to keep the Linux machine reachable and allow simultaneous openvpn connections.
Now I need to open several independent requests, always to outbound webserver 123.123.123.123 :80. But my actual flow is serial and I need to wait the first connection to close and clear itself before attempting a second connection.
I'm quite sure that I can achieve it mangling with "fake ports". Eg:
- interfaces tun0, tun1, tun2
- fake ports 9000, 9001, 9002
- multiple routing tables rt0, rt1, rt2
So conceptually speaking:
- 123.123.123.123:9000 -> mark for rt0 (tun0 is default gateway) -> rewrite as 123.123.123.123:80 -> rt0
- 123.123.123.123:9001 -> mark for rt1 (tun1 is default gateway) -> rewrite as 123.123.123.123:80 -> rt1
- 123.123.123.123:9002 -> mark for rt2 (tun2 is default gateway) -> rewrite as 123.123.123.123:80 -> rt2
I can only represent the concept because I have almost no skills on iptables. If you have different ways to achieve the result, they're welcome. Thank you for reading and helping.