miércoles 25 de mayo de 2011

Share internet with Ubuntu 11.04



This tutorial explains how to share internet from wifi (wlan0) to ethernet (eth0). So the
internet connection comes from the wifi and we share to other computer via ethernet.

edit /etc/network/interfaces, add statis IP to eth0
auto eth0
iface eth0 inet static
        address 10.0.0.1
        netmask 255.255.255.0

Restart network
sudo /etc/init.d/networking restart

Install dhcp3 and dnsmasq
sudo apt-get install dhcp3-server dnsmasq  

At this step is possible to get an error, we need to configure dhcp3 server. Edit /etc/dhcp/dhcpd.conf add this
subnet 10.0.0.0 netmask 255.255.255.0 {
  range 10.0.0.2 10.0.0.254;
  option routers 10.0.0.1;
  option domain-name-servers 10.0.0.1;
}
Now restart dhcpd
 sudo /etc/init.d/isc-dhcp-server restart

At this point we need to enable ip forwarding

sudo iptables -A FORWARD -o eth0 -i eth1 -s 10.0.0.0/24 -m conntrack --ctstate NEW -j ACCEPT
sudo iptables -A FORWARD -m conntrack --ctstate ESTABLISHED,RELATED -j ACCEPT
sudo iptables -A POSTROUTING -t nat -j MASQUERADE 

now save the iptables commands:

sudo iptables-save | sudo tee /etc/iptables.sav

sudo sh -c "echo 1 > /proc/sys/net/ipv4/ip_forward"

Make a permanent ip_forward=1,edit /etc/sysctl.conf and add these lines:

net.ipv4.conf.default.forwarding=1
net.ipv4.conf.all.forwarding=1

please if you need an easy we to share internet, comment a link!!
Google Analytics Alternative