I really wanted to describe my current network setup I use on my laptop. So here is this post.
My objectives were: keep the configuration simple and easy to use for the user.
What I have
My laptop automatically connects to wifi (for configured SSIDs) and obtains an IP address. If I connect the ethernet cable it gets an IP there as well and the same goes for USB (tethering). Each interface gets the default route and they are inserted with different metrics. The wired connection wins. If the preferred interface gets disconnected (e.g cable pulled out) it automatically starts to use the other available interface.
# ip route show
default via 192.168.44.129 dev usb0 metric 267
default via 141.70.74.1 dev wlan0 metric 303
141.70.74.0/21 dev wlan0 proto kernel scope link src 141.70.74.145 metric 303
141.70.74.145 via 127.0.0.1 dev lo metric 303
192.168.44.0/24 dev usb0 proto kernel scope link src 192.168.44.18 metric 267
192.168.44.18 via 127.0.0.1 dev lo metric 267
Components
Setup
dhcpd5
This is the dhcp client daemon that tries to get IP addresses on interfaces that are operational mode up. When a link comes up which is: usually after cable insertion for wired ethernet or successful AP association for wireless.
This tool also takes care to add the default routes with the mentioned metrics attached.
To get rid the legacy isc dhclient I did (there may be cleaner ways):
dpkg-divert --divert /sbin/dhclient.orig --rename /sbin/dhclient
ln -s /bin/true /sbin/dhclient
I created a systemd unit file (the default init script is also fine): /etc/systemd/system/dhcpcd.service
[Unit]
Description=dhcpcd5 - IPv4 DHCP client with IPv4LL support
Before=runlevel2.target runlevel3.target runlevel4.target runlevel5.target shutdown.target
After=local-fs.target
Conflicts=shutdown.target
[Service]
ExecStart=/sbin/dhcpcd5 -B -L -d
[Install]
WantedBy=multi-user.target
wpa_supplicant and /etc/network/interfaces
iface wlan0 inet dhcp
wpa-conf /etc/network/wpa_supplicant.conf
wpa_supplicant.conf looks like this for me:
ctrl_interface=/var/run/wpa_supplicant
update_config=1
network={
ssid="eduroam"
scan_ssid=1
key_mgmt=WPA-EAP
group=CCMP TKIP
eap=PEAP
identity="someuser@login.ppke.hu"
password="arealpasswordgoeshere"
ca_path="/etc/ssl/certs"
subject_match="/C=HU/ST=Budapest/L=Budapest/O=Pazmany Peter Katolikus Egyetem/CN=tutela.itk.ppke.hu"
phase1="peapver=0"
phase2="MSCHAPV2"
}
network={
ssid="Butterfly13"
scan_ssid=1
key_mgmt=NONE
priority=4
disabled=1
}
network={
ssid="homewifi"
scan_ssid=1
psk="thepskgoeshere"
key_mgmt=WPA-PSK
priority=4
}
I use wpa_cli
to control the wifi configuration or if I need to add ad-hoc changes (e.g for debconf). It is also easy to select networks to prefer or just disable all except for one.
The networks needs to be up:
ifup eth0
ifup wlan0