Network profiles for a laptop

Posted by niol on Tue 20 Dec 2005 at 13:04

This article explains how to configure networking in a very pleasant way, so that it works automatically wherever you go. It is adaptable to lots of uses, and may be usefull even if you don't use Wifi but connect to multiple networks. This solution has been inspired by a tutorial that can be found in the references section at the bottom of this page. It uses three tools that integrate well with the debian network configuration:

  • wpa_supplicant, which handles wireless access point association,
  • ifplugd that checks for a physical layer link to be established (i.e. an ethernet cable to be plugged or an active wireless association),
  • guessnet that gives you tools to detect which network you are connected to.
  • resolvconf to understand name server configuration in /etc/network/interfaces.

First, some installation:

# apt-get install wpasupplicant ifplugd guessnet resolvconf

The next steps consist mostly in editing a bunch of files. To configure all this, my advice is to turn networking off:

# ifdown eth0
# ifdown eth1
# /etc/init.d/wpasupplicant stop
# /etc/init.d/ifplugd stop

Physical layer


OPTIONS="-D ipw -i eth1 -c /etc/wpa_supplicant.conf"

You may notice that my Wifi driver regarding wpa_supplicant is ipw (which fits either ipw2100 and ipw2200). The wpa_supplicant manual page lists other drivers that may fit your Wifi chipset.

If you use kernel 2.6.13 or above, you need to know that what handles wireless in the kernel, the Wireless extensions, have been updated. As a consequence, you cannot use the ipw driver anymore. You need to use the wext driver.

OPTIONS="-D wext -i eth1 -c /etc/wpa_supplicant.conf"



# the network I use which is configured using WPA-PSK

# You may add networks below, such as public unencrypted APs

I stripped down the comments to save space on this page, but every detail may be found in the file /usr/share/doc/wpasupplicant/examples/wpa_supplicant.conf.gz. To get you some hints on how wpa_supplicant works, it tries to associate to an access point with the highest priority. My configuration is very basic. My goal is to get secure Wifi at home, and be able to add other configurations when I'm out (public AP).

Ensure your are associated to your access point:

# /etc/init.d/wpasupplicant start
# iwconfig

Transport, network and application layers

/etc/network/interfaces is the central repository of the network configuration in Debian.

# This file describes the network interfaces available on your system
# and how to activate them. For more information, see interfaces(5).

# The loopback network interface

auto lo
iface lo inet loopback

# ifplugd brings up interfaces, so do not bring them up at startup.
noauto eth0 eth1
# Both Ethernet and Wifi interfaces are managed automatically
mapping eth0 eth1
	script guessnet-ifupdown
	map default: foreign
	map timeout: 3
	map verbose: true

iface home inet static
	test peer address mac 00:01:23:45:67:89
	up /etc/init.d/samba start
	down /etc/init.d/samba stop

iface foreign inet dhcp

This basically tells eth0 or eth1 to be configured differently whether a host with address and mac 00:01:23:45:67:89 is found or not. If it is there, take a static ip address and start samba. If not, revert to dhcp.

A little tip for the samba example : for samba not to start while booting, just run :

# update-rc.d samba stop 0 1 2 3 4 5 6 .

Ensure your have the desired ip address:

# /etc/init.d/ifplugd start
# ifconfig

This setup works well for me.

There are issues when changing networks while in hibernation. The solution is to be stop ifplugd while hibernating. If you use the suspend2 ''hibernate'' script, you may want to add this line to your hibernate.conf:

RestartServices ifplugd

There should be a priority to the Ethernet interface, and the wireless interface should go down while a network cable is plugged in. A debian bug has been filled on the subject. There are two solutions :

  • Have the Ethernet ifplugd instance control the wireless instance. Drawback : this is hackish.
  • Use ifmetric to route traffic through Ethernet if available. Drawbacks : wireless is up for no reason and if wireless gets associated after the Ethernet cable is plugged, DNS settings are overwritten, which can be annoying if they are different.
  • Use the new wpa_supplicant feature to manage the Ethernet. Not sure I red well on this...

For now, before I plug to a wired network, I just use the kill switch feature of my laptop to turn wireless off.

As usual, comments welcomed.




Posted by jasonmartens (66.158.xx.xx) on Tue 20 Dec 2005 at 15:46
Network Manager is anther option to do this sort of thing. Once it is installed (which currently takes some work because it is still beta, and there is no debian package), connecting to different networks is effortless. It currently does not support WAP (just WEP), but is still very useful. You can check it out at The 0.5.1 breezy source packages are located at

[ Parent | Reply to this comment ]

Posted by Anonymous (66.36.xx.xx) on Wed 21 Dec 2005 at 04:09
Personally, I would never use something like this - an X app (let alone Gnome!) to control the network? I want the network working long before anything graphical happens. From the page: "A laptop user should never need to use the command line or configuration files to manage their network". I would add "A laptop user shold never need to use the GUI to manage their network".

[ Parent | Reply to this comment ]

Posted by jasonmartens (64.36.xx.xx) on Wed 21 Dec 2005 at 04:32
These two things are in direct conflict with each other. I know for sure that I am never going to teach my wife to configure the network via the command line. I also know that Network Manager actually detects what networks are available and configures them automatically, as opposed to something like whereami which doesn't so much detect which network you are on, but can be configured for different networks.

Also, from the user's perspective, why should you care if the network is up before the gui is up? You can't actually use it (if you are not a command line user) without a gui anyway, so it is somewhat pointless.

While I have configured my laptop for years from the commandline, I find network manager to be much less work, and far easier to configure from the beginning.


[ Parent | Reply to this comment ]

Posted by codejodler (84.57.xx.xx) on Mon 19 Feb 2007 at 20:10
jason: Also, from the user's perspective, why should you care if the network is up before the gui is up?

It may be handy if you have to boot into single mode, for some recovery.

For a special example, imagine somthing with updating X went wrong, and session low-level-crashes. You possibly would boot into single and disable graphical login managers, then boot into rc2 (for debian) to have multiple tty consoles and all services available. You would investigate the issue, maybe by looking up websites with a textbrowser, and possibly download a different video driver version.

Another example is if a comparable slow laptop runs services itself, like rsyncd or nfs, say for syncing and backups to different boxes. If you're in a hurry you could start connecting to services before login. Especially on slow (old) hardware, it may be worth to boot into a text session anyway, if all you want to do is downloading your photos from the cam, or read up a newsgroup.

A third fictive example is, where you're running unstable (+experimental), which is quite common on real new hardware, and the network GUI for some reason got ncompatible (conflicting) with other stuff. And you can't spend too much time on it right this moment, have to find a quick solution, and would decide to deinstall half the session just to have the network GUI working.

These are a few examples that comes to my mind immediately.
Maybe rare cases, but i'm sure i could find more. So...while for many people working without X is inconceivable, you must accept that there are others who see a benefit, sometimes. There's just no general rule.

And hey Alexandre, thanks for your great introduction!
It's a good example how to make things work together, and rather good understandable.


[ Parent | Reply to this comment ]

Posted by Anonymous (65.205.xx.xx) on Thu 22 Dec 2005 at 11:35
I would add that "a UNIX user shold never need to use the GUI to manage anything but GUI applications". I really only use X to manage a browser, an email reader, and a bunch of xterms.

The last time I made significant Linux on a laptop (2-3 years ago), I found too many packages claiming to handle profiles. It was easier for me to write a couple custom bash scripts than to evaluate all the convoluted, conflicting, and in-elegant packages available at the time.

Thanks for the article!

[ Parent | Reply to this comment ]

Posted by Anonymous (62.79.xx.xx) on Sun 19 Feb 2006 at 17:02
I'll just go and tell my father to create a bash script to set up his network..

Problem solved..

Hell I don't even know how to do that, and I have used linux constantly for several years now.

This is what I call linux techie fascism.

Network scripts should go out the window asap, and Network Manager is my best guess as to what should replace them.

[ Parent | Reply to this comment ]

Posted by Anonymous (81.158.xx.xx) on Sun 28 Oct 2007 at 14:25
Right. Because I really want to wait for my wireless connection to come up after I login, rather than being able to use the network/internet right after login.

Never mind that Network Manager won't work at ALL if your WM/DE doesn't have a systray.

Plus, this isn't a tutorial on writing bash scripts to configure network - it's a tutorial on configuring some programs to get network profiles to work without needing user input, like Network Manager. Just without needing to run a GUI to make it work.

[ Parent | Reply to this comment ]

Posted by Anonymous (82.249.xx.xx) on Tue 20 Dec 2005 at 17:00
whereami is another tool available in Debian, which handles network detection, configuration, etc. It supports scripts and so it's expandeable to define ip, routers, nameservers, proxys, mail servers, vpn......

[ Parent | Reply to this comment ]

Posted by spiney (128.131.xx.xx) on Tue 20 Dec 2005 at 17:15
I have set up something very similar and am quite happy about it. Even using a different proxy is working fine with the help of a Proxy Auto Configuration file that gets created for different environments, but one step I can't figure out how to do: automatically reloading the PAC file in Firefox when the network environment changes. Anyone?

I have searched for an extension that would let me control Firefox from the command line, but to no avail...
Debian GNU/Linux on an IBM Thinkpad T43p

[ Parent | Reply to this comment ]

Posted by Anonymous (195.149.xx.xx) on Wed 21 Dec 2005 at 12:15
I use privoxy or tinyproxy running on the local machine then I can setup all the proxy settings even $http_proxy at the shell level to use http://localhost:3128/ and you can just swap configs and reload when necessary. It uses a bit more ram but you can tweak that down a bit. You also can get the benefit of a shared cache across all applications and some add filtering if you use privoxy.


[ Parent | Reply to this comment ]

Posted by spiney (128.131.xx.xx) on Wed 21 Dec 2005 at 15:01
Good idea, and when disabling the browser-internal cache the memory consumption shouldn't be much different.

Too bad GUI applications tend to be just that: GUI applications. No way in controlling them via signals (like -HUP for daemons) or by other means, some don't even have sensible shortcuts for menus etc.

But I better stop ranting now. ;)
Debian GNU/Linux on an IBM Thinkpad T43p

[ Parent | Reply to this comment ]

Posted by Anonymous (212.11.xx.xx) on Thu 29 Dec 2005 at 11:50
My best practice to use wireless and wired connection together is use them both through bonding interface, set up to prioritize the cable... so I´m at home connected via cable, downloading some big file... when I need to move my laptop to second room, I unplug the cables, move it, the download goes still on.... come back, put the cables back, everything goes seamlessly :-)

OK, you need the kernel module bonding, insmod with options "mode=active-backup miimon=100 primary=eth0"

and the ifenslave package, which is called "from /etc/network/interfaces" like this:
auto lo eth0 wlan0 bond0

# The loopback network interface
iface lo inet loopback
name Loopback device

iface wlan0 inet manual
name Wireless LAN
pre-up iwsetup wlan0
#this is my own tool, I´m going to replace with wpa_supplicant :-)

iface eth0 inet manual
name Ethernet LAN card

iface bond0 inet dhcp
pre-up ifconfig bond0 up
pre-up ifenslave bond0 eth0 wlan0
name Bonded wired and wireless

Cheers, Michal

[ Parent | Reply to this comment ]

Posted by Anonymous (84.51.xx.xx) on Sat 14 Jan 2006 at 11:13
A little overkill there, you might find you are better off installing 'ifmetric', its a debian package, and replacing all that bonding marlakey with simply:

ifmetric wlan0 5

It simply uses the routing metrics built into Linux and makes the wireless routes a lower priority than the ethernet one (which defaults to 0). When both wired and wireless are connected then the wired connection is used, the moment your wired connection is unplugged everything starts to use the wireless connection.

No kernel dependencies and simply using a facility thats been in Linux kernel since...forever.


[ Parent | Reply to this comment ]

Posted by Anonymous (213.235.xx.xx) on Wed 8 Feb 2006 at 13:41
I'll write it again (and again).

The main feature of this setup is, that the connections initialized over cable are not lost when the cable is pulled off and switched to wireless. Which is not what you'd get with ifmetric, there you'd still have two IPs for that two devices. I have one (virtual) device with one IP, which has two physicall ways, how to send packets.

Yes, I like Linux due to its unbelieavable amount of solutions for everyones' demand/task/problem.


[ Parent | Reply to this comment ]

Posted by Anonymous (81.18.xx.xx) on Mon 10 Apr 2006 at 22:28
Does anyone found out how to automaticly connect to the wlan network with hidden essid? Of course we know this essid.

I try this in /etc/network/interfaces, I have skipped the part for other interfaces:

noauto eth1
mapping eth1
script guessnet-ifupdown
map eth1-home
map eth1-auto
map verbose: true
map timeout: 5
map default: eth1-auto
iface eth1-home inet dhcp
pre-up iwconfig eth1 essid xxxxxx
test wireless mac 00:80:C8:xx:xx:xx
# wireless-essid xxxxxx
iface eth1-auto inet dhcp

but unfortunatelly this does not work. It works neither with commented line nor without. There is no password set up.
If I run as root command:
iwconfig eth1 essid xxxxxx
everything works fine, and the interface gets IP from dhcp.

Any help apprieciated.

[ Parent | Reply to this comment ]

Posted by Anonymous (59.176.xx.xx) on Tue 16 Jan 2007 at 20:41
Can you please explain how to have the Ethernet ifplugd instance control the wireless instance.

[ Parent | Reply to this comment ]

Posted by suspended user romkas (193.206.xx.xx) on Sat 27 Jan 2007 at 10:50

New wpa_supplicant offers the roaming mode. So, in some cases everything you need to do (tested on Ubuntu Edgy Eft) is:

  1. install wpa_supplicant, ifplugd
  2. write wpa_supplicant configuration file for your interface (i have a wired+WPA on eth2)
  3. write something like this to your /etc/network/interfaces:
iface eth2 inet manual
        wpa-driver wired
        wpa-roam /etc/wpa_supplicant/wpa_eth2.conf

iface university inet dhcp

iface default inet dhcp

See docs that come with wpa_supplicant. They did a really good stuff!

[ Parent | Reply to this comment ]

Posted by freeroute (212.40.xx.xx) on Tue 25 Dec 2007 at 21:59
[ View Weblogs ]

I have 2 network cards in my laptop. eth1- wired, eth2- wifi

Unfortunatelly, eth2-anyopen doesn't work. eth1 working, eth2-home and eth2-SMC works fine. Could you please give me an advice?
OS: Debian-testing
Installed guessnet, ifplugd, rsolvconf, ifmetric
My /etc/network/interfaces:

# This file describes the network interfaces available on your system
# and how to activate them. For more information, see interfaces(5).

# The loopback network interface
auto lo
iface lo inet loopback

auto eth2
allow-hotplug eth1

mapping eth1
script guessnet-ifupdown
# Scan all logical interfaces
# More options can be given here, such as:
# map timeout: 10
# map verbose: true
# map debug: true
map default: none

iface eth1-home inet dhcp
test peer address mac 00:03:2F:29:E6:C2 source
up ifmetric eth1-home 0

mapping eth2
script guessnet-ifupdown
# Disable open net checking, just comment out if you are
# desperate enough :) (see relative stanza below)
map timeout: 10
#map !eth2-anyopen
# Scan only logical interfaces named eth2-*
#autofilter: true
map eth2-home
map eth2-SMC
map eth2-anyopen

iface eth2-home inet dhcp
up ifmetric eth2-home 5
wireless-essid FREEROUTE
wireless-key open xxxxxxxxxxxxxxxxxxxxxxxxxxxxx
# Match a wireless network with the given essid
test wireless essid FREEROUTE

iface eth2-SMC inet dhcp
wireless-essid SMC
wireless-key off
# Match a wireless network with the given essid
test wireless essid SMC

iface eth2-anyopen inet dhcp
up ifmetric eth2-anyopen 4
# You can also match any open network, if you are desperate :)
wireless-key off
wireless-essid any
test wireless essid any

# If nothing else is found, try DHCP
iface none inet dhcp

[ Parent | Reply to this comment ]

Posted by MicoFilos (128.122.xx.xx) on Mon 29 Dec 2008 at 18:03

I have the same problem. I have spent two days searching in google and have seen many different solutions, most of them from almost 4 years ago, and many of them contradicting with each other. This same document is tagged as 'obsolete'. What's going on guys, everybody has moved en masse to network-manager to configure their interfaces? :) Why if we don't want to rely on a GUI solution?

So, forgive my stupidity here, but I still cannot figure out whether 'ifplugd' is necessary or not to switch automatically from a wired to a wireless interface, or if wpa_supplicant should be used to manage the wired(?) interface, or if everything should be controlled via ifupdown. Don't get me wrong, I honestly think that Niol's document is clear and helpful, I just think it would be great to update it.

Can some of the experts enlighten us with an updated summary of how to configure network interfaces for a laptop, so that it switches seamlessly from a wired to a wireless connection, depending on whether or not an ethernet cable is plugged in? To avoid confusion it would help to start with the simplest scenario, in which both wired and wireless are managed by dhcp.

Again, sorry for my ignorance and thanks a lot for your attention.

[ Parent | Reply to this comment ]

Sign In







Current Poll

Should this site stay open?

( 1628 votes ~ 24 comments )