As you take your laptop from one network to the next, from home to work or from the coffee shop to the conference, how do you tell it about each new network?
Modern Linux systems come with nifty GUI programs such as NetworkManager and wicd, but I find them slightly cumbersome and hard to use. I find they're always trying to out-guess me about what network I really want to use, and they don't work terribly well with a lightweight desktop.
I find it much faster to type one command, like netscheme home or netscheme work, for networks I use a lot, and save all the fiddling with menus.
This page covers two topics:
You need two Python scripts: netscheme-1.4 and netutils-1.4.py. Put them somewhere in your path and name them netscheme and netutils.py: I put them in $HOME/bin, my personal bin directory, but somewhere like /usr/local/bin is also fine.
By default, netscheme knows about two schemes. The first, "dhcp", will try to set up a connection using your first wired ethernet port (e.g. eth0) and a DHCP address. To use it, type:
sudo netscheme dhcp
The second built-in scheme, "wifi", is also DHCP, but uses your first wireless connection (typically wlan0 or eth1). This works on some networks, but most wireless networks will require that you specify a network name (SSID).
To set up your own custom schemes for places you go, create a file in your home directory called .netscheme containing entries like this:
[home] dhcp = false ip = 192.168.1.42 netmask = 255.255.255.0 broadcast = 192.168.1.255 gateway = 192.168.1.1 dns_servers = 192.168.1.1,192.168.1.2 [coffeehouse] encryption = open essid = coffeehouse-wifi [work] encryption = wpa essid = MyWorkWPA key = secretpassword
DHCP is the default, but you can set it to false and use static addresses.
netscheme with no arguments will try to figure out the
current scheme. (For a wired scheme with no essid, it may not be sure.)
netscheme schemename will switch to that scheme.
netscheme essid will try to connect to the given wireless
network, and will ask whether you want to save that as a scheme for later.
|--version||show program's version number and exit|
|-h, --help||show this help message and exit|
|-l, --list||List the known schemes|
|-a, --accesspoints||List available accesspoints|
|-m, --multi||Add a new interface without bringing down current one|
netutils.py is the heart of netscheme. It consists primarily of wrappers around system utilities like ifconfig, iwconfig, iwlist, route, modprobe and so on, but it presents a much cleaner Python interface so you don't have to deal with those underlying details.
Download it: netutils-1.4.py
Documentation for it (generated with pydoc) is available here: Python netutils.py networking module.
If you have a wishlist for functions you'd like to see in netutils.py, or ways you think I should change the API, don't hesitate to let me know!
For historical reasons I've left the Debian/Ubuntu-specific network schemes page online. It includes some possibly helpful though also partly obsolete information about Debian's /etc/network/interfaces mechanism, and maybe even a bit of even more obsolete information about networking under old Redhat systems.