10.6.3 Automatic network configuration using ifupdown
Interface names can be "mapped" to other names when ifup
runs. How names are mapped can be made to depend on circumstances. Thus
ifup
can be so configured that it brings up a given physical
interface as the appropriate logical interface among a set of predefined
alternatives.
Logical interface name mapping occurs as follows:
-
If no logical interface name is given on the ifup
command line
then the physical interface name is used as the initial logical interface name.
-
If the logical interface name matches the glob-pattern of a
mapping stanza then that mapping is applied to generate a new
logical interface name. This is done for each mapping stanza in turn.
-
If the final logical interface name is the label of a logical interface
definition in /etc/network/interfaces
then the physical interface
is brought up as that logical interface. Otherwise ifup
prints a
message that it is "Ignoring unknown interface" and exits.
The syntax of a mapping stanza is:
mapping glob-pattern
script script-name
[map script input]
The script named in the mapping stanza is always run with the
physical interface name as its argument and with the contents
of all following "map" lines in the stanza (without the word
"map" itself) provided to it on its standard input. The script
prints the result of the mapping on its standard output before exiting.
For example, the following mapping stanza will cause
ifup
to bring up interface eth0 as the
home logical interface.
mapping eth0
script /usr/local/sbin/echo-home
where /usr/local/sbin/echo-home
is:
#!/bin/sh
echo home
Because mapping is done with a script it is possible to select the logical
interface automatically — based on some sort of test. See Logical interface selection using
guessnet
, Section 10.6.3.1 for an example of this.
10.6.3.1 Logical interface selection using guessnet
Install guessnet
and then add a stanza like the following to
/etc/network/interfaces
:
mapping eth0
script guessnet-ifupdown
map home
map work
Now when you ifup eth0
, guessnet
will check whether
eth0 can be brought up as home or work.
To do this it uses information stored in the logical interface definitions.