This HOWTO is based on this forum post, but also explains how to set up internet connection sharing with wireless and DHCP.
Say you want to use your desktop as a router, so that the topology looks something like this:
internet -> [eth0 - desktop - wlan0] -> laptop
with the laptop being assigned a dynamic IP address. To do this (replace eth0 and wlan0 appropriately for your setup - eth0 is the connection to the internet, and wlan0 is the wireless for your LAN):
- First, install the packages dnsmasq, ipmasq, and dhcp3-server, either with Synaptic or with the following command line:
Code:
sudo apt-get install dnsmasq ipmasq dhcp3-server
This may warn you that dhcp3-server could not be started - as we haven't edited the configuration yet, this is normal .
- Assign a static IP address for the wireless card on the desktop machine by editing the file /etc/network/interfaces. Add these lines to the end of the file (if you already see wlan0 somewhere else, delete that first):
Code:
auto wlan0
iface wlan0 inet static
address 192.168.0.1
netmask 255.255.255.0
broadcast 192.168.0.255
wireless-mode ad-hoc
wireless-essid YOUR-NETWORK-SSID-HERE
You can also add encryption to this - see "man interfaces" for more details.
- Edit the file /etc/default/dhcp3-server by finding the line with INTERFACES="" and replacing it with
This tells the DHCP server to listen on the local network for connections.
- Open the file /etc/dhcp3/dhcpd.conf. Find the following lines:
Code:
option domain-name "example.org";
option domain-name-servers ns1.example.org, ns2.example.org;
default-lease-time 600;
max-lease-time 7200;
and replace them with:
Code:
#option domain-name "example.org";
#option domain-name-servers ns1.example.org, ns2.example.org;
#default-lease-time 600;
#max-lease-time 7200;
by adding a pound sign to the beginning of the lines. Then paste this at the end of the file:
Code:
subnet 192.168.0.0 netmask 255.255.255.0 {
range 192.168.0.100 192.168.0.200;
option domain-name-servers 192.168.0.1;
# option domain-name "internal.example.org";
option routers 192.168.0.1;
option broadcast-address 192.168.0.255;
default-lease-time 600;
max-lease-time 7200;
}
- Set up IP masquerading and forwarding:
Code:
sudo iptables -t nat -A POSTROUTING -o eth0 -j MASQUERADE
sudo sh -c "echo 1 > /proc/sys/net/ipv4/ip_forward"
sudo dpkg-reconfigure ipmasq
The default answers should be fine.
- Set up DNS masquerading:
Code:
sudo dpkg-reconfigure dnsmasq
- Start everything up!
Code:
sudo ifdown wlan0
sudo ifup wlan0
sudo /etc/init.d/dnsmasq restart
sudo /etc/init.d/dhcp3-server restart
If everything went well, you should now be able to get internet from a laptop just by connecting to this network!
Note: If the settings aren't saved after a reboot, try this:
Code:
sudo sh -c "echo \"net.ipv4.ip_forward = 1\" >> /etc/sysctl.conf"
Hope you enjoyed, post any problems and questions here
Bookmarks