Technology Lab —

Ever wanted to know how to automatically detect which network interface to use …

Tools, Tips, and Tweaks

guessnet,ifplugd, and waproamd

Wouldn't it be nice just to pick up your laptop, plug it in at work, and be connected to the network without having to do anything other than connect the cable? Or to take a WiFi laptop to school, have it recognize the hotspot there and set up the appropriate WEP key*? Well, with the help of a couple of programs and some configuring this can become a reality.

What exactly are we doing? It's actually quite simple. We are going to set up multiple logical interfaces for a single physical interface. Next, we are going to help the computer recognize what network it is on and bring up the appropriate logical interface. Finally, we will show the computer how to recognize that it is connected to a network and have it trigger the network recognition

* Yes, WEP is insecure. But some security is better than none, as long as you recognize that it is weak security.

Before we begin

A few quick things things to note. First, this assumes that you have root access on the machine you are using. Second, this was written with Debian systems in mind, so theoretically, this should work with any Debian-based distribution. Things are likely very different in other distributions, especially Red Hat-based distributions. Distributions such as Knoppix, Morphix, Xandros and Lindows may be similarly configured. A guide to doing something similar in Red Hat is in the works. Finally, be sure to make a back up before you make any changes. If something bad occurs a backup will allow you to restore your network settings, which is better than no networking at all.

First things first . /etc/network/interfaces

If you know what's in /etc/network/interfaces already and know how to use ifup and ifdown, you can skip this section. Otherwise, read on.

Layout

/etc/network/interfaces is where the configuration of your network is stored. A basic interfaces file might look like this:

iface eth0 inet dhcp ? use dhcp to configure the first physical interface

iface eth1 inet static ? Set up a static interface for the second card based on the lines below it

auto eth0 lo ? automatically bring up the loopback interface and the first interface

how to use the information in /etc/network/interfaces

In order to make use of the information in this file, you use the ifup and ifdown commands. To use the second card and not the first card you would use the following commands (you will probably need root access to execute them):

ifup eth1
ifdown eth0

Using multiple configurations for an single interface

Okay, that's great. But what if you want to have a different configuration for work and home and you only have one card? The interfaces file can handle that, too. You don't have to name the logical interface based on the physical interface. For example,

# Use dhcp to configure work
iface work inet dhcp
# Use a static configuration at home
iface home inet static
address 192.168.1.2
netmask 255.255.255.0
gateway 192.168.1.1

The only problem is that ifup doesn't know what to do with those configs. When you want ifup now, you need to tell it what config to use. All you do is use

ifup =

An example:

ifup eth0=work
ifdown eth0
ifup eth0=home

Notice that you don't have to tell ifdown which config to use; it already knows which is being used.

Discovering which configuration to use . guessnet

All that is well and good, but we don't want to have to tell the computer where we are. This is step one of automatic configuration. The interfaces file allows you to do a couple of neat things. There is a special stanza that allows you to plug in a script to determine where you are. This stanza is the mapping stanza. First, we add the following lines:

The script stanza specifies what command/script to run. It is passed the interface name (eth0) in this case. It is expected to echo a logical interface name (home or work). Basically the mapping command will run the script and the run ifup eth0=.

For our purposes, we are going to use the guessnet program. guessnet is intended to be used just to find out where you are. It does this by performing specific tests, which can be stored in /etc/network/interfaces or in its own config file. We will use /etc/network/interfaces to store the config information.

New /etc/network/interfaces:

auto lo eth0
iface lo inet loopback
# special mapping for eth0
mapping eth0
script /usr/sbin/guessnet-ifupdown
# Due to limitations in ifupdown's parser, you have to do some fun things
map default: none
map verbose: true
# Use dhcp to configure work
iface work inet dhcp
# some script to check that you are at work
test-command /usr/local/bin/check_work
# Use a static configuration at home
iface home inet static
address 192.168.1.2
netmask 255.255.255.0
gateway 192.168.1.1
# due to ifupdown parser, you can't have two options with the same name
test1-peer address 192.168.1.1 mac 00:01:02:03:04:05
test2-peer address 192.168.1.3 mac 00:01:02:03:04:06

What does that file do? First, it allows eth0 to be brought up by ifup -a. Second, it maps eth0 to either home or work. guessnet will run an external command (/usr/local/bin/check_work) that determines if it is at work or not. It will also send an ARP packet to 192.168.1.1 and 192.168.1.3 and matches their MAC addresses. Whichever test is successful first will have its interface assigned.

Discovering when to reconfigure . ifplugd

So now all we have to do is ifup -a and we should have a network interface up and going (assuming we are at home or work). But things can be made even simpler. ifplugd is a daemon that runs and determines whether or not a network interface is activated. When it finds it is connected, it automatically ifups the interface. It can be set to run when booting, or even run when hotplug detects a connection.

ifplugd has a config file, /etc/ifplugd/ifplugd.conf. The line that is most important to us is the INTERFACES line. That line tells the daemon what interfaces to keep an eye on. When it detects that an interface changes state it runs the approrpriate action. A sample line might be:

INTERFACES="eth0"

The daemon will keep check on eth0. If you had other interfaces, you would still have to manually initiate the configuration process.

One final thing with ifplugd: you have to stop the interfaces its controlling from being brought up automatically by ifup -a because ifplugd now controls it. The auto stanza in /etc/network/interfaces should now look like this:

auto lo

Problems with wireless and WEP keys . waproamd

ifplugd is great, but it doesn't allow you to set a WEP key with ifup because ifup is called after a connection has been found. The solution is simple: another program called waproamd. Its sole purpose is to scan for access points and configure as needed. It works well with ifplugd.

Summary

Automatic network configuration consists of several parts.

Defining multiple configurations in/etc/network/interfaces

Determining what configuration to use . guessnet

Triggering the reconfiguration . ifplugd/waproamd

References

Cool App of the Week

Lately, many people have bought TV tuner cards for their computers and started to enjoy watching broadcast and cable television programs to their own desktop computer. However, in the past, there has been a scarcity of killer programs to keep the boob-tubery easy and fun. Windows users have had DScaler for a while, which boasts a vast array of features. But counterparts for Linux haven't really been equivalent in terms of features or quality until tvtime came along.

tvtime, used with cards that have Video4Linux drivers available, offers many features that many other TV viewers for Linux do not. Right-clicking on the screen gives you the "Setup" menu. You have the ability to manage the channels, change input configuration, the picture settings, how the video feed is processed and other display options. tvtime uses deinterlacers from DScaler delivering better picture quality, offers widescreen 16:9, overscan, XDS decoding (showing the channel name and what's playing) and even closed captioning in its own font rather than the standard black strips with white text as seen on real television sets.

D'oh! It's tvtime!

Many other options make tvtime easy to work with no matter where you live. TV modes in most places are variants of NTSC, PAL or SECAM, which are all supported. Also, most frequency bands in which you might want to access channels are listed, such as "us-cable," "europe," or even "russia" and "france." If you can't find the frequency settings you need, you can make your own custom set.

There are a few other options that become useful if you have slightly different system settings than the usual defaults. If you need tvtime to place its video overlay on a different X display or use a different display driver, sound device, channel or video capture/tuner device, you can make the appropriate settings in tvtime. There is even a mirror option for those of you who feel the need to watch TV in another room reflecting the image off a mirror or three.

When tvtime is started for the first time you can have it scan for active channels, much as you do on a real TV. You can change settings for each channel individually and also have global defaults for brightness, contrast, color and hue. This allows you to compensate for the different picture qualities you might receive on different channels. The settings for tvtime are stored in XML format which is also helpful, since the file format is easy to understand and can be used by other applications. The on-screen display makes things simpler to set up and alter. From the captioning features to the easy-to-use interface for the options available, overall this is the best TV viewing application available for Linux.

/dev/random

From the Department of Speedy Service With a Smile: the GNOME Nautilus
developers have fixed a good number of the issues we had with the GNOME 2.6
release in our
GNOME 2.6 review. For more details, check out
this thread. These changes will be in the forthcoming GNOME 2.6.1 release.

Real-world Desktop Analysis - Nat Friedman of Novell takes a morerealistic approach to Linux's deployment on desktops. While most apologists
continue to preach the "we are there" mantra, Nat takes a binary approach, it's
either there, or it isn't. Check the story to see how Novell plans on making the
enterprise desktop a viable solution.

After the controversy surrounding XFree86 4.4 licensing,
the X.Org Foundation, a consortium
that manages the development of the specification and an implementation
of the X Window System, has announced
their first release, called the X Window System X11R6.7. It seems
that most prominent X developers and distributors have now thrown their weight
behind X.Org instead of the XFree86 Project.