Thursday, September 6, 2012

Internet connection sharing

Informations from here:
https://help.ubuntu.com/community/Internet/ConnectionSharing

Use the Advanced Gateway Configuration Method. Basically:
- install dnsmasq
- stop the dnsmasq service
- edit /etc/dnsmasq.conf and add the following lines
interface=eth0
dhcp-range=192.168.1.50,192.168.1.90,infinite
dhcp-host=golfcart-lowlevel,192.168.1.3,infinite
- start dnsmasq

On Precise, the network manager has its own instance of dnsmasq running, so there is some conflict. The following might help get rid of it:
http://sokratisg.wordpress.com/2012/03/31/ubuntu-precise-12-04-get-rid-of-nms-dnsmasq-and-setup-your-own/

INSTRUCTIONS TO CONFIGURE THE MASTER COMPUTER AS A GATEWAY WITH DNS AND DHCP

The master computer connects to the internet via the 3G USB dongle. Other
computers on the LAN should benefit from that connection.

In the following:
- internet connection comes from broadband --> ppp0
- LAN is connected on eth3
- LAN subnet mask is 192.168.1.0
- master's IP is 192.168.1.2
- lowlevel's IP is 192.168.1.3



I followed the guide at:
https://help.ubuntu.com/community/Internet/ConnectionSharing


a) Using network manager, configure the ethernet connection to be static IP
192.168.1.2 : in the IPv4 tab set Method to Manual, Address to 192.168.1.2,
Netmask to 192.168.1.0 and leave the gateway field empty (or 0.0.0.0)
Click Routes and select "use this connection only for resources on its network".


b) DHCP / DNS
set up the box as a DHCP server so that whoever connects can get and IP and
connect to the internet.

sudo apt-get install dnsmasq
sudo /etc/init.d/dnsmasq stop

Edit /etc/dnsmasq.conf and add the following two lines:
interface=eth3
dhcp-range=192.168.1.50,192.168.1.90,infinite
dhcp-host=golfcart-lowlevel,192.168.1.3,infinite

the last line assigns a fixed IP to golfcart-lowlevel

sudo /etc/init.d/dnsmasq start



c) Install a script that will run at boot time to create iptables rules
sudo ./install
this copies load_iptables to /etc/init.d and sets it up as a boot up script
check that script to see how iptables are configured
to verify that they are: sudo iptables-save

the iptables script is:
# delete existing rules
iptables -F
iptables -t nat -F
iptables -t mangle -F
iptables -X
iptables -t nat -X
iptables -t mangle -X

# enable ip forwarding
echo "1" > /proc/sys/net/ipv4/ip_forward

# set up masquerading
iptables -t nat -A POSTROUTING -o ppp0 -j MASQUERADE
iptables -t nat -A POSTROUTING -o wlan0 -j MASQUERADE

# save these rules
iptables-save > /dev/null
d) configure client to get their IP via DHCP

No comments:

Post a Comment