Friday, November 23, 2012

Easy Way to Share Internet from Ubuntu to Mobile Device

If you are trying to share your internet connection between computers, you can easily to make ad-hoc connection on your laptop and share it to the others. But it's getting hard when you tried to share your laptop internet connection to another mobile devices like Android or Windows Mobile. Because not every devices can read ad-hoc access point across platform. Here it is I'll show you  how to make it possible.

I have to inform you what I've been use to do this action:

1. Asus EeePC 1015 BX (netbook) with Atheros series WiFi
2. Android Tablet with Gingerbread version 2.3.4
3. Ubuntu 12.04 LTS Precise

First thing you need to install some supporting application. Open the Terminal console you can found it on Unity Menu or press Ctrl-Alt-T on keyboard. Then type this following command:

sudo apt-get install hostapd
sudo apt-get install dhcp3-server

or copy the command above and hit Ctrl-Alt-V to paste on Terminal

create hostapd.conf file with this command:

sudo gedit hostapd.conf

Then add this following text on hostapd.conf file:

wpa_pairwise=TKIP CCMP

Save it.

Now edit dhcpd.conf file

sudo gedit /etc/dhcp3/dhcpd.conf

And add this following text to file:

option subnet-mask;
default-lease-time 600;
max-lease-time 7200;

option domain-name-servers, ;
subnet netmask {
option broadcast-address;
option routers;

(no need to worry if the file is empty, just add those text above)

Edit dhcp3-server file : 

sudo gedit /etc/default/dhcp3-server

Find INTERFACES="" text and change it to INTERFACES="wlan0"

Now you have to forward your internet connection by editing this file

sudo gedit /etc/sysctl.conf

Remove the hash symbol on # net.ipv4.ip_forward=0
then change the value from 0 to 1

Then edit rc.local file : 

sudo gedit /etc/rc.local

Add this text below :

/sbin/iptables -t nat -A POSTROUTING -o ppp0 -j MASQUERADE
ifconfig wlan0 inet netmask
hostapd -d hostapd.conf &
/etc/init.d/dhcp3-server restart

Just before "exit 0" script.

If you want to share internet connection on LAN, just replace ppp0 with eth0.

At this step, you can reboot your computer.

Connect the computer to the internet with USB modem or LAN then run the hostapd application to share the connection from WiFi with this command from Terminal console:

sudo hostapd ./hostapd.conf

You computer is already to an Access Point. Next, you have to setup your mobile devices.

Turn on WiFi on your mobile and scan for available network. Choose your already made hot spot and fill the password. If your mobile device can't obtain IP address. So you need to input  it manually.

You can put this address on your mobile:

IP address : to 
Netmask :
Gateway :
DNS 1 :
DNS 2 :

It shoud work now.

Filled Under:


Post a Comment