Revision 1 as of 2007-01-22 01:31:21

Clear message


Have you been wondering if and how it is possible do do things automatically, based on your current network connection?

For instance when establishing a connection you could check your mail, start a download tool, etc. You could even stop the download when there's no connection left... Another appliance would be to mount your homeserver as soon as your connected to your homenetwork and unmount it when you disconnect from your network! (actually i use this to solve a system freeze during shutdown (and the fsck the next boot...) when i forget to disconnect before shutting down my laptop)

Basics (applies for NetworkManager as well as the Standart network config)

  1. You must put your scripts into 1 of the following 4 folders to get them executed on the appropriate event:BR(normally you can put the "onConnection" script in "if-up.d" and the "onDissconnection"-script in "if-down.d")

    • /etc/network/if-pre-up.d/

    • /etc/network/if-up.d/

    • /etc/network/if-down.d/

    • /etc/network/if-post-down.d/

If they don't exist you must create them as superuser. for example :

sudo mkdir /etc/network/if-down.d/
  1. Write your script and save it.
  2. Now you can copy it to one of the folders above and mark the script executale. must be superuser!

sudo cp <pathtoyoursavedfile>/<file> /etc/network/<folderyouselect>
sudo chmod 755 /etc/network/<folderyouselect>/<file>

When using : Standart Network Administration Tool / shell

This only applies when you have configured your network with the standart tool shipped with ubuntu 6.10 (or older) or configure it from the shell.

  1. do the step described for network manager
  2. Edit the text configuration file /etc/network/interfaces and add one of the following directive pre-up , post-up , pre-down , post-down to the appropriate network connection, for example :

auto eth0
iface eth0 inet dhcp
name WiFi
post-up /etc/network/if-up.d/myscript.sh
  1. restart your network

/etc/init.d/networking restart