Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

I'm connected to the Internet via a campus network: IP range is, let's say 10.42.0.0/16 and everything has to go through a proxy server 10.42.0.42.

I'm sometimes connected to this network via a wireless access point, in a local IP range 192.168.0.0/24, this wireless router being connected to the campus network.

I'm also using a personal VPN, based on OpenVPN. My VPN IP range is 10.8.0.0/24.

When I'm connected to this wireless network, my routing table is:

Kernel IP routing table
Destination     Gateway         Genmask         Flags Metric Ref    Use Iface
0.0.0.0         192.168.1.1     0.0.0.0         UG    304    0        0 wlan0
127.0.0.0       0.0.0.0         255.0.0.0       U     0      0        0 lo
192.168.1.0     0.0.0.0         255.255.255.0   U     304    0        0 wlan0

And when I start my VPN on this wireless network:

Kernel IP routing table
Destination     Gateway         Genmask         Flags Metric Ref    Use Iface
0.0.0.0         10.8.0.41       128.0.0.0       UG    0      0        0 tun0
0.0.0.0         192.168.1.1     0.0.0.0         UG    304    0        0 wlan0
10.8.0.0        10.8.0.41       255.255.255.0   UG    0      0        0 tun0
10.8.0.41       0.0.0.0         255.255.255.255 UH    0      0        0 tun0
127.0.0.0       0.0.0.0         255.0.0.0       U     0      0        0 lo
128.0.0.0       10.8.0.41       128.0.0.0       UG    0      0        0 tun0
10.42.0.0       192.168.1.1     255.255.0.0     UG    0      0        0 wlan0
10.42.0.42      192.168.1.1     255.255.255.255 UGH   0      0        0 wlan0
192.168.1.0     0.0.0.0         255.255.255.0   U     304    0        0 wlan0

As you see, I have configured my VPN so that the campus network is not redirected to tun0, so that servers in this private zone remains available.

But here comes the problem: the Wireless being unstable (and I can't do anything about it), I am regularly disconnected and reconnected. During this process, all entries in the routing table about wlan0 are flushed, and my table looks like this afterwards:

Kernel IP routing table
Destination     Gateway         Genmask         Flags Metric Ref    Use Iface
0.0.0.0         10.8.0.41       128.0.0.0       UG    0      0        0 tun0
0.0.0.0         192.168.1.1     0.0.0.0         UG    304    0        0 wlan0
10.8.0.0        10.8.0.41       255.255.255.0   UG    0      0        0 tun0
10.8.0.41       0.0.0.0         255.255.255.255 UH    0      0        0 tun0
127.0.0.0       0.0.0.0         255.0.0.0       U     0      0        0 lo
128.0.0.0       10.8.0.41       128.0.0.0       UG    0      0        0 tun0

And nothing works anymore : all traffic is redirected to tun0, which doesn't exists any longer and openVPN cannot reconnect to my server (No route to host.). The only workaround I found is manually restarting my OpenVPN client.

Is it possible to stabilize this, and how ?

I'm running on Gentoo Linux, managing my network with Wicd.

share|improve this question
    
Do you control the server? –  MariusMatutiae May 31 at 9:55
    
@MariusMatutiae I indeed control the OpenVPN server, it is outside of the campus network. –  Levans May 31 at 10:51
    
Do you have any info about OpenVPN in /var/log/daemon.log? In /etc/openvpn/openvpn.log? –  MariusMatutiae May 31 at 13:45
    
@MariusMatutiae simply things like "cannot connect to server, no route to host." But a friend of mine gave ma an other workaroud, I'll write it here as an answer. –  Levans May 31 at 13:52

2 Answers 2

You may try as follows. Add these two lines to your client config file:

 route-delay 2
 route-up "/path/to/shell/script.sh"

The file script.sh (which must be made executable) consists of a single command:

 #!/bin/bash
 ip route add 10.42.0.0/24 via 192.168.1.1 dev wlan0

The command route-delay forces the following commands to be executed 2 seconds (change this as you best see fit) after all of the routes have been set-up; the following command, every time the routes are brought up, executes a shell script, whose only purpose is to add back the ad-hoc route you created.

share|improve this answer
    
It doesn't change anything. The problem is, if I got disconnected from wireless (like 10 minutes after I started my VPN), OpenVPN is not automatically restarted, and it doesn't reset routes, it just tries to reconnect to server(and can't, because routes are messed up). –  Levans May 31 at 10:50
up vote 0 down vote accepted

It is possible, using Wicd scripts to have it restart OpenVPN when connection to Wireless is re-established.

Simply create an executable script in /etc/wicd/scripts/postconnect/restart-openvpn.sh checking the existence of OpenVPN PID file and restarting it if it was already started :

#!/bin/bash
[ -f /var/run/openvpn.pid ] && /etc/init.d/openvpn restart
share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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