View Full Version : [ubuntu] Run script when connecting to specific network

June 29th, 2008, 02:04 PM
I'm using Ubuntu Hardy Heron on my laptop and autoconnect to a WPA2 wireless network when at home using the NetworkManager from Gnome.
Furthermore I have a server running NFS on my homenetwork, and I would like a NFS share from the server to be automounted on my laptop when I connect to my own network.
Is that possible?

June 29th, 2008, 04:31 PM
I dont think its possible using NetworkManager -- they haven't integrated this feature. I believe WICD has this feature, or you are going to have to make a script and then connect manually.

June 29th, 2008, 04:35 PM
The easiest thing would be to just add some code to /etc/rc.local that detects what network you're on and runs the appropriate commands if you're on your home network. Detecting what network you're on could be done by parsing the output of "netstat -in", "netstat -rn", and/or "ifconfig".

Here's some sample code to get you started:

DEFROUTE=`netstat -rn | awk '/^ { print $2 }'`

if [ "$DEFROUTE" = "$HOMEROUTER" ]; then
# if you get here then you're on your home network
# put the commands you want to run here

You would need to replace with the IP address of your default gateway on your home network.