Differences between revisions 190 and 191
Revision 190 as of 2008-05-05 08:09:22
Size: 56188
Editor: OsamuAoki
Comment:
Revision 191 as of 2008-05-05 08:47:37
Size: 56186
Editor: OsamuAoki
Comment:
Deletions are marked like this. Additions are marked like this.
Line 543: Line 543:
A single physical Ethernet interface can be configured as multiple virtual interfaces with different IP addresses. Usually the purpose is to connect an interface to several IP subnetworks. For example, IP address based virtual web hosting by the single network interface is one such application. A single physical Ethernet interface can be configured as multiple virtual interfaces with different IP addresses. Usually the purpose is to connect an interface to several IP subnetworks. For example, IP address based virtual web hosting by a single network interface is one such application.

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)

I welcome your contributions to update the wiki pages. You must follow these rules:

  • Do not use Edit(GUI) button of MoinMoin.

  • You can update anytime for:
    • grammer errors
    • spelling errors
    • moved URL location
    • package name transition adjustment (emacs23 etc.)
    • clearly broken script.
  • Before updating real contents:

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 infrastructure

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 may 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 matches the own host name defined in the /etc/hostname. The <domain_name> in this is the [http://en.wikipedia.org/wiki/FQDN fully qualified domain name (FQDN)] of this host.

{i} I sometimes 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 resolvconf package makes this /etc/resolv.conf into a symbolic link and manages its contents by the hook scripts automatically.

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

ifmetric

-

-

, ,

Set routing metrics for a network interface.

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). ifconfig(8) etc.

iproute

19172

-

, ,

IPv6 and other advanced network configuration. ip(8)

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-arping

-

-

Test

Tool to send ICMP echo requests to an ARP address

iputils-ping

-

-

, ,

Tools to test the reachability of network hosts

iputils-tracepath

-

-

, ,

Tools to trace the network path to a remote host

arping

-

-

, ,

Tool to sends IP and/or ARP pings (to the MAC address)

inetutils-ping

-

-

, ,

ICMP ECHO tool

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 @{@nonfreehardwaredrivers@}@.

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/Local_area_network LAN]

The local area network

[http://en.wikipedia.org/wiki/Wide_area_network WAN]

The wide 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

(!) For PC connected to the WAN via BB-router, network interfaces on the LAN are served by static IP or DHCP connection by the BB-router.

(!) The cable TV service is generally served by DHCP or PPPoE. Both ADSL and FTTP are generally served by PPPoE. You have to consult your ISP for exact configuration requirement of WAN connection.

<!> 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 /sbin/ifconfig eth0 up
$ sudo pon dsl-provider
...
$ sudo poff dsl-provider
$ sudo /sbin/ifconfig eth0 down

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 conatins 2 commands: ifup(8) and ifdown(8). They offer basic 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.

(!) There is no command ifupdown.

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

This one always exists in the /e/n/i file.

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
 hostname "mymachine"

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 (see @{@thepppconnectionwithpppconfig@}@). 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 (see @{@thealternativepponwithwvdialconf@}@). Then, add the /e/n/i file entry for the primary PPP device ppp0 as:

iface ppp0 inet wvdial

The PPPoE connection

For PC connected directly to the WAN served by the PPPoE, you need to configure system with the PPPoE connection as described before (see @{@thepppoeconnectionwithpppoeconf@}@). Then, add the /e/n/i file entry for the primary PPPoE device eth0 as:

allow-hotplug eth0
iface eth0 inet manual
 pre-up /sbin/ifconfig eth0 up
 up ifup ppp0=dsl
 down ifdown ppp0=dsl
 post-down /sbin/ifconfig eth0 down
# The following is used internally only
iface dsl 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 functionalities described here are completely optional. I, being lazy and minimalist, rarely bother to use these.

<!> If you could not set up network connection by information in @{@thebasicnetworkctionwithifupdown@}@, you will make situation worse by using information below.

The ifplugd

The ifplugd package solves unplugged/replugged Ethernet cable issues for mobile PC etc.. It replaces auto or allow-hotplug functionarities (see @{@listofstanzasineni@}@) and 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" or "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:

  • Upon power-on or upon hardware discovery, the interface is not brought up by itself.
    • Quick boot process without the long DHCP timeout.
    • No funny activated interface without proper IPv4 address (see @{@thenetworkconfignstateofifupdown@}@).
  • Upon finding the Ethernet cable, the interface is brought up.
  • Upon some time after unplugging the Ethernet cable, 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.

The ifmetric

The ifmeric package enables us to manipulate metrics of routes a posteriori even for DHCP.

The following will set the eth0 interface preferred over the wlan0 interface:

  • Install the ifmetric package, and

  • Add an option line with "metric 0" just below the "iface eth0 inet dhcp" line.

  • Add an option line with "metric 1" just below the "iface wlan0 inet dhcp" line.

The metric 0 means the highest priority route and is the default one. The larger metric value means lower priority routes. The IP address of the active interface with the lowest metric value becomes the originating one. See ifmetric(8).

The virtual interface

A single physical Ethernet interface can be configured as multiple virtual interfaces with different IP addresses. Usually the purpose is to connect an interface to several IP subnetworks. For example, IP address based virtual web hosting by a single network interface is one such application.

For example, let's suppose that

  • a single Ethernet interface on your host is connected to a Ethernet hub (not by broadband router),
  • the Ethernet hub is connected to both the Internet and LAN network,
  • the Internet and LAN network by a single Ethernet interface with the Ethernet hub,
  • the LAN network uses subnet 192.168.0.x/24,

  • your host uses DHCP served IP address with the physical interface eth0 for the Internet, and

  • your host uses 192.168.0.1 with the virtual interface eth0:0 for the LAN,

then following stanzas in /etc/network/interfaces will configure your network:

iface eth0 inet dhcp
 metric 0
iface eth0:0 inet static
 address 192.168.0.1
 netmask 255.255.255.0
 network 192.168.0.0
 broadcast 192.168.0.255
 metric 1

<!> Althugh this onfiguration example with [http://en.wikipedia.org/wiki/Network_address_translation Network address translation] using [http://en.wikipedia.org/wiki/Netfilter/iptables netfilter/iptables] can provide cheap router for the LAN, there is no real firewall capability with such set up. You should use 2 physical interfaces to secure the real network separation.

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 provides 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
 hostname "mymachine"

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 manual
 pre-up /sbin/ifconfig eth0 up
 up ifup ppp0=dsl
 down ifdown ppp0=dsl
 post-down /sbin/ifconfig eth0 down

# The following is used internally only
iface dsl 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 check the /etc/network/run/ifstate file for the current network configuration state of the ifupdown system.

/!\ You may need to adjust numbers at the end of eth*, ppp*, etc. if you have multiple network interfaces.

Scripting with the ifupdown

The ifupdown system automatically runs scripts installed in /etc/network/*/ while exporting environment variables to 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 option under the iface stanza.

Here, each environment variable name, IF_<OPTION>, is created from the name for the corresponding option by prepending "IF_", converting the case to the upper case, replacing hyphens to underscores, and discarding non-alphanumeric characters.

The ifupdown-extra package (see @{@theifupdownextrapackage@}@) uses these environment variables to extend the functionality of the ifupdown package. The ifmetric package (see @{@theifmetric@}@) installs the /etc/network/if-up.d/ifmetric script which sets the metric via the IF_METRIC variable. The guessnet package (see @{@mappingwithguessnet@}@), which provides simple and powerful framework for the auto-selection of the network configuration via the mapping mechanism, also uses these.

(!) For more specific examples of custom network configuration scripts using these environment variables, you should check example scripts in /usr/share/doc/ifupdown/examples/* and scripts used in the ifscheme and ifupdown-scripts-zg2 packages. These addyional scripts have some overlaps of functinalities with the basic ifupdown-extra and guessnet packages. If you install these additional scripts, you should customize these scripts to avoid interferences.

Mapping with guessnet

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

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

  • you list test condition as the value for guessnet options 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, and the original network configuration infrastructure, ifupdown, does not cause negative impacts since guessnet options only export extra environment variables to scripts run by the ifupdown system. See details in guessnet-ifupdown(8).

(!) When multiple guessnet option lines are required in /e/n/i, use option lines started with guessnet1, guessnet2, and so on, since the ifupdown package does not allow starting strings of option lines to be repeated.

Other network configuration tools

GUI network configuration tools for Gnome and KDE may address basic network configuration such as static IP or DHCP but may not understand complicated advanced configuration done manually. Please check how they change e/n/i file by yourself.

The network-manager package seems to be very interesting one for wireless LAN environment and popular with some other distributions. The author has not been successful using it under the Debian system as of March 2008. (This may be due to author's fault.)

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 ~/.bashrc.

Network optimization

Generic network optimization is beyond the scope of this documentation. I will touch only subjects pertinent to the consumer grade connection.

List of network optimization tools.

1

2

3

packages

popcon

size

description

iftop

-

-

displays bandwidth usage information on an network interface

iperf

-

-

Internet Protocol bandwidth measuring tool

apt-spy

-

-

writes a sources.list file based on bandwidth tests

bwm

-

-

?BandWidth Monitor

ifstat

-

-

?InterFace STATistics Monitoring

bmon

-

-

portable bandwidth monitor and rate estimator

ethstatus

-

-

script that quickly measures network device throughput

bing

-

-

Empirical stochastic bandwidth tester

bwm-ng

-

-

small and simple console-based bandwidth monitor

ethstats

-

-

console-based ethernet statistics monitor

ipfm

-

-

a bandwidth analysis tool

ftm

-

-

Frogfoot Networks Traffic Monitoring Utility

Finding optimal MTU

The [http://en.wikipedia.org/wiki/Maximum_transmission_unit Maximum Transmission Unit (MTU)] value can be determined experimentally with ping(8) with "-M do" option which sends ICMP packets with data size starting from 1500 (with offset of 28 bytes for the IP+ICMP header) and finding the largest size without IP fragmentation.

$ ping -c 1 -s $((1500-28)) -M do www.debian.org
PING www.debian.org (194.109.137.218) 1472(1500) bytes of data.
From 192.168.11.2 icmp_seq=1 Frag needed and DF set (mtu = 1454)

--- www.debian.org ping statistics ---
0 packets transmitted, 0 received, +1 errors
  • ... try 1454 instead of 1500
  • The ping(8) command succeed

This process is [http://en.wikipedia.org/wiki/Path_MTU_discovery Path MTU (PMTU) discovery] and the tracepath(8) command can automate this.

For my home LAN connected via consumer router and FTTP, the PMTU value was identified to be 1454. The configuration menu of the router configured my router's MTU to 1454 when ISP name was given to it and that limits my choice of MTU for PC clients on the LAN to 1454. (My FTTH provider uses [http://en.wikipedia.org/wiki/Asynchronous_Transfer_Mode Asynchronous Transfer Mode] (ATM) as its backbone network and serves its clients with the [http://en.wikipedia.org/wiki/Point-to-Point_Protocol_over_Ethernet PPPoE].)

For normal PC clients, guide lines of the optimal MTU value are:

  • With the normal Ethernet link, the value for the MTU value is 1500 or less. (This is for DHCP served cable service.)
  • With the network link involving PPPoE with pure Ethernet backbone, the MTU value should be 1492 (=1500-8) or less to avoid the fragmentation. (The PPPoE wrapper consumes 8 bytes out of 1500.)
  • With the real life Ethernet link bridged over ATM backbone (typical cable service using DHCP), the optimal MTU value may be 1462 (=48*31-18-8). (author's speculation)
  • With the real life network link involving PPPoE bridged over ATM backbone (typical BB services using PPPoE), the optimal MTU value should be 1454 . (=48*31-8-18-8. see "[http://www.mynetwatchman.com/kb/ADSL/pppoemtu.htm Optimal MTU configuration for PPPoE ADSL Connections]" for rationale).

  • Any use of tunneling methods may reduce optimal MTU further by their overheads.
  • The MTU value should not exceed the experimentally determined smallest PMTU value.
  • The bigger MTU value is generally better when other limitations are met.

Setting MTU

Here are examples for customizing the MTU value to 1454 for typical BB services.

For the DHCP (see @{@thenetworkinterfeservedbythedhcp@}@), you can replace pertinent iface stanza lines in the /e/i/n with, e.g.,:

iface eth0 inet dhcp
 hostname "mymachine"
 pre-up /sbin/ifconfig $IFACE mtu 1454

For the static IP (see @{@thenetworkinterfewiththestaticip@}@), you can replace pertinent iface stanza lines in the /e/i/n with, e.g.,:

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

For the direct PPPoE (see @{@thepppoeconnectionwithpppoeconf@}@), you can replace pertinent mtu line in the /etc/ppp/peers/dsl-provider with:

mtu 1454

The [http://en.wikipedia.org/wiki/Maximum_segment_size maximum segment size] (MSS) is used as an alternative measure of packet size. The relationship between MSS and MTU are:

  • MSS = MTU - 40 for IPv4
  • MSS = MTU - 60 for IPv6

(!) The iptables(8) based optimization can clamp packet size by the MSS and is useful for the router.

WAN TCP optimization

The TCP throughput can be maximized by adjusting TCP buffer size parameters as described in "[http://dsd.lbl.gov/TCP-tuning/ TCP Tuning Guide]" and "[http://en.wikipedia.org/wiki/TCP_tuning TCP tuning]" for the modern high-bandwidth and high-latency WAN. So far, the current Debian default settings serve well even for my LAN connected by the fast 100M bps FTTP service.

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(1) program.

  1. You login to a remote machine.
  2. You start the screen command on a single console.

  3. You execute multiple programs in 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 previous screen windows with all actively running programs.

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

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).