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

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 running the latest Raspbian Wheezy
  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

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

 

 

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.

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 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

Please let me your feedback or questions through comments.

Thanks 🙂

References:

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

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

  1. Hi there !
    I’m new to RPi, and I managed to connect my laptop to the Pi in headless mode (with direct SSH through the ethernet cable), but I couldn’t connect it to the internet, although I followed your indications. I always get the ping error “ping: unknow host name”. What can I do to fix that ?

    Thanks ! 🙂

  2. If you are having trouble accessing the sharing tab options on your wireless connection try enabling the microsoft virtual wifi adapter. Look at this instructable:

    http://www.instructables.com/id/How-to-Set-Up-a-Wireless-Hotspot-Windows-7/step1/Step-1-Enabling-the-Microsoft-Virtual-WiFi-Minipor/

    The command I used was:
    netsh wlan set hostednetwork mode=allow ssid=yourssidname

    Just replace yourssidname with whatever name you want the virtual wlan to be. The name was important to me. It wouldn’t work without it.

    Thanks for the tutorial!!

  3. Hello Anwar
    You have written perfect tutorials for us.
    I’m very thankfull for your efforts.
    I have followed your tutorials on direct connected Rasp Pi to computer via ethernet cable, it all work seamlessly.
    However I’d like to have Rasp Pi’s independent internet connection via wifi (connected direct to wifi router, instead connected to computer via internet connection sharing), while in the same time the rasp pi also can be accessed via ethernet cable to computer.
    So, the idea is that the rasp pi has its own wifi adapter, its own power (not depends to computer usb’s) thus after the computer executes rasp pi command (example: downloading a large file), user can then shut down the computer while the rasp pi keep downloading the file because it has it own internet connection and its own power.
    Can we do that? How is the internet/ ipv4 thing setup?

    Thanks in advance

    1. If you’d like to have the Pi connect to the Router, you may use a USB WiFi dongle and have it setup using wicd-curses utility on the Pi. I’ve not tried a simultaneous connection on WiFi and Direct Access Lan; However, what I’ve tried is connecting the Pi to the Router via WiFi and LAN at the same time. You can then connect your Computer to the same network and schedule large file downloads.

  4. Thanks for the explanation. Much better than to install additional software on the
    Windows Laptop.
    A note: Windows has changed the Ethernetadapter to static after sharing the Internetconnection of the WLAN.
    So I had to change the cmdline.txt and take the new address.

    1. Yep, Windows sometimes assigns a static IP after WLAN interconnection. Instead of again changing the cmdline.txt file, you can plan at simply changing the adapter settings back to Obtain IP Automatically.

  5. i got a little problem here
    my local area connection cable is said to unplugged even if i have connected it
    when i connect my rpi it connects to Ethernet

    1. I also faced this issue recently but don’t remember why it occurred and what I did to resolve it 🙁 Do you have admin rights on your PC?

      1. Hmmm. I haven’t moved to Win 10 yet so can’t debug it at my end. Can you try bridging the connections instead of sharing them?

        1. Have you made sure that the Obtain IP Automatically radio button in the LANs Network Setting is set to Automatic after enabling the Share feature of the WiFi adapter?

  6. When i connect my raspberry pi3 with raspbian jessie with pixel installed on my sd card to the laptop via ethernet, there is no detection of network. However, if i edit the cmd.txt file and add an ip address like 192.168.137.10::192.168.137.1, only then i can see unidentified network on my laptop. However whenever i try to use it to access putty.I’m unable to do so..Could you please help me in this?

  7. Whenever i install the raspbian jessie with pixel or raspbian jessie 2016/5/27 on my sd card, put it in the raspberry pi 3 and connect ethernet from my laptop to rpi3, do sharing from wireless to local area connection, the laptop does not even locate that there is a local area connection. If i modify the cmd.txt file from the sd card by adding for example 192.168.137.10:192.168.137.1, then after rebooting there is unidentified network which i can see from my connections. However even after i go to local area connection and go to ipv4 and set it to 192.168.137.1 and subnet mask is automatic as 255.255.255.0, whenever i want to connect to rpi via putty, it is not working. Also i noticed that the subnet mask for wireless and local area network is not same. However whenever i run my previous microsd card having raspbian jessie 2016/5/27 which i did before, it has no problem to login via putty. So i presume that the error here is not linked to the subnet mask.Could anyone please help me out with setting this up?

Leave a Reply