I have a php / bash application on top of a Linux machine with 1 physical interface connecting to e.g., outbound webserver 220.127.116.11 :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 18.104.22.168 tun0
- send traffic to 22.214.171.124 :80
- close the vpn
sudo route del 126.96.36.199
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 188.8.131.52 :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:
- 184.108.40.206:9000 -> mark for rt0 (tun0 is default gateway) -> rewrite as 220.127.116.11:80 -> rt0
- 18.104.22.168:9001 -> mark for rt1 (tun1 is default gateway) -> rewrite as 22.214.171.124:80 -> rt1
- 126.96.36.199:9002 -> mark for rt2 (tun2 is default gateway) -> rewrite as 188.8.131.52: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.