Server Fault is a question and answer site for system and network administrators. Join them; it only takes a minute:

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

Hey, I'm trying to make a script run every time NetworkManager (or whatever, but that's what I'm talking to right now) connects to a network (or changes networks).

What I really want is, metaphorically, an init directory that fires everything inside of it whenever my wifi interface changes state/essid. Or a "network status changed" runlevel. Or something.

share|improve this question

You didn't say what distribution you're using, but on Debian derivatives (Ubuntu, etc.) you can specify scripts to be called at various points in the setup/teardown of an interface in its config stanza in /etc/network/interfaces. You can specify scripts to be called at each of these points:

  • pre-up
  • up
  • post-up
  • down
  • pre-down
  • post-down

You can also drop scripts into the directories named /etc/network/if-<stage>.d.

For more details, see man 5 interfaces.

share|improve this answer

NetworkManager has a script triggers directory called /etc/NetworkManager/dispatcher.d/. Do man NetworkManager to see how to use it.

share|improve this answer

Aside from the above suggestions, you could also set up an Upstart script that ran on the event wherein your network comes up.

share|improve this answer

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.