Watch for addresses added to or deleted from interfaces and call up/down-scripts for them
ifwatchd [-hiqv] [-A arrival-script] [-c carrier-script] [-D departure-script] [-d down-script] [-n no-carrier-script] [-u up-script] ifname(s)
Since ifwatchd typically is started late in the system boot sequence, some of the monitored interfaces may already have come up when it finally starts, but their up-scripts haven't been called. By default, ifwatchd calls them on startup to account for this (and make the scripts easier.)
The ifwatchd utility is used to monitor dynamic interfaces (for example PPP interfaces) for address changes, and to monitor static interfaces for carrier changes. Sometimes these interfaces are accompanied by a daemon program, which can take care of running any necessary scripts (such as pppd or isdnd), but sometimes the interfaces run completely autonomously (such as pppoe).
The ifwatchd utility provides a generic way to watch these types of changes. It works by monitoring the routing socket and interpreting RTM_NEWADDR (address added), RTM_DELADDR (address deleted) and RTM_IFINFO (carrier detect or loss of carrier) messages. It doesn't need special privileges to do this. The scripts called for up or down events are run with the same user ID as for ifwatchd.
# ifwatchd -u /etc/ppp/ip-up -d /etc/ppp/ip-down pppoe0
If your pppoe0 interface is your main connection to the Internet, the typical use of the up/down scripts is to add and remove a default route. This is an example of an up script that does this:
#! /bin/sh /sbin/route add default $5
As described below, the fifth command line parameter contains the peer address of the pppoe link. The corresponding ip-down script is:
#! /bin/sh /sbin/route delete default $5
|This isn't a good idea if you have pppoe0
configured to connect only on demand (via the link1 flag), but works
well for all permanent connected cases.
! /sbin/route add default -iface 0.0.0.1
in your /etc/ifconfig.pppoe0 file in the on-demand case.