0

I have this configuration script:

I OPENVPN TUNNELS

openvpn --config serverx.ovpn  > /dev/null 2>&1 &
openvpn --config servery.ovpn  > /dev/null 2>&1 &

TEST ON MY SCRIPT which outputs the connection address

route add 69.195.103.232/32 dev tun0
curl http://checkmyproxy.xx/checkproxy.php
route delete 69.195.103.232

I GET THE CORRECT SERVERX IP

I PREPARE IPTABLES

echo 1 > /proc/sys/net/ipv4/ip_forward
iptables -F
iptables -t nat -F
iptables -t mangle -F
iptables -X

I EDIT RT_TABLES

nano /etc/iproute2/rt_tables

I ADD IN RT_TABLES

100 tunnel0
101 tunnel1

THEN

ip route add default dev tun0 table tunnel0
ip route add default dev tun1 table tunnel1
ip rule add from all fwmark 0x100 table tunnel0
ip rule add from all fwmark 0x101 table tunnel1
ip route flush cache
ip rule show

ALL FINE, I get the following results

IFCONFIG

eth0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
        inet 192.168.1.10  netmask 255.255.255.0  broadcast 192.168.1.255
        ETC ETC
lo: flags=73<UP,LOOPBACK,RUNNING>  mtu 65536
        inet 127.0.0.1  netmask 255.0.0.0
        ETC ETC
tun0: flags=4305<UP,POINTOPOINT,RUNNING,NOARP,MULTICAST>  mtu 1500
        inet 10.120.1.6  netmask 255.255.255.255  destination 10.120.1.5
        ETC ETC, IP CLASS CAN VARY
tun1: flags=4305<UP,POINTOPOINT,RUNNING,NOARP,MULTICAST>  mtu 1500
        inet 10.199.1.6  netmask 255.255.255.255  destination 10.199.1.5
        ETC ETC, IP CLASS CAN VARY

ROUTES

default         192.168.1.254   0.0.0.0         UG    0      0        0 eth0
10.151.1.5      0.0.0.0         255.255.255.255 UH    0      0        0 tun0
10.199.1.5      0.0.0.0         255.255.255.255 UH    0      0        0 tun1
link-local      0.0.0.0         255.255.0.0     U     1002   0        0 eth0
192.168.1.0     0.0.0.0         255.255.255.0   U     0      0        0 eth0

IP RULE SHOW

0:  from all lookup local 
32764:  from all fwmark 0x100 lookup tunnel0 
32765:  from all fwmark 0x101 lookup tunnel1 
32766:  from all lookup main 
32767:  from all lookup default 

I MARK PACKETS to associate to the right route / interface

iptables -A PREROUTING -t mangle -p tcp --sport 10000 -j MARK --set-mark 100
iptables -A PREROUTING -t mangle -p tcp --sport 10001 -j MARK --set-mark 101
iptables-save

AND THE QUESTION IS

How can I obtain to return server x IP and server y IP for the first and for the second request, using the following commands?

 curl http://checkmyproxy.xx:10000/checkproxy.php
 curl http://checkmyproxy.xx:10001/checkproxy.php

The final port is always 80, so 10000 and 10001 should be translated as 80. This other translates correctly, but I get the eth0 real address (no tunneling), so it bypassess the mangle mark

iptables -t nat -A OUTPUT -p tcp --dport 10000 -j DNAT --to :80
iptables-save

Thank you!

0

I solved and documented it here: http://aftermanict.blogspot.it/2015/11/bash-iptables-iproute2-and-multiple.html

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.