IFWATCHD(8) | System Manager's Manual | IFWATCHD(8) |
ifwatchd
—
ifwatchd |
[-hiqv ] [-A
arrival-script] [-c
carrier-script] [-D
departure-script] [-d
down-script] [-u
up-script] [-n
no-carrier-script]
ifname(s) |
ifwatchd
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 (like
pppd(8)), but sometimes the
interfaces run completely autonomously (like
pppoe(4)).
ifwatchd
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 does not need special privileges to
do this. The scripts called for up or down events are run with the same user
id as ifwatchd
is run.
The following options are available:
-A
arrival-script-c
carrier-script-D
departure-script-d
down-script-h
-i
ifwatchd
will check all watched interfaces on
startup whether they are already marked up and, if they are, call the
up-script with appropriate parameters. Additionally, if the interface is
up and has a link, ifwatchd
will run the carrier
script.
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 have not been called. By default
ifwatchd
calls them on startup to account for
this (and make the scripts easier.)
-n
no-carrier-script-q
-u
up-script-v
# 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 for an up script doing this:
#! /bin/sh /sbin/route add default $5 /sbin/route add -inet6 default fe80::2 -iface ifp $1
As described below the fifth command line parameter will contain the peer address of the pppoe link. The corresponding ip-down script is:
#! /bin/sh /sbin/route delete default $5 /sbin/route delete -inet6 default fe80::2
Note that this is not 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. Use
! /sbin/route add default -iface 0.0.0.1
in your /etc/ifconfig.pppoe0 file in the on-demand case.
The format of the address depends on the address family, for IPv4 it is the usual dotted quad notation, for IPv6 the colon separated standard notation.
-v
(verbose) option.
ifwatchd
utility appeared in NetBSD
1.6.
February 17, 2019 | NetBSD 9.4 |