# network-adaptive scripts and network-manager

## depontius

I've been using network-adaptive scripts on my systems for years now.  Using the standard dhcp hooks, I find out what address I've just gotten and take "appropriate" actions.  For instance:

If I'm at work, I start openafs-client, start sshd, tweak /etc/pam.d/ to afs-integrate my login, make sure X is listening for TCP connections, etc.

If I'm at home, I start sshd, make sure X is listening for TCP connections, and start the daemon side of my employer's VPN.

If I'm  elsewhere, I start nothing, make sure X is only listening on the Unix socket, and start the daemon side of my employer's VPN.

X configuration is more flexible now, but I've used various tests to check/guess if I'm docked, and tweak the X configuration for a deskto monitor.

For one thing, this produces a very safe system when on the road, because a "netstat -tupln" shows that it simply has no open ports at all - even better than just a firewall.  (Safety in layers)  It's also very convenient for home and work, because by the time I login, the system has "done the right thing" and is pretty much ready to go.

For various other reasons, I now need to be working also (not giving up my Gentoo) with a RedHat-based system, meaning Gnome and network-manager.  I'd like to do this same network-adaptation stuff, and TPTB have suggested that I work through network-manager.  I've checked the documentation pages, and at the moment don't see any sort of hooks of the kind that I need.  Maybe I'm not looking in the right place.  Can anyone supply a hint or two?

----------

## Dagger

I guess NM's dispatcher should be answer to your problem.

Quite old, but good starting point:

http://sysadminsjourney.com/content/2008/12/18/use-networkmanager-launch-scripts-based-network-location

https://help.ubuntu.com/community/RoamingProfilesWithNetworkManager

----------

## depontius

 *Dagger wrote:*   

> I guess NM's dispatcher should be answer to your problem.

 

Thanks for the links.  I've been surprised in the few answers to this question, because I would think that it's really a generic wish.  I would expect many laptops to have 3 or 4 environments - home/standalone/other-network, with employer's network being the 4th.  This seems rather generic, to me.  Yet there's been so little to see.

One thing I see already in the first article is that this seems to wait until the user is logged in, which is too late for me.  For one instance, I want to start gdm with "-tcp nolisten" if I'm not at home or work.  For another, I want to start openafs and tweak /etc/pam.d to integrate the afs login if I'm at work.  Both of those obviously must happen prior to login.

The second reference looks much better - I'm surprised I found nothing of the sort looking at the network-manager pages, but I wasn't to happy with their information presentation, anyway.

----------

## depontius

 *Dagger wrote:*   

> I guess NM's dispatcher should be answer to your problem.
> 
> Quite old, but good starting point:
> 
> http://sysadminsjourney.com/content/2008/12/18/use-networkmanager-launch-scripts-based-network-location
> ...

 

So I tuck the start of my stuff in as "/etc/NetworkManager/dispatch.d/20-netAdapt" and give it a whilrl.  Now I find that when NetworkManager runs that stuff, the "ifconfig" command returns nothing.  If I go back on the command line and run my new script with the correct parameters manually, all is well.  I've added some extra instrumentation to the script and find that indeed the "ifconfig" command itself returns nothing at all - at this point in the network bringup process.  Is this a known characteristic of "ifconfig"?  I guess the "ip" (part of iproute2) command is the newer alternative.

Back after a pause...

Using the "ip" command doesn't work, either.  At this point in the bringup I don't know how to discover my IP address.  I guess I can kick off my script without an IP address, then put it into a sleep loop polling until it can get one.

Is there a cleaner way?

Does NetworkManager have a different hook, called at a different time?

----------

