Differences between revisions 120 and 121
Revision 120 as of 2008-03-02 13:19:13
Size: 43309
Editor: OsamuAoki
Comment:
Revision 121 as of 2008-03-02 15:10:08
Size: 43544
Editor: OsamuAoki
Comment:
Deletions are marked like this. Additions are marked like this.
Line 90: Line 90:
|| {{{guessnet}}} || 112 || - || , , || Helper script to enhance "{{{ifupdown}}}" package via {{{/etc/network/interfaces}}} file ||
Line 92: Line 91:
|| {{{guessnet}}} || 112 || - || , , || Mapping script to enhance "{{{ifupdown}}}" package via {{{/etc/network/interfaces}}} file ||
Line 638: Line 638:
In adition to the {{{guessnet}}} package, the {{{ifscheme}}} and {{{ifupdown-scripts-zg2}}} packages also enhance {{{ifupdown}}} package with scripts. All these require intensive work and there are some overlap of functinalities.

Do not use Edit(GUI) button.

?TableOfContents(4)

Copyright 2007 Osamu Aoki GPL, (Please agree to GPL, GPL2, and any version of GPL which is compatible with DSFG if you update any part of wiki page)

The network

This section will address network setup for the mobile PC which moves around different networks. (For the non-mobile PC, the debian-installer should have taken care your network setup and there are almost nothing for us to play with.)

You should install the resolvconf package for the mobile PC. This package provides framework to solve conflicts of the host address resolution between different network configuration scripts when network configuration changes. Read more on /usr/share/doc/resolvconf/README.Debian.

For the fixed location server machine, you can do without the resolvconf package and keep your system simple.

In this document, we focus on Debian-specific issues. For a general guide to GNU/Linux networking, read the [http://www.tldp.org/LDP/nag2/ Linux Network Administrators Guide].

The basic network infrastructures

Let's review the basic network infrastructure of the modern Debian system.

The domain name

The naming for the domain name is a tricky one for the normal workstation PC users. The PC workstation may be mobile one hopping around the network or located behind the NAT firewall inaccessible from the Internet. For such case, you do not want the domain name to be a valid domain name to avoid name collision.

According to [http://tools.ietf.org/html/rfc2606 rfc2606], "invalid" seems to be a choice for the top level domain (TLD) to construct domain names that are sure to be invalid from the Internet.

The [http://en.wikipedia.org/wiki/MDNS mDNS] network discovery protocol ([http://en.wikipedia.org/wiki/Bonjour_(software) Apple Bonjour / Apple Rendezvous], Avahi on Debian) uses [http://en.wikipedia.org/wiki/.local "local"] as the [http://en.wikipedia.org/wiki/Pseudo-top-level_domain pseudo-top-level domain]. [http://support.microsoft.com/kb/296250 Microsoft also seem to promote "local" for the TLD of local area network].

Other popular choices for the invalid TLD seem to be "localdomain", "lan", "localnet", or "home" according to my incoming mail analysis.

The host name resolution

The host name resolution is currently supported by the NSS (Name Service Switch) mechanism too. The flow of this resolution is:

  1. The /etc/nsswitch.conf file with stanza like "hosts: files dns" dictates the host name resolution order. (This replaces the old functionality of the "order" stanza in /etc/host.conf.)

  2. The files method is invoked first. If the host name is found in the /etc/hosts file, it returns all valid addresses for it and exits. (The /etc/host.conf file contains "multi on".)

  3. The dns method is invoked. If the host name is found by the query to the Internet Domain Name System (DNS) identified by the /etc/resolv.conf file, it returns all valid addresses for it and exits.

The /etc/hosts file [http://bugs.debian.org/316099 associates IP addresses with hostnames]:

127.0.0.1 localhost
127.0.1.1 <host_name>.<domain_name> <host_name>

# The following lines are desirable for IPv6 capable hosts
::1     ip6-localhost ip6-loopback
fe00::0 ip6-localnet
ff00::0 ip6-mcastprefix
ff02::1 ip6-allnodes
ff02::2 ip6-allrouters
ff02::3 ip6-allhosts

Here the <host_name> in this configuration matches the PC's own host name defined in the /etc/hostname. I tend to use bogus domain name for <domain_name>, such as "invalid" in this configuration for the mobile PC.

The /etc/resolv.conf is a static file if the resolvconf package is not installed. If installed, it is a symbolic link. Either way, it contains information that initialize the resolver routines. If the DNS is found at IP="192.168.11.1", it contains:

nameserver 192.168.11.1

The host name resolution via Multicast DNS (using [http://en.wikipedia.org/wiki/Zeroconf Zeroconf], aka [http://en.wikipedia.org/wiki/Bonjour_(software) Apple Bonjour / Apple Rendezvous]) which effectively allows name resolution by common Unix/Linux programs in the ad-hoc mDNS domain "local", can be provided by installing the libnss-mdns package. The /etc/nsswitch.conf file should have stanza like "hosts: files mdns4_minimal [NOTFOUND=return] dns mdns4" to enable this functionality.

The network interface name

The network interface name, e.g. eth0, is assigned to each hardware in the Linux kernel through the user space configuration mechanism, udev (see: @{@theudevsystem@}@), as it is found. The network interface name is referred as physical interface in the manpage of ifup(8) and interfaces(5).

In order to ensure each network interface to be named persistently for each reboot using MAC address etc., there is a record file "/etc/udev/rules.d/z25_persistent-net.rules". This file is automatically generated by the "/lib/udev/write_net_rules" program, probably run by the "persistent-net-generator.rules" rules file. You can modify it to change naming rule.

<!> When editing the "persistent-net-generator.rules" rules file, you must keep each rule on a single line and the MAC address in lowercase. For example, if you find "Firewire device" and "PCI device" in this file, you probably want to name "PCI device" as eth0 and configure it as the primary network interface.

The network address range for the LAN

Let us be reminded of the IPv4 32 bit address ranges in each class reserved for use on the local area networks (LANs) by [http://tools.ietf.org/html/rfc1918 rfc1918]. These addresses are guaranteed not to conflict with any addresses on the Internet proper.

List of network address ranges.

Class

network addresses

net mask

net mask /bits

# of subnets

A

10.x.x.x

255.0.0.0

/8

1

B

172.16.x.x -- 172.31.x.x

255.255.0.0

/16

16

C

192.168.0.x -- 192.168.255.x

255.255.255.0

/24

256

(!) If one of these addresses is assigned to a host, then that host must not access the Internet directly but must access it through a gateway that acts as a proxy for individual services or else does Network Address Translation(NAT). The broadband router usually performs NAT for the consumer LAN environment.

The network configuration infrastructure

The network configuration tools can be classified into several levels.

List of network configuration tools.

1

2

3

packages

popcon

size

level

function

ifplugd

571

-

Higher

Manage the wired network automatically

waproamd

141

-

, ,

Manage the wireless network automatically

network-manager

14064

-

, ,

Manage the network with GUI

ifupdown

35032

-

Middle

Standardized level to bring up and down the network

ifupdown-extra

--

-

, ,

Network testing script to enhance "ifupdown" package

guessnet

112

-

, ,

Mapping script to enhance "ifupdown" package via /etc/network/interfaces file

ifscheme

--

-

, ,

Mapping scripts to enhance "ifupdown" package

ifupdown-scripts-zg2

--

-

, ,

Zugschlus' interface scripts for ifupdown's manual method

iptables

-

-

Lower

Administration tools for packet filtering and NAT

net-tools

36300

-

, ,

The NET-3 networking toolkit (IPv4 network configuration)

iproute

19172

-

, ,

IPv6 and other advanced network configuration

dhcp3-client

20532

-

, ,

DHCP client

wpasupplicant

-

-

, ,

Client support for WPA and WPA2 (IEEE 802.11i)

wireless-tools

-

-

, ,

Tools for manipulating Linux Wireless Extensions

ppp

4638

-

, ,

PPP/PPPoE connection with chat

pppoeconf

566

-

, ,

Configuration helper for PPPoE connection

pppconfig

559

-

, ,

Configuration helper for plain PPP connection with chat

wvdial

224

-

, ,

PPP connection with wvdial with ppp, configuration helper

iputils-ping

-

-

Test

Tools to test the reachability of network hosts

traceroute

-

-

, ,

Traces the route taken by packets over an IPv4/IPv6 network

dnsutils

-

-

, ,

Network clients provided with BIND

dlint

-

-

, ,

Checks dns zone information using nameserver lookups

In this document, we focus on managing the network using middle level tools, i.e. the ifupdown package while supplementing it with useful lower level tools. ifupdown is the standard way to manage network interfaces in Debian.

The network device support

Although most hardware devices are supported by the Debian system, there are some network devices which require [http://www.debian.org/social_contract#guidelines DSFG] non-free external hardware drivers to support them. Please see @{@thenonfreehardwaredrivers@}@.

The network connection method

The typical network connection method and connection path for a PC can be summarized as:

List of network connection types and connection paths.

PC

connection method

connection path

Serial port (ppp0)

PPP

<=> [http://en.wikipedia.org/wiki/Modem modem] <=> POTS <=> dial-up access point <=> ISP

Ethernet port (eth0)

PPPoE/DHCP/Static

<=> BB-modem <=> BB service <=> BB access point <=> ISP

Ethernet port (eth0)

DHCP/Static

<=> LAN <=> BB-router (<=> BB-modem ...)

Here is the summary of configuration script for each connection method:

List of network connection configurations.

connection method

configuration

backend package(s)

PPP

pppconfig to create deterministic chat

pppconfig, ppp

PPP (alternative)

wvdialconf to create heuristic chat

ppp, wvdial

PPPoE

pppoeconf to create deterministic chat

pppoeconf, ppp

DHCP

described in /etc/dhcp3/dhclient.conf

dhcp3-client

static IP (IPv4)

described in /etc/network/interfaces

net-tools

static IP (IPv6)

described in /etc/network/interfaces

iproute

The network connection acronyms mean:

List of network connection acronyms.

acronym

meaning

[http://en.wikipedia.org/wiki/Plain_old_telephone_service POTS]

The plain old telephone service

BB

The [http://en.wikipedia.org/wiki/Broadband broadband]

BB-service

E.g., the digital subscriber line (DSL), the cable TV, or the fiber to the premises (FTTP).

BB-modem

E.g., [http://en.wikipedia.org/wiki/DSL_modem the DSL modem], [http://en.wikipedia.org/wiki/Cable_modem the cable modem], or [http://en.wikipedia.org/wiki/FTTP the optical network terminal (ONT)].

[http://en.wikipedia.org/wiki/LAN LAN]

The local area network

[http://en.wikipedia.org/wiki/DHCP DHCP]

The dynamic host configuration protocol

[http://en.wikipedia.org/wiki/Point-to-Point_Protocol PPP]

The point-to-point protocol

[http://en.wikipedia.org/wiki/Pppoe PPPoE]

The point-to-point protocol over Ethernet

[http://en.wikipedia.org/wiki/ISP ISP]

The Internet service provider

<!> The connection test method described in this section are not meant to be used directly for the daily network connection. You are advised to use them via the ifupdown package (see @{@thebasicnetworkctionwithifupdown@}@).

The DHCP connection with the Ethernet

The typical modern home and small business network, i.e. LAN, are connected to the WAN(Internet) using some consumer grade broadband router. The LAN behind this router is usually served by the [http://en.wikipedia.org/wiki/Dynamic_Host_Configuration_Protocol dynamic host configuration protocol (DHCP)] server running on the router.

Just install the dhcp3-client package for the Ethernet served by the [http://en.wikipedia.org/wiki/Dynamic_Host_Configuration_Protocol dynamic host configuration protocol (DHCP)].

The static IP connection with the Ethernet

No special action is needed for the Ethernet served by the static IP.

The PPP connection with pppconfig

The configuration script pppconfig will configure the PPP connection interactively just by selecting:

  • the telephone number,
  • the ISP user name,
  • the ISP password,
  • the port speed,
  • the modem communication port, and
  • the authentication method.

The configuration files are:

List of configuration files for the PPP connection with pppconfig.

file

function

/etc/ppp/peers/<isp_name>

The pppconfig generated configuration file for pppd specific to <isp_name>

/etc/chatscripts/<isp_name>

The pppconfig generated configuration file for chat specific to <isp_name>

/etc/ppp/options

The general execution parameter for pppd

/etc/ppp/pap-secret

Authentication data for the PAP (still used)

/etc/ppp/chap-secret

Authentication data for the CHAP (more secure)

<!> The "<isp_name>" value of "provider" is assumed if pon and poff commands are invoked without arguments.

You can test configuration using lower level network configuration tools:

$ sudo pon <isp_name>
...
$ sudo poff <isp_name>

See /usr/share/doc/ppp/README.Debian.gz for more information.

The alternative PPP connection with wvdialconf

A different approach to using pppd is to run it from wvdial which comes in the wvdial package. Instead of pppd running chat to dial in and negotiate the connection, wvdial does the dialing and initial negotiating and then starts pppd to do the rest.

The configuration script wvdialconf will configure the PPP connection interactively just by selecting:

  • the telephone number,
  • the ISP user name, and
  • the ISP password.

The wvdial succeeds in making the connection in most cases and maintains authentication data list automatically.

The configuration files are:

List of configuration files for the PPP connection with wvdialconf.

file

function

/etc/ppp/peers/wvdial

The wvdialconf generated configuration file for pppd specific to wvdial

/etc/wvdial.conf

The wvdialconf generated configuration file

/etc/ppp/options

The general execution parameter for pppd

/etc/ppp/pap-secret

Authentication data for the PAP (still used)

/etc/ppp/chap-secret

Authentication data for the CHAP (more secure)

You can test configuration using lower level network configuration tools:

$ sudo wvdial
...
$ sudo killall wvdial

See manpages of wvdial(1), wvdial.conf(5) for more information.

The PPPoE connection with pppoeconf

When your ISP serves you with PPPoE connection and you decide to connect your PC directly to the WAN, the network of your PC must be configured with the PPPoE. The PPPoE stand for PPP over Ethernet. The configuration script pppoeconf will configure the PPPoE connection interactively.

The configuration files are:

List of configuration files for the PPPoE connection with pppoeconf.

file

function

/etc/ppp/peers/dsl-provider

The pppoeconf generated configuration file for pppd specific to pppoe

/etc/ppp/options

The general execution parameter for pppd

/etc/ppp/pap-secret

Authentication data for the PAP (still used)

/etc/ppp/chap-secret

Authentication data for the CHAP (more secure)

You can test configuration using lower level network configuration tools:

$ sudo pon dsl-provider
...
$ sudo poff dsl-provider

See /usr/share/doc/pppoeconf/README.Debian for more information.

The basic network configuration with ifupdown

The ifupdown package provides standardized middle level for the network configuration in the Debian system. In this section, we learn the basic network configuration with ifupdown with simplified introduction and many typical examples.

The command syntax simplified

The ifupdown package offers basic commands for network configuration.

List of basic network configuration commands with ifupdown.

command

action

ifup eth0

To bring up a network interface eth0 with the configuration eth0 if "iface eth0" stanza exists.

ifdown eth0

To bring down a network interface eth0 with the configuration eth0 if "iface eth0" stanza exists.

The configuration file /etc/network/interfaces (/e/n/i as its acronym in the following text) dictates the actual behavior of above commands.

The basic syntax of /etc/network/interfaces

The key syntax of /e/n/i as explained in the manpage interfaces(5) can be summarized as:

List of stanzas in /e/n/i

stanza

meaning

"auto <interface_name>"

To start interface <interface_name> upon start of the system.

"allow-auto <interface_name>"

, ,

"allow-hotplug <interface_name>"

To start interface <interface_name> when the kernel detects a hotplug event from the interface.

Lines started with "iface <config_name> ..."

To define the network configuration <config_name>.

Lines started with "mapping <interface_name_glob> "

To define mapping value of <config_name> for the matching <interface_name>.

A line starting with a hash "#"

To be ignored as comments. (end-of-line comments are not supported)

A line ending with a backslash "\"

To extend the configuration to the next line.

Lines started with "iface" stanza has the following syntax:

iface <config_name> <address_family> <method_name>
 <option1> <value1>
 <option2> <value2>
 ...

For the basic configuration, the "mapping" stanza is not used and you use the network interface name as the network configuration name. (See @{@themappingstanza@}@).

The loopback network interface

The following configuration entry in the /e/n/i file brings up the loopback network interface lo upon booting the system (via auto stanza).

auto lo
iface lo inet loopback

The network interface served by the DHCP

After prepairing the system by @{@thedhcpconnectionwiththeethernet@}@, the network interface served by the DHCP is configured by creating the configuration entry in the /e/n/i file as:

allow-hotplug eth0
iface eth0 inet dhcp

When the Linux kernel detects the physical interface eth0, the allow-hotplug stanza will cause ifup to bring up the interface and the iface stanza will cause ifup to use DHCP to configure the interface.

The network interface with the static IP

The network interface served by the static IP is configured by creating the configuration entry in the /e/n/i file as, e.g.,:

allow-hotplug eth0
iface eth0 inet static
 address 192.168.11.100
 netmask 255.255.255.0
 broadcast 192.168.11.255
 gateway 192.168.11.1
 dns-domain lan
 dns-nameservers 192.168.11.1

When the Linux kernel detects the physical interface eth0, the allow-hotplug stanza will cause ifup to bring up the interface and the iface stanza will cause ifup to use the static IP to configure the interface.

Here, I assumed:

  • IP address range of the LAN network: 192.168.11.0 - 192.168.11.255

  • IP address of the gateway: 192.168.11.1

  • IP address of the PC: 192.168.11.100

  • The resolvconf package is installed.

  • The domain name as "lan".

  • The DNS server at: 192.168.11.1

When the resolvconf package is not installed, DNS related configuration needs to be done manually by editing the /etc/resolv.conf as:

nameserver 192.168.11.1 
domain lan

<!> The IP addresses used in the above example are not meant to be copied literally. You have to adjust IP numbers to your actual network configuration.

The basics of wireless LAN interface

The [http://en.wikipedia.org/wiki/Wireless_LAN wireless LAN (WLAN for short)] provides the fast wireless connectivity through the spread-spectrum communication of unlicensed radio bands based on the set of standards called [http://en.wikipedia.org/wiki/IEEE_802.11 IEEE 802.11].

The WLAN interfaces are almost like normal Ethernet interfaces but require some network ID and encryption key data to be provided when they are initialized. The higher level network tools are exactly the same as the Ethernet except the interface names are a bit different like ath0, wlan0, ath0, wifi0, ... depending on the kernel drivers used.

Here are some keywords to remember for the WLAN:

List of acronyms for WLAN.

acronym

full word

meaning

NWID

Network ID

The 16 bit network ID used by pre-802.11 network. Very much deprecated.

(E)SSID

(Extended) [http://en.wikipedia.org/wiki/Service_set_identifier Service Set Identifier]

The network name of the [http://en.wikipedia.org/wiki/Wireless_access_point Wireless Access Points (APs)] interconnected to form an integrated [http://en.wikipedia.org/wiki/IEEE_802.11 802.11 wireless LAN]. Domain ID.

WEP, (WEP2)

[http://en.wikipedia.org/wiki/Wired_Equivalent_Privacy Wired Equivalent Privacy]

The 1st generation 64-bit (128-bit) wireless encryption standard with 40-bit key. Deprecated.

WPA

[http://en.wikipedia.org/wiki/Wi-Fi_Protected_Access Wi-Fi Protected Access]

The 2nd generation wireless encryption standard (most of 802.11i), compatible with WEP.

WPA2

[http://en.wikipedia.org/wiki/IEEE_802.11i Wi-Fi Protected Access 2]

The 3rd generation wireless encryption standard (full 802.11i), non-compatible with WEP.

The actual choice of protocol is usually limited by the wireless router you deploy.

The wireless LAN interface with the WEP

You need to install the wireless-tools package to support the WLAN with the old WEP. (Your consumer grade router may still be using. Insecure infrastructure but better than nothing.)

<!> Please note that your network traffic on WLAN may be sniffed by others.

In case of the [http://en.wikipedia.org/wiki/Dynamic_Host_Configuration_Protocol DHCP] served IP on WLAN connection, the /e/n/i file entry should be:

allow-hotplug eth0
iface eth0 inet dhcp
 wireless-essid Home
 wireless-key1 0123-4567-89ab-cdef
 wireless-key2 12345678
 wireless-key3 s:password
 wireless-defaultkey 2
 wireless-keymode open

See more on /usr/share/doc/wireless-tools/README.Debian.

The wireless LAN interface with the WAP/WAP2

You need to install the wpasupplicant package to support the WLAN with the new WAP/WAP2.

In case of the DHCP served IP on WLAN connection provided by the the madwifi driver backend, the /e/n/i file entry should be:

allow-hotplug ath0
iface ath0 inet dhcp
 wpa-driver madwifi
 wpa-ssid homezone
 # hexadecimal psk is encoded from a plaintext passphrase
 wpa-psk 000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f

See more on /usr/share/doc/wpasupplicant/README.modes.gz.

The PPP connection

You need to configure the PPP connection first as described before. Then, add the /e/n/i file entry for the primary PPP device ppp0 as:

iface ppp0 inet ppp
 provider <isp_name>

The alternative PPP connection

You need to configure the alternative PPP connection with wvdial first as described before. Then, add the /e/n/i file entry for the primary PPP device ppp0 as:

iface ppp0 inet wvdial

The PPPoE connection

You need to configure the PPPoE connection first as described before. Then, add the /e/n/i file entry for the primary PPPoE device eth0 as:

allow-hotplug eth0
iface eth0 inet ppp
 provider dsl-provider

The network configuration state of ifupdown

The /etc/network/run/ifstate file stores the intended network configuration states for all the currently active network interfaces managed by the ifupdown package are listed. Unfortunately, even if the ifupdown system fails to bring up the interface as intended, the /etc/network/run/ifstate file lists it active.

The output of the ifconfig(8) command without any arguments or with the interface name as its argument provides the actual network configuration state. If the interface does not have the second line as:

          inet addr:192.168.11.2  Bcast:192.168.11.255  Mask:255.255.255.0

it can not be used as a part of [http://en.wikipedia.org/wiki/IPv4 IPV4 network].

(!) For the Ethernet device connected to the PPPoE, the output of the ifconfig(8) command lacks above line.

The basic network reconfiguration

When you try to reconfigure the interface, e.g. eth0, you must disable it first with the "sudo ifdown eth0" command. This will remove the entry of eth0 from the /etc/network/run/ifstate file. (This may result in some error message if eth0 is not active or it is configured improperly previously. So far, it seems to be safe to do this for the simple single user work station at any time.)

You are now free to rewrite the /e/n/i contents as needed to reconfigure the network interface, eth0.

Then, you can reactivate eth0 with the "sudo ifup eth0" command.

{i} You can (re)initialize the network interface simply by "sudo ifdown eth0;sudo ifup eth0".

The ifupdown-extra package

The ifupdown-extra package provides the easy network connection test for use with the ifupdown package:

  • the network-test(1) command from the shell, and

  • the automatic scripts run for each ifup command execution.

The network-test command frees you from the execution of cumbersome low level commands to analyze the network problem.

The automatic scripts are installed in /etc/network/*/ and:

  • check the network cable connection,
  • check duplicate use of IP address,
  • setup system's static routes based on the /etc/network/routes definition,

  • check if network gateway is reachable, and
  • record results in the /var/log/syslog file.

This syslog record is quite useful for administration of the network problem on the remote system.

{i} The automatic behavior of the ifupdown-extra package is configurable with the /etc/default/network-test . Some of these automatic checks slow down the system bootup a little bit since it takes some time to listen for [http://en.wikipedia.org/wiki/Address_Resolution_Protocol ARP] replies.

The advanced network configuration with ifupdown

The functionality of the ifupdown package can be improved beyond what was described in @{@thebasicnetworkctionwithifupdown@}@ with the advanced knowledge. The functionality described here is completely optional.

The advanced command syntax

The ifupdown package offers advanced network configuration using the network configuration name and the network interface name. I use slightly different terminology from one used in the manpage of ifup(8) and interfaces(5).

List of terminology for network devices.

manpage terminology

my terminology

explanation

examples in the following text

physical interface name

network interface name

A name given by the Linux kernel (using udev mechanism).

lo, eth0, <interface_name>

logical interface name

network configuration name

A name token following iface in the /e/n/i.

config1, config2, <config_name>

Basic network configuration commands in @{@thebasicsyntaxofetworkinterfaces@}@ require network configuration name token of iface stanza matching the network interface name in the /e/n/i.

Advanced network configuration commands enables separation of the network configuration name and the network interface name in the /e/n/i:

List of advanced network configuration commands with ifupdown.

command

action

ifup eth0=config1

To bring up a network interface eth0 with the configuration config1.

ifdown eth0=config1

To bring down a network interface eth0 with the configuration config1.

ifup eth0

To bring up a network interface eth0 with the configuration selected by mapping stanza.

ifdown eth0

To bring down a network interface eth0 with the configuration selected by mapping stanza.

The mapping stanza

We skipped explaining the "mapping" stanza in the /e/n/i in @{@thebasicsyntaxofetworkinterfaces@}@ to avoid complication. This stanza has the following syntax:

mapping <interface_name_glob>
 script <script_name>
 map <script_input1>
 map <script_input2>
 map ...

This provids advanced feature to the /e/n/i file by automating the choice of the configuration with the mapping script specified by <script_name>.

When the "<interface_name_glob>" matches "eth0", the execution of

$ sudo ifup eth0

will produce the execution of:

$ sudo ifup eth0=$(echo -e '<script_input1> \n <script_input2> \n ...' | <script_name> eth0)

to configure eth0 automatically. Here, lines with "map" are optional and can be repeated.

(!) The glob for mapping stanza works like shell file name glob.

The manually switchable network configuration

Here is how to switch manually among several network configurations without rewriting the /e/n/i file as in @{@thebasicnetworkreconfiguration@}@ .

For all the network configuration you need to access, you create a single /e/n/i file, e.g,:

auto lo
iface lo inet loopback

iface config1 inet dhcp

iface config2 inet static
 address 192.168.11.100
 netmask 255.255.255.0
 broadcast 192.168.11.255
 gateway 192.168.11.1
 dns-domain lan
 dns-nameservers 192.168.11.1

iface pppoe inet ppp
 provider dsl-provider

iface pots inet ppp
 provider provider

Please note the network configuration name which is the token after iface does not use the token for the network interface name. Also, there are no auto stanza nor allow-hotplug stanza to start the network interface eth0 automatically upon events.

Now you are ready to switch the network configuration.

Let's move your PC to a LAN served by the DHCP. You bring up the network interface (the physical interface) eth0 by assigning the network configuration name (the logical interface name) config1 to it:

$ sudo ifup eth0=config1
Password:
...

The interface eth0 is up, configured by DHCP and connected to LAN.

$ sudo ifdown eth0=config1
...

The interface eth0 is down and disconnected from LAN.

Let's move your PC to a LAN served by the static IP. You bring up the network interface eth0 by assigning the network configuration name config2 to it:

$ sudo ifup eth0=config2
...

The interface eth0 is up, configured with static IP and connected to LAN. The additional parameters given as dns-* configures /etc/resolv.conf contents. This /etc/resolv.conf is better maneged if the resolvconf package is installed.

$ sudo ifdown eth0=config2
...

The interface eth0 is down and disconnected from LAN, again.

Let's move your PC directly connected to BB-modem connected to the PPPoE served service. You bring up the network interface eth0 by assigning the network configuration name pppoe to it:

$ sudo ifup eth0=pppoe
...

The interface eth0 is up, configured with PPPoE connection directly to the ISP.

$ sudo ifdown eth0=pppoe
...

The interface eth0 is down and disconnected, again.

Let's move your PC to a location without LAN or BB-modem but with POTS and modem. You bring up the network interface ppp0 by assigning the network configuration name pots to it:

$ sudo ifup ppp0=pots
...

The interface ppp0 is up and connected to the Internet with PPP.

$ sudo ifdown ppp0=pots
...

The interface ppp0 is down and disconnected from the Internet.

You should chack the /etc/network/run/ifstate file for the current network configuration state of the ifupdown system.

The ifplugd

The ifupdown package normally starts the network interface triggered by the auto stanza or allow-hotplug stanza which starts the interface upon system boot or upon their device discovery by the kernel. If the interface, e.g. eth0, has some issues such as the case when the wire to the Ethernet port is unplugged while device is activated, there is a long DHCP timeout delay when the DHCP is used and the interface becomes activated without the proper IPv4 address confirmed with the ifconfig(8) command without any arguments (see @{@thenetworkconfignstateofifupdown@}@).

This situation can be improved by installing the ifplugd package to replace the auto or allow-hotplug functionarities of the ifupdown package. The ifplugd package starts interfaces upon their connection to the network.

Here is how to use the ifplugd package for the internal Ethernet port, e.g. eth0:

  • Remove stanza in /e/n/i: "auto eth0" and "allow-hotplug eth0",

  • Keep stanza in /e/n/i: "iface eth0 inet ..." and "mapping ...",

  • Install the ifplugd package,

  • Run "sudo dpkg-reconfigure ifplugd", and

  • Put eth0 as the "static interfaces to be watched by ifplugd".

Now, the network reconfiguration works as you desire:

  • At boot time, the interface is not brought up by itself.
  • Upon finding the Ethernet cable, the interface is brought up.
  • Some time after you make the Ethernet cable unplugged, the interface is brought down automatically.
  • Upon plugging in another Ethernet cable, the interface will be brought up under the new network environment.

{i} The arguments for the ifplugd(8) command can set its behaviors such as the delay for reconfiguring interfaces.

{i} For the wireless LAN where the WEP key configuration before AP associations is required, you should check the waproamd package instead of the ifplugd package.

Scripting with the ifupdown

The ifupdown system automatically runs scripts installed in /etc/network/*/ while exporting environment variables to the scripts:

List of environment variables passed by the ifupdown system

environment variable

value passed

IFACE

physical name (interface name) of the interface being processed.

LOGICAL

logical name (configuration name) of the interface being processed.

ADDRFAM

address family of the interface.

METHOD

method of the interface. (e.g., "static")

MODE

"start" if run from ifup, "stop" if run from ifdown.

PHASE

as per MODE, but with finer granularity, distinguishing the pre-up, post-up, pre-down and post-down phases.

VERBOSITY

indicates whether "--verbose" was used; set to 1 if so, 0 if not.

PATH

the command search path: /usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin

IF_<OPTION>

the value for the corresponding sub-stanza of the iface stanza.

Here, the environment variable names, IF_<OPTION>, are created from the sub-stanza strings by prepending "IF_", converting the case to the upper case, replacing hyphens to underscores, and discarding non-alphanumeric characters.

The mapping with guessnet

Instead of manually chosing configuration as described in @{@themanuallyswitcorkconfiguration@}@, you can use the mapping mechanism described in @{@themappingstanza@}@ to select network configuration automatically by the custom scripting.

The guessnet-ifupdown(8) command provided by the guessnet package is designed to be used as the mapping script and provides powerful framework to enhance the ifupdown system.

  • you list test condition as test-* sub-stanza for each network configuration under iface stanza.

  • mapping will chose the iface with first non-ERROR result as the network configuration.

This dual usage of the /e/n/i file by the mapping script, guessnet-ifupdown, does not cause negative impacts to the ifupdown system since test-* sub-stanzas only export extra environment variables to the scripts run by the ifupdown system. See details in guessnet-ifupdown(8).

In adition to the guessnet package, the ifscheme and ifupdown-scripts-zg2 packages also enhance ifupdown package with scripts. All these require intensive work and there are some overlap of functinalities.

The compatible lower level network operations

You may use the lower level network commands as follows anytime since they do not change network configuration:

List of lower level network commands.

command

effects

"ifconfig" without arguments

displays the status of active interfaces (IPv4)

"route -n"

display all the routing table in numerical addresses (IPv4)

"ip link show"

displays the link status of active interfaces (IPv4/v6)

"ip addr show"

displays the link and address status of active interfaces (IPv4/v6)

"ip route show"

displays the routing table (IPv4/v6)

"plog"

display ppp daemon log

"ping yahoo.com"

check Internet connection to yahoo.com

"traceroute yahoo.com"

trace Internet connection to yahoo.com

"dig [@dns-server.com] example.com [{a|mx|any}]"

check example.com DNS records by dns-server.com for a {a|mx|any} record

"iptables -L -n"

check packet filter

"netstat -a"

find all open ports

"netstat -l --inet"

find listening ports

"netstat -ln --tcp"

find listening TCP ports (numeric)

"dlint example.com"

check dns zone information of examle.org

{i} Some of these lower level network configuration tools reside in /sbin/. You may need to issue full command path such as /sbin/ifconfig or add /sbin to the PATH list in your ~/.basrc.

The screen program

The screen program (popcon: @@@pop-screen@@@) enables remote shell process to survive the interrupted connection. This is the essential tool for people to access remote sites via the unreliable connection.

The use scenario for the screen command

Here is a typical use scenario of the screen program.

  1. You log in to a remote machine.
  2. You execute the "screen" command on a single console.

  3. You execute multiple programs in the screen windows created with ^A c ("Control-A" followed by "c").

  4. You switch among the multiple screen windows by ^A n ("Control-A" followed by "n").

  5. Suddenly you need to leave your terminal, but you don't want to lose your active work by keeping the connection.
  6. You detach the screen session by any methods such as:

    • brutally unplugging your network connection,
    • typing ^A d ("Control-A" followed by "d") and manually logging out from the remote connection, or

    • typing ^A DD ("Control-A" followed by "DD") to have screen detach and log you out.

  7. You log in again to the same remote machine (even from a different terminal).
  8. You enter the "screen -r" command.

  9. The screen program will magically reattach all the previous screen windows with all the actively running programs.

This is good way to save connection fee if you are on the dial-up network connection.

The key bindings for the screen command

In screen session, all keyboard inputs are sent to your current window except for the command keystroke, by default ^A ("Control-A"). All screen commands are entered by typing ^A plus a single key [plus any parameters]. Here are important ones to remember:

List of key bindings for screen.

key binding

meaning

^A ?

show a help screen (display key bindings)

^A c

create a new window and switch to it

^A n

go to next window

^A p

go to previous window

^A 0

go to window number 0

^A 1

go to window number 1

^A w

show a list of windows

^A a

send a Ctrl-A to current window as keyboard input

^A h

write a hardcopy of current window to file

^A H

begin/end logging current window to file

^A ^X

lock the terminal (password protected)

^A d

detach screen session from the terminal

^A DD

detach screen session and log out

See screen(1) for details.

The screen like program for the X

Install the xmove package to enable support for mobile X11 clients. See xmove(1).