Ask Ubuntu is a question and answer site for Ubuntu users and developers. It's 100% free.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I use VPN client to connect to my corporate servers. It creates tun0 interface after starting the client. I've written script which install specific routes point to tun0 interface and rest to use normal wifi connection. So that, only my office related traffic goes via VPN and rest are goes via home internet connection. How do I make the script to run automatically when tun0 interface up/down events ?.

share|improve this question
up vote 2 down vote accepted

I am not sure about tun0, but I think the script in /etc/network/if-up.d/ and /etc/network/if-down.d/ are invoked when an interface goes up or down, respectively.

Inside the script you can determine which interface is interested from the content of the variable IFACE.

To be sure, add a simple script to /etc/network/if-up.d/ which content is

# filename: tun-up

if [ "$IFACE" = tun0 ]; then
  echo "tun0 up" >> /var/log/tun-up.log

make it executable

sudo chmod +x /etc/network/if-up.d/tun-up

then see if the up events are recorded in /var/log/tun-up.log

share|improve this answer
Thanks. I'm getting below syslog message and the scripts are not invoked at all. /etc/network/interfaces has no info other than loopback. May 9 15:26:48 mypc NetworkManager[869]: SCPlugin-Ifupdown: device added (path: /sys/devices/virtual/net/tun0, iface: tun0): no ifupdown configuration found. – sudurais May 9 '11 at 22:28

Your Answer


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.