networking

This page describes some networking configuration for Debian GNU/Linux.

For networking to "just work", the computer must notice when cables are plugged in or wireless hot spots come into range and then connect to the network.

Further, if the computer gets connected to a network that does not have DHCP (such as when using a crossover cable to connect to a computer that does not have DHCP), the computer should give itself an address and start a DHCP server.

In the examples, I have an interface called green that makes a network 192.168.3.0/24 if given the chance and an interface called air that makes a network 192.168.6.0/24. My computer is at address 192.168.X.13 on these networks.

Firstly, install the software:

$ sudo apt-get install ifplugd dhcp dhcp3-client

ifplugd

ifplugd notices when networks are available and executes /sbin/ifup iface when iface is connected to a network.

Edit /etc/default/ifplugd and change this:

INTERFACES="green air"
..to include your network interfaces, then:
$ sudo /etc/init.d/ifplugd restart

ifup

To make ifup use DHCP to configure your network interfaces, edit /etc/network/interfaces like so:

iface green inet dhcp
    up /etc/init.d/iptables start

iface air inet dhcp
    up /etc/init.d/iptables start
..for each of your interfaces.

DHCP client

To prevent dhclient3 from getting an IP address from the DHCP server running on the same computer, get dhclient3 to stop the DHCP server before requesting an address using DHCP by making a file /etc/dhcp3/dhclient-enter-hooks.d/stop-dhcp-server like this:

case "$reason" in

    PREINIT)

        # stop the DHCP server so we don't get an address from ourselves!
        /etc/init.d/dhcp stop
        ;;

esac

To configure dhclient3 so it doesn't wait a whole minute before failing to configure an interface using DHCP, edit /etc/dhcp3/dhclient.conf and append this:

# seconds
timeout 10;

# minutes after failing to get an address before trying again
retry 2147483647;

# the time between requests in seconds
initial-interval 2;

When dhclient3 fails to configure an interface using DHCP it runs /etc/dhcp3/dhclient-exit-hooks.d/*, so make a file in that directory like this:

case "$reason" in

    FAIL)
        # configure $interface with a static IP address and start the DHCP
        # server
        case "$interface" in

            green)
                /sbin/ifconfig green 192.168.3.13 up
                ;;

            air)
                /sbin/ifconfig air 192.168.6.13 up
                ;;
        esac

        /etc/init.d/dhcp start
        ;;

esac

DHCP server

Edit /etc/dhcpd.conf like this:

subnet 192.168.3.0 netmask 255.255.255.0 {
    option domain-name "green";
    range  192.168.3.128  192.168.3.254;
    option domain-name-servers your-isps-name-server;
    option routers 192.168.3.13;
}

subnet 192.168.6.0 netmask 255.255.255.0 {
    option domain-name "air";
    range  192.168.6.128  192.168.6.254;
    option domain-name-servers your-isps-name-server;
    option routers 192.168.6.13;
}

$Revision: 1.2 $, $Date: 2006/03/30 03:51:50 $

Valid HTML 4.01 Transitional