Sharing Internet over Wifi Between Ubuntu and Android

I searched the internet alot for a solution to connect my PC’s internet to my android phone by creating a hotspot. In windows you have softwares like connectify to make your life easy, But in linux things are not so easy, and I was never a windows guy. I hated to logon to windows just to share the internet over wifi to my android phone. I spend many sleepless nights trying to configure hostapd in Ubuntu and make it connect to my Android. And finally after days of searching and experimenting that wonderful day of bliss occurred to me. I have combined information I received from various sites in this post.

Initially when I shared my problem in certain groups I got the advice to set up an ad-hoc wifi network in ubuntu, but Android 2.3 and lower versions do not detect ad-hoc network so that means you either have to root your phone and ad the necessary features or you have to go for an alternative way.

I was definite that there will be an alternative because in windows there are softwares like connectify that do the job, and in linux we have hostapd.

So let me get directly to the point.

Open a terminal and type

#lspci

It will show the network adapter available to you.

#lsmod

Shows that it uses the ath9k drivers (this information may help you to google for setup information specific to your machine.)

Also

#iwconfig

will give you the name of your wireless adapter like wlan0. Please notedown this name as you will be needing it later on.

Now its time to install the packages.

Either fire up the ubuntu software center and install hostapd and dhcp3-server, or fire up the terminal and type

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

After this is done we have some serious editing to do so create a backup of all the files that are being edited.

At this stage you can reboot. And hopefully any device / laptop should connect to your wifi hotspots network via the network manager applet. On these devices search for the network “geekpeek” and type in the password.

To Connect to the internet we have some more procedures to follow.

In a terminal type:

#ifconfig

It will display the adapter name being used for connecting to the internet. I was using the LAN so my adapter name was “eth0”, if you are using modems then it might be “ppp0”

First we have to allow ip forwarding:

#sudo gedit /etc/sysctl.conf

Make sure the following line is uncommented and reads

net.ipv4.ip_forward=1

Save and close gedit. (reboot)

After reboot: Connect to the Internet and In a terminal type:

#sudo gedit /etc/rc.local

add this line just before “exit 0′′

iptables -t nat -A POSTROUTING -s 10.10.0.0/16 -o ppp0 -j MASQUERADE

Then reboot the system.

The eth0 should be changed to whatever adapter you are using.

Once this is done you can make other laptops connect to to youe new wifi hotpsot by assingning them IP addreses in the range of 10.10.0.2 to 10.10.0.16

To make and Android detect your wifi hotspot.

Goto the wifi settings

press the options key ( the left most key)

Select Advanced>Use Static IP

Give the IP address as something between 10.10.0.2 to 10.10.0.16

Gateway the same IP as your PC, In this case it is 10.10.0.1

Netmask as 255.255.255.0

DNS1 as 8.8.4.4

DNS2 as 8.8.8.8

Once this much has been set your android phone should be able to connect to your wifi hotspot and you can access the internet connection on your PC through your phone.

Now when you turn on your PC go to terminal and type

#sudo hostapd /etc/hostapd/hostapd.conf

Now I have made an application in Qt4 that provides a GUI to turn on and off the wifi Hotspot, You can get it from the download section

Share this:

Like this:

LikeLoading...

Related

About vineethkartha

Hi, I am Vineeth Kartha, I hold a Masters degree in Embedded Systems from BITS Pilani, Goa Campus. I currently work as a Software Developer. I am A free software promoter and electronics hobbyist. In my free time I do a little bit of birding and Wildlife photography. I love travelling, reading and blogging.

I followed the tutorial and I can connect from my android to my laptop with these 2 ip addresses off 10.10.0.1 (wlan0) and 192.168.0.100 (eth0) but can not get the internet to work on my android and not on my laptop

Hi vineeth
I followed all your mentioned steps,my HTC explorer connects to the network made,but the Internet does not work,I can’t browse internet or anything which requires internet.
I did everything mentioned in your post.I am using Ubuntu 12.04 LTS and my HTC explorer is on the stock ROM(not rooted).
I router is Nokia Siemens residential router 1600
I even have an inbuilt wireless adapter,but do not know which is it.
Well,if this does not workout,I actually want to use WiFi to use internet on my mobile,but my router reboots whenever I connect my phone to it,possible b’coz of IP address conflicts,as it used to connect to my ubuntu via wired and even by wireless,both.
Hoping for a quick reply.

I have the Nokia Siemens wifi router,I have a wireless adapter in my CPU cabinet,and I have this wireless option in my ubuntu which use this wireless adapter to connect to wifi by the nokia wifi router.
The prob. is whenever I connect my phone to the the router to access internet,it reboots,possibly b’coz of IP conflicts,but wired and wireless connection simultaneously connected works on Ubuntu,there is no IP conflict problem on my PC,it is only on my HTC.
I tried your method to make use of wireless adapter or router to make it as a hotspot to which I can connect my HTC to use internet,is there any other way possible where I do not have to root my phone?

Really thank you very much for your tutorial , i was very happy to see the (GEEKPEEK) at my android device connected to my ubuntu. but unfortunately , there is no internet in my android device. could you please help me to share the internet.

when i run the command to start sharing the wirless this line appears:
Using interface wlan0 with hwaddr 00:c0:a8:ee:f4:48 and ssid ‘geekpeek’

I am sorry to hear this, But I have made a post that has worked for me and some of my friends. So this was not posted without trying it out. And as a solution to your problem please read through the comments of this post, I have mentioned on how to change the unmanaged status.

sorry for being rude extremly sorry as recently in a week twice i have formated my system and wasted a much time to have all the things customized like shell extension app mozilla and chrome extensions , and lots more ……problem solved but still not able to share my wired connection ….thnking to go for a wifi router the better way its been a month searching for the thing to work out sorry once again…u r doing great job by sharing ur knowldege and promoting open soyrce

Hm. I had written MAC ADDRESS in brackets where the mac addresses are, but apparently, the scripts on this site thought it was a piece of code and did not display that. So, here’s the output of the sudo hostapd again:

hi Vineeth,
i followed your tutorial and did all steps as mentioned. i want to share my pc internet which i am using through wifi and i want to create a wifi network to access internet in my android phone.
my android phone is not able to directly connect to router because router is far away but my laptop is able to connect to router. so, currently, i am connected to internet in my laptop and now from laptop i want to connect to my phone. is it possible?
thanks

Thanks for the tutorial.
Since the port forwarding, I’m not able to use VNC or SSH throught the both interfaces. I need a screen for change something on the hotspot.
Do you know how I can have a remote access to the hotspot?