Server Fault is a question and answer site for system and network administrators. It's 100% free, no registration required.

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

In freebsd when a cable gets plugged/unplugged the following lines are written to dmesg buffer:

em0: link state changed to DOWN em0: link state changed to UP

I would like to run a script when either happens but can't find anything exposing these state changes programmatically. Not even C APIs.

I see that ifconfig prints "status: no carrier" and "status: active" depending on whether a cable is connected. But I would prefer to avoid polling as 1) it burns CPU time which is important on a laptop and 2) it might miss changes if the polling interval is too long.

Is there any way to be notified when a cable is plugged and unplugged?

share|improve this question
up vote 3 down vote accepted

You'll probably want to check out /etc/devd.conf. devd is the primary way on FreeBSD of reacting to kernel/hardware events.

There's an example in there that shows how to match a network UP/DOWN event and run a task, as below, and the man page has some good information.

notify 0 {
    match "system"          "IFNET";
    match "type"            "LINK_UP";
    media-type              "ethernet";
    action "/etc/rc.d/dhclient quietstart $subsystem";

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.