Stack Exchange Network

Stack Exchange network consists of 175 Q&A communities including Stack Overflow, the largest, most trusted online community for developers to learn, share their knowledge, and build their careers.

Visit Stack Exchange
    Bounty Ended with 50 reputation awarded by Chris Down
2 added clarification that the first sentence actually answers the question
source | link

Interface-specific {PRE,POST}_{UP,DOWN} commands can be defined in /etc/network.d/interfaces/$DEVICE, where $DEVICE is your network device name. So, although you need a hook per interface (which is actually what you indicate that you want), you do not need one per connection.

For example, my interfaces folder has the following files:

/etc/network.d/interfaces/_functions:

notify() {
dev="$1"
state="$2"
/usr/local/sbin/xuserrun /usr/local/sbin/network_notification "$dev" "$state"
return 0
}

/etc/network.d/interfaces/{wlan0,eth0} (both with same contents):

source /etc/network.d/interfaces/_functions
POST_UP="notify ${INTERFACE} up"
PRE_DOWN="notify ${INTERFACE} down"

This runs a script to send a pop-up notification telling me when a connection has been made/lost. Note that these hooks run as the root user. The xuserrun command is available on github and determines the current X username and switches to that user before running the subsequent command.

Interface-specific {PRE,POST}_{UP,DOWN} commands can be defined in /etc/network.d/interfaces/$DEVICE, where $DEVICE is your network device name.

For example, my interfaces folder has the following files:

/etc/network.d/interfaces/_functions:

notify() {
dev="$1"
state="$2"
/usr/local/sbin/xuserrun /usr/local/sbin/network_notification "$dev" "$state"
return 0
}

/etc/network.d/interfaces/{wlan0,eth0} (both with same contents):

source /etc/network.d/interfaces/_functions
POST_UP="notify ${INTERFACE} up"
PRE_DOWN="notify ${INTERFACE} down"

This runs a script to send a pop-up notification telling me when a connection has been made/lost. Note that these hooks run as the root user. The xuserrun command is available on github and determines the current X username and switches to that user before running the subsequent command.

Interface-specific {PRE,POST}_{UP,DOWN} commands can be defined in /etc/network.d/interfaces/$DEVICE, where $DEVICE is your network device name. So, although you need a hook per interface (which is actually what you indicate that you want), you do not need one per connection.

For example, my interfaces folder has the following files:

/etc/network.d/interfaces/_functions:

notify() {
dev="$1"
state="$2"
/usr/local/sbin/xuserrun /usr/local/sbin/network_notification "$dev" "$state"
return 0
}

/etc/network.d/interfaces/{wlan0,eth0} (both with same contents):

source /etc/network.d/interfaces/_functions
POST_UP="notify ${INTERFACE} up"
PRE_DOWN="notify ${INTERFACE} down"

This runs a script to send a pop-up notification telling me when a connection has been made/lost. Note that these hooks run as the root user. The xuserrun command is available on github and determines the current X username and switches to that user before running the subsequent command.

1
source | link

Interface-specific {PRE,POST}_{UP,DOWN} commands can be defined in /etc/network.d/interfaces/$DEVICE, where $DEVICE is your network device name.

For example, my interfaces folder has the following files:

/etc/network.d/interfaces/_functions:

notify() {
dev="$1"
state="$2"
/usr/local/sbin/xuserrun /usr/local/sbin/network_notification "$dev" "$state"
return 0
}

/etc/network.d/interfaces/{wlan0,eth0} (both with same contents):

source /etc/network.d/interfaces/_functions
POST_UP="notify ${INTERFACE} up"
PRE_DOWN="notify ${INTERFACE} down"

This runs a script to send a pop-up notification telling me when a connection has been made/lost. Note that these hooks run as the root user. The xuserrun command is available on github and determines the current X username and switches to that user before running the subsequent command.