Search

Wednesday 16 April 2014

Sharing Wi-Fi Internet Connection between Windows PC and Raspberry Pi : A Complete Easy Guide

Here is hassle-free, simple way to share an internet connection. Spent a lot of time to enable an internet on my Raspberry Pi through my Windows 7 based PC. Unfortunately didn't found the easiest guide on internet.

This post simplifies all. This post is also written for my future reference if I need to re-set the settings on my Pi.

So here is the list of what we need, and what not.
I assume that you have followed this post. (Meaning your Pi is having expanded root_fs)

What we need:
1. Windows 7 based PC/Laptop with ethernet port
2. Internet Connectivity
3. Putty(Download)
4. SD Card Reader (either inbuilt or an add-on SD Card reader)
5. Raspberry Pi (Obviously!)
6. An Ethernet cable (Must)
7. Editing of cmdline.txt in /boot file.

What we DO NOT need:
1. DHCP Server for Windows
2. No need to set Fixed IP address on adapter settings in Computer
3. USB Keyboard/mouse (we will use desktop/laptops's peripherals indirectly)
4. HDMI/RCA enabled Display

Here we go!

Step1:
Follow this link if you are setting up Rasperry Pi first time.
If you have already expanded Root_FS go to Step 2.

Step 2:
1. Remove SD card from the Raspberry Pi.
2. Insert SD Card to the PC's inbuilt or add-on SD card slot.
3. Upon opening, You will see multiple file's on the Disk.(The size of the Removable Media may be upto 20MB)
4. Open cmdline.txt you will be able to see this text.



dwc_otg.lpm_enable=0 console=ttyAMA0,115200 kgdboc=ttyAMA0,
115200 console=tty1 root=/dev/mmcblk0p2 rootfstype=ext4
elevator=deadline rootwait


5. Modify this file by putting the static IP of Raspberry Pi at the end of the line:



dwc_otg.lpm_enable=0 console=ttyAMA0,115200 kgdboc=ttyAMA0,
115200 console=tty1 root=/dev/mmcblk0p2 rootfstype=ext4
elevator=deadline rootwait ip=169.254.0.2

This is the static IP we provided for the Raspberry Pi. All the time from now onward, you have to access your Pi using this address.(you can have range of IP : 169.254.0.2.to 169.254.255.255 )

6. Save this cmdline.txt file and safely remove the SD card from computer and insert it into the Raspberry Pi.

7. Power-ON the Raspberry Pi, meanwhile connect the Ethernet cable to the Pi and Windows 7 computer.
    - You will see the multiple status LED's ON now; which indicates the Ethernet cable connected to it.

8. Easy Tweak
You can also check weather you Pi is connected with your PC or not by opening your command prompt on Windows PC by "ping 169.254.0.2"

9.Open Network Sharing center from Window's Control Panel > Change Adapter Settings > Right click on the Adapter where you are getting internet connection.(In my case it's wifi adapter, where I am getting an Internet connectivity.)
Click on Sharing Tab > Set to the "Allow other...." > Press OK

10. Open Network Sharing center from Window's Control Panel > Change Adapter Settings > Right click on Local Area Connection/Ethernet adapter > Properties > IPv4 Settings and Set to "Obtain an IP address automatically".

11. Open Command Prompt of Windows.

  1. Run > type cmd > Enter
  2. Enter "ipconfig"
  3. Check the IP of the "ethernet connection."
  4. Note Down the IP address. Mine it is showing 169.254.121.232 (Your's will differ)
  5. Close Command Prompt.
12. Open Putty (Download) and make these changes

Select Session :

Select "Selection"

Select X11:
13. Save the Configuration on Raspberry Pi. Now Load the Configuration.
14.Now you will be able to See the Login of Raspberry Pi
  1. Enter The ID and Password of Raspberry.
  2. Default ID, password are respectively : pi and rapberry
15. Type this command

sudo su

This will take you in the root user.

enter the command "poweroff" to shutdown the Raspberry Pi.

16. Now we need to again edit the cmdline.txt to enter the PC's ethernet address we got after connecting the raspberry pi.

17. Remove SD card from Raspberry Pi and Insert that in to the PC. Using same method open cmdline.txt and modify the code like this. 


dwc_otg.lpm_enable=0 console=ttyAMA0,115200 kgdboc=ttyAMA0,115200
 console=tty1 root=/dev/mmcblk0p2 rootfstype=ext4 elevator=deadline rootwait ip=169.254.0.2::your noted ip address
For Example::

dwc_otg.lpm_enable=0 console=ttyAMA0,115200 kgdboc=ttyAMA0,115200
 console=tty1 root=/dev/mmcblk0p2 rootfstype=ext4 elevator=deadline rootwait ip=169.254.0.2::169.254.121.232


In a simple language the :: between two IP states the interface and data sharing between these two IP's.

18. Save the cmdline.txt and insert the SD card back to the Pi.
19. Power-ON the raspberry Pi and do the Procedure as specified in Step 13 and Step 14.
20. Check whether the internet connection is active or not.

Enter this command:
ping -c 4 www.google.com

Success!!!

now you first type these command to make your Pi up-to-date.

sudo apt-get update
sudo apt-get upgrade


That's all.!!
Thank you!! Share the Link!!

10 comments:

Deven Patil said...

Wow, Perfectly working!!
Thank you.. you made my day.

Sean Bantor said...

this post works perfect, i am really able to download packages on my ras, unable to share internet through win8 though, please help. tried my gf's win7 and work flawless, thanks haha

SJ said...

please sir,put on steps for connecting RPi with internet for windows 8 OS users also.

Rushi Gajjar said...

Hello Sean and SJ,
I have got many mails regarding sharing internet to Pi through win8 PC's , I just tried yesterday with three win8 PCs, unfortunately it was a bad experience, though win8 is too bad for networking and wireless. Just go on with win7 PC.
Thanks.

Rushi Gajjar said...

Thanks Deven Patil. :)

Mamta Binne said...

I loved this postt , it works amazingly, i am trying with windows 7, is it possibl wid ubuntu?

Rushi Gajjar said...

Yes Mamta,
It is possible, but it has different way to log in to Raspberry Pi.

Just connect the Pi, and type this:

ssh pi@169.254.0.2

Enter Password.

That's It.

Rushi Gajjar said...

But Mamta, this will not share the internet though.

Kapil Parware said...

wonderful, tried, perfectly working, thanks rushi.

Unknown said...

in order to expect this internet connection in our rpi, which operating system should I have installed??(like wheezy,arch Linux,riscos,raspbmc,pidora,or NOOBS)....kindly answer me..