This was originally posted on 2009-08-10 to http://andrewho.co.uk/weblog/debian-powerbook-g4-network-configuration
Debian's network configuration is pretty straightforward (make sure you have the
package wireless-tools
installed). The first thing to note is that on the
PowerBook G4, you'll need to extract the Broadcom firmware. You can do this by
installing the b43-fwcutter
package (it's in the contrib repository) which
automatically extracts the firmware in its post-installation "configuration".
I have three scenarios that I need to account for:
- Wired ethernet port with a fixed IP on my home network
- Wireless on a defined access point (HO1) with a fixed IP on my home network
- Wireless roaming via DHCP
Debian stores all of the pertinent network configuration in
/etc/network/interfaces
. Wireless networks are usually defined in
/etc/wpa_supplicant/wpa_supplicant.conf
. I'll explain how these files are
laid out before going ahead and showing my configuration. This explanation
should cover a decent proportion of use cases, but for more information see
interfaces(5), wpa_supplicant.conf(5), wpa_action(8) etc.
interfaces
consists of stanzas defining logicial interfaces, starting with the
word iface
(there are also mapping
, auto
and allow-
stanzas). What
happens is that when you call:
% ifup <physical-interface>=<logical-interface>
Debian brings up the physical interface with the configuration defined for the
logical interface in interfaces
. If you don't specify the logical interface,
Debian looks for a logical interface with the same name as the physical
interface. In other words, when you issue ifup eth0
, Debian thinks of this as
ifup eth0=eth0
. Thus, for very simple (e.g. single-location) configurations,
you don't really need to think about the separation of physical and logical
interfaces.
The first line of each stanza has this syntax:
iface <logical-interface> inet <method>
Of course, inet
just defines TCP/IP networking; if you want IPv6 or something
else then you probably don't need this article to help you with network
configuration. <method>
, for our sake, can be dhcp
, static
, or manual
.
dhcp
is self-explanatory; static
is for static IP configuration; manual
is
for completely manual configuration (as in the case of wireless).
So, to give an example, the wired configuration stanza for my home network looks like this:
iface eth0 inet static
address 192.168.1.31
netmask 255.255.255.0
broadcast 192.168.1.0
gateway 192.168.1.1
Wireless configuration is a bit more complicated, and is handled by the
wpasupplicant
package. There are two ways to configure a wireless network.
The first is to manual describe it in interfaces
, such as the following two
examples:
iface ap1 inet dhcp
wpa-ssid ap1
wpa-psk <hex-key>
iface ap2 inet static
wpa-ssid ap2
wpa-key-mgmt NONE
address 192.168.1.31
netmask 255.255.255.0
broadcast 192.168.1.0
gateway 192.168.1.1
Whilst this is good for known configurations, it doesn't really offer much
flexibility in terms of wireless roaming. The second option is to hand off
deciding which wireless network to connect to (and associated configuration) to
wpa_supplicant.conf
. You do this with the following stanza:
iface wlan0 inet manual
wpa-roam /etc/wpa_supplicant/wpa_supplicant.conf
Then, define the wireless networks in wpa_supplicant.conf
. One interesting
trick that you can use is to set id_str
in wpa_supplicant.conf
for each
network. This then invokes a logical interface of that name in interfaces
,
which is useful for IP configuration.
Hopefully this will bring it all together. Here are the two files:
[ /etc/network/interfaces ]
# Loopback
auto lo
iface lo inet loopback
# Wired interface with a static IP
iface eth0 inet static
address 192.168.1.31
netmask 255.255.255.0
broadcast 192.168.1.0
gateway 192.168.1.1
up rm /etc/resolv.conf && ln -s /path/to/etc.git/resolv.conf /etc/resolv.conf
# Use wpa_supplicant to determine which wireless network to associate to
iface wlan0 inet manual
wpa-roam /etc/wpa_supplicant/wpa_supplicant.conf
# Configuration for id_str="wlan0-ho1"
iface wlan0-ho1 inet static
address 192.168.1.31
netmask 255.255.255.0
broadcast 192.168.1.0
gateway 192.168.1.1
up rm /etc/resolv.conf && ln -s /path/to/etc.git/resolv.conf /etc/resolv.conf
# All other wireless networks should use DHCP
iface wlan0-dhcp inet dhcp
[ /etc/wpa_supplicant/wpa_supplicant.conf ]
# For wpa_cli
ctrl_interface=DIR=/var/run/wpa_supplicant
# HO1 network
network={
ssid="HO1"
priority=10
key_mgmt=NONE
id_str="wlan0-ho1"
}
# Default: associate with any open network
network={
key_mgmt=NONE
id_str="wlan0-dhcp"
}
The eth0
configuration should be pretty self explanatory. I bring it up with
ifup eth0
and down with the corresponding command. The wireless interface is
a bit more interesting. In all cases, I bring it up with ifup wlan0
and down
with wpa_action wlan0 stop
. This uses the wlan0
stanza which tells Debian
to look at wpa_supplicant.conf
. Here, we decide which network to associate
to. If HO1 is available, it associates to that, otherwise it associates to any
open network. In both cases, id_str
causes the invokation of a wlan-*
logical interface which results in either a static IP or DHCP assignment.
The final thing to note is those up
commands. They just restore my home DNS
configuration (the master resolv.conf
is stored in a git repository) because
DHCP overwrites resolv.conf
.