Sharing WiFi Internet connection with Raspberry Pi through LAN/Ethernet (Headless Mode)

raspi

After having setup the Raspberry Pi to work in headless mode directly without installing anything on it as described in this post, we then tinkered on to share WiFi internet connection with the Raspberry Pi through the LAN/Ethernet connection which we established in our earlier post.

 

What you want to do:

  1. Share PC/Laptop’s WiFi internet connection with Raspberry Pi through LAN/Ethernet connected to Raspberry Pi

What you have:

  1. Raspberry Pi A+/B/B+/Pi 2 (If you’ve a Pi Zero, please try and let us know if this works on a Zero) running the latest Raspbian Wheezy. (I’ve not yet tried it with recently released Raspbian Jessie based off Debian 8. If you’ve been successful with this latest release, please post in the comment and I’ll update it here. Thanks.)
  2. PC/Laptop with WiFi Internet connection and a Ethernet Jack (LAN Connector / RJ45)
  3. A working SSH connection with Raspberry Pi (direct access, explained here)

What you don’t have:

  1. Display Device for the Raspberry Pi (HDMI enabled display unit / Old TV)
  2. Direct Internet connection for the Raspberry Pi (LAN or WiFi)

Extra Stuff you need:

  1. Standard Network Cable (Cat 5, Standard or Crossover)
  2. PutTTY Software (will be used to SSH into the Pi)
  3. SD Card Writer

Method 1: Using Network Bridging

Edit: [12:58AM IST, 1 Feb, 2016]: I just stumbled upon a super simple process of Bridging the connections and directly ping and access Internet on the Raspberry Pi without having to edit anything on the SD Card’s cmdline.txt file.

This process worked flawlessly for me and I’ve wrote a detailed tutorial here: https://www.hackster.io/Anwaarullah/sharing-wifi-with-raspberry-pi-using-a-lan-cable-ae1f44

If this doesn’t work, please follow Method 2

Method 2: Editing cmdline.txt file of Raspberry Pi SD Card

Edit: 2nd Jan, 2015. Added Video Tutorial:


A large part of this post assumes you’ve read the earlier post on directly accessing the shell on Raspberry Pi through a Ethernet/LAN connection. In this post, we’ll go about setting up the Raspberry Pi to access internet through the Ras-Pi’s Ethernet/LAN port from a Laptop/PC’s shared WiFi connection.

Method 2 Steps:

  1. Firstly, enable the WiFi adapter of the PC/Laptop and make sure it’s connected to a WiFi hotpspot. Open any Internet Browser and confirm internet access by opening any website.

raspi

Note: I’m using my Android device (Nexus One) configured as a WiFi hotspot J

  1. Now, go to Network and Sharing Center (Network Settings in Win XP) and then head to the Change Adapter Settings page. As shown below, we’re connected to ‘Wireless Network Connection’ on ‘Android 4’. Do remember the ‘Local Area Connection’ to which we’ll eventually share this connection

raspi

  1. Now, right click the above Network → Properties and then select the Sharing tab

raspi

  1. From the drop down list, choose ‘Local Area Connection’ and enable both the checkboxes and hit OK. Once done, head back to the Adapter Settings page and you should now see the Shared info message on the Wireless Network Connection

raspi

raspi

  1. Now, right click ‘Local Area Connection’ → Properties and then select Internet Protocol Version 4 and then click the Properties Button

raspi

Once the properties tab pops up, make sure that the ‘Obtain IP address automatically’ checkbox is selected. If not, check it and hit OK

raspi

  1. Now, power up the Raspberry Pi (making sure that the Ras-Pi and the Laptop/PC are connected to each other through the LAN/Ethernet cable) and wait a minute or two while the Ras-Pi boots. Now, repeat step 5 (previous one) to make sure ‘Obtain IP Address Automatically’ is still checked.
  2. Open up command prompt using the hotkey Windows Key + R and then typing in cmd or simply keying in cmd in the start menu (Win 7)
  3. In the command prompt, key in ipconfig and scroll to the top of the info shown

raspi

Note the IPv4 address which is 169.254.39.68 in this example. Please make a note of what you see as this will be required further.

  1. Now, power off the Raspberry Pi and plug the Ras-Pi’s SD card into a card reader and connect it to the PC. Once the disk opens up, open the cmdline.txt file in any editor

raspi

raspi

You’d probably have an entry as ip=169.254.39.71 which we set up in our previous post

  1. Now, to this entry, append the IPv4 which we got earlier preceded by two colons as shown below:

raspi

where the first half is the static IP for Raspberry Pi (169.254.39.71) and the other half is the IP of the IPV4 or Ethernet Adapter (169.254.39.68) which we obtained earlier.

  1. Save this file and plug the SD card back into the Raspberry Pi. Power up the Raspberry Pi and wait for a min or two. Establishg a direct SSH connection with the Raspberry Pi as explained in the previous post.
  2. Now, to verify if our Ras-Pi is Internet-Connected, type in this command in the Shell (PuTTY terminal connected to the Ras-Pi)

ping http://www.google.com

and you should see response from the servers as shown below:

raspi

Voila!!! Your Raspberry Pi is now connected to the World Wide Web :)

  1. Going one step further, lets direct access the Raspberry Pi’s desktop and open up the midori browser. Verify Internet connectivity on the Ras-Pi by opening any website.

raspi

 Note (Edited: 5th Feb, 2015): Midori browser is no longer coming pre-installed with the latest Raspbian version and has been replaced with Epiphany Browser. Please use that instead to verify internet connectivity.

Method 3:

Check out the comments. Many users have shared their own techniques which work on Win 8/10 flawlessly. Since I don’t have Win8/10, I can’t personally verify that. However, I intend to try out some of those methods on my Win 7 and will update here soon.

Please let me know your feedback or questions through comments.

Thanks :)

References:

  1. http://pihw.wordpress.com/guides/direct-network-connection/super-easy-direct-network-connection/
  2. https://anwaarullah.wordpress.com/2013/07/16/direct-access-raspberry-pi-shell-and-desktop/

P.S: Did this post help you? Please leave your feedback. If you’ve tried some additional steps that helped you in getting this working, please share so we all can benefit from.

If you’ve benefited from this post, please consider donating and help me buy new development stuff and resources. Thanks!

paypal-donate-button

Author: Anwaarullah

Designer, Developer, Maker, Speaker, Educator and Dreamer. ♥ Tinkering with Embedded, Android, Open Soft/Hard/Firm ware, Robotics and 3D Printer. Talk to me at syed {Shift+2} anwaarullah dash com

155 thoughts on “Sharing WiFi Internet connection with Raspberry Pi through LAN/Ethernet (Headless Mode)”

  1. Assalamualaikum, Mr. Anwar.

    I tried every step of the procedure. Alhamdulillah, i got it earlier. Once I upgraded the Raspbian Wheezy to Jessie, everything gone head-wire. I reformat back the SD to Wheezy, and subsequently, the internet connectivity unable to achieve. Same as other, I’m using Window 7 HP and be advised, my rpi able to Putty and Xming earlier. Very dire of your assistance thus I’m using rpi 2 for my final year project. And now, the project’s progress from 40% achievement down to 0%. Cant figure out which step I missed. Duly waiting for your assistance.

  2. Assalamou Alaykom Mr. Anwar,

    First, I would like to thank you for this tutorial. It is great.

    I am running Windows 10 on my PC and Debian Jessie on my Raspberry Pi. I followed all the steps but I wasn’t able to ping outside from my LAN. In fact, when I ping the RPi from the PC it goes well but the other way does not pass. I unchecked the Ethernet connexion from the “Protected network connexions” window and I was able to ping the PC from the RPi but not the Internet. So I probably think that the problem is coming from the Windows 10 Firewall.

    I would be grateful if you can help me fixing this issue. Thank you.

    Sincerely,
    Nizar

  3. i use raspberry pi 2 B+,i connect putty and work well,but after use wifi share option,i connect putty but it will appear connection time out..please help me get out of this.

      1. now i fix that problem,but when i use wifi share,and it connect to pi but i cant access to internet stil

  4. First of all, thank you! After attempting to use multiple guides your’s got things working for me. All the others failed to note you must include the static IP AND the Default gateway for the LAN cable in the cmdline.txt.

    Thank you so much for this detailed guide!

  5. Thank you so much Mr. Anwar for this tutorial….I have been trying to connect my rasp-pi to internet for 10-15 days using different guides and forums but it didn’t work out….your easy to follow tutorial made that happen….Thank you once again:)

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s