A Linux virtual machine for Internet Connection sharing
Usage scenario
This setup is targeted to improvised setups where you need to share out a wireless or mobile connection on your laptop, to a number of computers on a wired network. Instead of using any built in ICS (Internet Connection Sharing) in your laptop's OS, with this solution you start a virtual machine ("device") that takes care of it all. In this way the ICS services are insulated from your laptop, and no changes to the routing on your laptop is needed.
I have only made initial tests with the setup, using two laptops, both running Ubuntu Linux 10.10, and pulling down the Internet over Wi-Fi and putting the local computer on a wired connection from the other latop.
How it works
A small (256 MB RAM) pre-configured Ubuntu Linux is running as a virtual machine under Virtualbox on your laptop. The virtual machine takes care of the Internet Connection Sharing, dishing out IP numbers and handling DNS for any number of computers connected via the wired network and routing their traffic on to the Internet.
In Virtualbox you can easily change the interface on your laptop used for the local connection. The Internet connection is handled automatically.
Your laptop is connected to the Internet via a mobile connection or a wireless connection.
Step by step guide:
- Install Virtualbox
- Download an iso image for the server version of Ubuntu 10.4LTS
- In Virtualbox, make a virtual machine ("machine") with two network interfaces, the first one as NAT, the second one as bridged. Make the second interface link to your local interface on your computer where the local computer should be connected (typically your wired network interface, usually eth0). The NAT connection will automatically connect to whatever Internet connection you have on the laptop.
- Start the machine
- Choose "Devices->CD/DVD devices->Choose a virtual CD/DVD disk file...", and navigate to your downloaded ISO.
- Reset the virtual machine. It will now boot from the ISO
- Run through the Ubuntu installation, install as little as possible, possibly the SSH server (which I needed due to particular circumstances). The minimum size of a Ubuntu server install is in the order of 600MB (see info on this here).
- Choose "Devices->CD/DVD devices->Remove virtual drive" in the VirtualBox guest window
- Restart the machine
- Login, run "dmesg|grep eth0" and "dmesg|grep eth1" to check that the OS hasn't moved them to new names (e.g. eth2 and eth3)
- Follow the instructions here Ubuntu Internet Gateway Method (iptables), changing eth0 and eth1 if needed.
- Set up the interfaces in /etc/network/interfaces, in my case using eth2 and eth3, in your case possibly eth0 and eth1:
auto eth2
iface eth2 inet dhcp
auto eth3
iface eth3 inet static
address 192.168.0.1
netmask 255.255.255.0 - Restart the networking:
sudo /etc/init.d/networking restart
- Install dnsmasq, also according to that page: DHCP/DNS server
- Make sure your host computer has an Internet Connection
- Plug another computer in to your local interface so it becomes a client
- Configure the client computer for DHCP
Now it should all work, check that the client computer can connect to the Internet.
You can now install a switch instead of the client computer and then hang as many client computers as you want off that switch (as many as the configured range of dnsmasq allows, 250 according to the example on the instructions page above).
Trying other operating systems and solutions
I first tried Internet Connection Sharing Appliance | Virtual Appliance Marketplace , but could not get it to run the way I wanted. It is also a bit old, from 2006.
I then tried puppy Linux 2.2.0 from here. I could not figure out how to install a dhcp server and I realised I did not want to learn another package system. However ICS was very straight forward since it is a part of the Puppy firewall wizard.
I then tried Debian, but installations failed due to not being able to partition the disk, due to corrupt packages, not finding the kernel and not being able to install the bootloader respectively. All or some of these may have been due to overconservative parameters for disk size.
I then tried m0n0wall, but realised it was not open source, then tried Zeroshell but that one did not have a wizard for ICS so in the end I went with the for me more familiar Ubuntu instead.