July 10, 2006

Roaming Ethernet configuration with Guessnet

Author: Manolis Tzanidakis

If you use your laptop in many different locations, you must be tired of having to configure your network manually every time. Dynamic Host Configuration Protocol (DHCP) is a nice alternative, but what can you do in places where DHCP is not an option. Guessnet is the right tool for that job.

As its name implies, Guessnet tries to guess the network you are connected to based on a list of candidate profiles and a test pattern for each one. To make a long story short, it tries to match the static IP of a host, usually a router or a server, with a specific MAC address, which is unique for every network card. If it succeeds, it prints out the name of the profile, and you can use that to configure your Ethernet interface accordingly using a shell script, or, if you use Debian (or any Debian-based distribution, such as Ubuntu) directly from /etc/network/interfaces and ifupdown. Other test methods that can be used are described in the guessnet man page, but I prefer the IP-MAC matching method, because it's easy to set up and just works.

Since I use Debian (Unstable) on my laptop I will focus on that in the following example. Edit the /etc/network/interfaces file to create a guessnet-friendly stanza for the Ethernet interface (eth0):


auto eth0

mapping eth0
        script guessnet-ifupdown
        map timeout: 10
        map default: none

iface home inet static
        address 192.168.1.3
        netmask 255.255.255.0
        gateway 192.168.1.1
        test1 peer address 192.168.1.1 mac 00:11:22:33:44:55
        test2 peer address 192.168.1.2 mac 00:55:44:33:22:11

iface work inet static
	address 192.168.0.40
	netmask 255.255.255.0
	gateway 192.168.0.254
	test1 peer address 192.168.0.254 mac 00:55:66:77:88:99
	test2 peer address 192.168.0.1   mac 00:99:88:77:66:55

# default dhcp for none
iface none inet dhcp

This configuration has two profiles with static IP addresses, home and work, and a failsafe with DHCP (none) in case I'm connected to another LAN. To discover the remote host's MAC address, you can use arping (part of the iputils suite, which is installed by default in most distributions; in Debian install the iputils-arping package) as arping REMOTE_IP.

You can further automate the whole process by installing ifplugd and have it configure your Ethernet interface automatically every time you plug in a network cable. Also make sure to read the man pages of ifupdown, interfaces, and, of course, guessnet in order to create more advanced configurations.

Click Here!