Take the 2-minute tour ×
Server Fault is a question and answer site for system and network administrators. It's 100% free, no registration required.

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

3 Answers 3

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

 
discard

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.