Tuesday, May 11, 2010

Internet Connection Sharing through WiFi with Ubuntu PC as a gateway

The Problem

I have Ubuntu installed on my notebook computer(from now onwards, I will call it host computer in this post) which has a wired ethernet connection to a broadband internet service provider. I want to have a WiFi network broadcast in my room using my host computer so that any other notebook(guest) or smart phone with WiFi capability in the vicinity can connect to the broadband internet with host notebook working as a gateway.

The solution 

I had this problem from long ago since I wanted my broadband to be shared on my Sony Ericsson P1i. and I searched whole of the internet to find a solution but none actually worked.
Today after some fiddling I finally made my P1i to hook to the broadband with Ubuntu notebook working as a gateway.

This tutorial I am presenting has been tested on Ubuntu 10.04 Lucid Lynx and works perfectly fine. I can't guarantee it to work on earlier distributions because I myself had seen funny characters in WiFi network search list in P1i on 9.10 Karmic Koala and it never worked for me.

So, lets proceed.

1. Turn on your notebook's WiFi if there's a dedicated switch to turn it on. On my Fujitsu Siemens Amilo Si 3655 notebook, WiFi can be turned on using Fn+F1 key combination.

2. Click on the Network Manager icon(which looks like ) in the notification area and click Create New Wireless Network...

3. In the dialog box that pops up, put the network name as anything(I put WLAN). Set Wireles Security as WEP 40/128-bit key. In the Key box, enter any five digit number(I entered 31323). Click Create.


4. Now right click on the Network Manager icon and click Edit Connections... In the Network Connections dialog box that pops up, go to the Wireless tab. Click WLAN(or the network name you had provided) and click Edit.


5. In the Edit WLAN dialog box that opens up, set the Mode as Ad-hoc. Make sure the Connect Automatically checkbox is checked and in the IPv4 Settings tab, and Method is set to Shared to other computers. Now click Apply.

Your network is ready!!! Congrats!!! But thats only 50 percent of the hurdle complete. You might have reached this far several times using other tutorials and how tos available on the net. Lets proceed through to get the configuration details for the client pc/notebook/smart phone.

6. Open a terminal(for eg. by pressing Alt+F2 then typing xterm and pressing enter). In the terminal type ifconfig and press enter. Scroll down tothe place where wlan0 is written. Beside that, in the second line you will see three things viz. inet addr, Bcast and Mask. Note these things somewhere safely. In my case inet addr is 10.42.43.1 and Mask is 255.255.255.0. No need to note Bcast.

7. Use the following manual configuration details for the client system:

IPv4 Addr: 10.42.43.2(for a yet another machine use 10.42.43.3 and so on...)
Subnet Mask: 255.255.255.0
DNS Address1: 208.67.222.222
DNS Address2: 208.67.220.220

After doing all this above you may notice that the client computer connects to net successfully but the host computer isn't able to access any website. Thats because the network manager blanks the DNS records set in /etc/resolv.conf

To solve this, type

sudo gedit /etc/resolv.conf

in any terminal and there append

nameserver 208.67.220.220
nameserver 208.67.222.222

and save the file. Afterwards you will be able to surf the web on gateway computer as well, normally.

You may notice that the network manager blanks out /etc/resolv.conf every now and then and you've to manually edit it and add nameservers. This is a very common problem faced by GNOME users. To get rid of this just type the following command in terminal and press enter.

chattr +i /etc/resolv.conf



Now I am going to explain how did I connect my P1i to this network to use the broadband internet.

1. Turn on Wireless LAN 

2. Touch Scan for scanning for new networks You will see the newly created network WLAN listed there with a lock icon.

3. Now go to Internet Accounts by tapping More in the WLAN page and tapping Internet Accounts.

4. There tap More>New account>WLAN

5. Fill in the details as shown in the screenshot and create the connection.



6. Now in the Internet Accounts tab highlight WLAN and tap Edit, then tap More>TCP/IP>IP Config and fill in the details as shown in the screenshot. Similarly fill in the details for the DNS address. Press Done and come back to Wireless LAN. There scan for networks. You will notice a yellow star beside th network name WLAN. Hit the Connect button after highlighting WLAN.
7. Cheers!!! You are now connected to the internet. Open web browser and test your connectivity and enjoy.

10 comments:

snowman said...

why not just put the wifi card in hostap mode, set up a dhcp server (it is linux after all), and turn on the ipforwarding?

Prab97 said...

I have posted the GUI way. Not every user is comfortable with command line and terminal.

snowman said...

Yeah but you still have them opening up the console for ipconfig and changing resolv.conf. And theres a lot of info that needs to input on the client side. Dont get me wrong, I know how scared people are of the console, but this seems like a lot of work.

Prab97 said...

It seems to be a lot of work just because I've explained every step with screenshots and in detail. Practically, doing this on the computer is very easy.

Well, I used to try the command line way with the steps from Ubuntu site, on 9.10 Karmic Koala, but it never worked for me. My P1i phone used to show funny characters in the place of Network Name.

Can u please tell me your method? Write the commands here. I'll try on my machine and if it works for me perfectly, I'll post it here in another post(with your courtesy off course), for those users who prefer to type a few commands instead of fiddling through some dialog boxes.

Dhirendra said...

My connection keeps showing connection established / disconnected. What is the matter i cannot establish.
notably first time i did the settings it got connected amicably and worked well. But since one reboot nothings working. I did te whole setting again many times after delecting the old entries but of no help

Prab97 said...

@Dhirendra
Turn off your wireless adaptor. Most laptops have a dedicate key or a key combination to do so. On my Fujitsu it is Fn+F1. After turning it off, turn it on after a few seconds. It will establish the connection automatically.

Dhirendra said...

Guys That solution of turning on after turning off does not work.
It still keeps showing cooenctiin established /Disconnected at interval of about two seconds alternatively.

any help?..

Dhirendra said...

Hey!..
I am able to ping 10.42.43.2 . That is my nokia e 71. The message that E71 says when i try to open a page is "no dns reply"

Prab97 said...

Man, you are very near!!! Just fiddle with the settings in your phone.
By the way, which is your ISP on Ubuntu PC? DOes it use some proxy server or something to connect to net?

Olivia Princess said...

The sites you have referred was good. Thanks for sharing...
the best carding forum