| Chapter 17 - Network Switching | < ^ > |
The Flybook is highly portable and has plenty of different network connection options, and I will therefore be using it at multiple locations. Mac OS X has a handy 'Location' feature that allows you to set an entire network configuration (all interfaces, proxies, etc.) and give it a name: these configurations can then be swapped on the fly. For example, you can have a 'Work' setup for ethernet only with DHCP and a corporate http proxy, and a 'Home' setup with Wifi, static IP and no proxy. As standard in Linux, changing from one network location to another requires a bunch of /etc/init.d scripts to be run as root. Also due to HTTP proxy functionality not being fully integrated into Linux, all the various apps that connect to the web would need config changes.
To give similar functionality to OS X Locations, I hacked together some simple scripts. These are very rudimentary - the basic idea being the current location is stored in a file, and each location has a setup script. This script can be run with either 'up' or 'down' parameters, the 'up' param setting up the interfaces as required and starting services, etc. and the 'down' param returning the system to baseline (i.e. only loopback interface). The setnet script simply runs the 'down' script for the current location, then runs the 'up' script for the new location. So far this appears to work, though it's not robust or particularly generic. There are other, better developed, options. The scripts contain comments for easy comprehension. Note that I am not a unix guru, so advice / recommendations / etc. are most welcome!
My scripts all reside in /etc/lxnet and are as follows:
The Proxy problem was more difficult. Firefox contains its http proxy detail in its config files, and you can't change the proxy whilst Firefox is running. Using command line tools like wget requires an environment variable to be set: again, changing this requires shells to be restarted.
To get round this, I installed tinyproxy, which runs as a daemon, forwarding TCP traffic according to its own configuration. This allows all default proxy settings on the Flybook to point to the local machine on a specified port, on which the tinyproxy daemon is listening (i.e. Mozilla proxy, and env variable http_proxy for wget, etc.). The network switching scripts can then restart the tinyproxy daemon as necessary and change the external proxy details.
The current stable config was 1.6.3, so I downloaded the source and compiled / installed it.
To fit in nicely with Gentoo I created an init.d script to start / stop the tinyproxy daemon, based on the sshd script. I store the HTTP remote proxy settings in the /etc/lxnet directory, these can be deleted / created by the netconfig scripts. Note that I've set the local port for tinyproxy to be 49000 - this is just an unused port and has no special significance. The daemon is set to start with the default runlevel: subsequent changes to the proxy settings are handled by my simple netconfig scripts. The /etc/init.d/tinyproxy script is here.