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

 

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

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/
About these ads

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

  1. am stuck here now…doesnt seem to connect. Please help me out ..followed all the steps.. any suggestions? thank you

    1. Sorry, I was in office so didn’t get time to reply. Have you had any success with it? This is a little tricky and requires lot of trial and error. If you’re still facing issues, lemme know and I’ll call or email you.

  2. Hey there,
    I’m having trouble with the wireless as well. My laptop is connected to my wireless router and when I go into wireless network connection properties -> sharing tab, there is no drop down.
    I’m using window 7.
    Hope I’ve given enough details… just message back if you need more info :)
    Thanks in advance.

    1. Hi Stephenie,

      You first need to configure your WiFi adapter to share it’s Internet. Right click the WiFi adapter and on opening the properties, you should be able to enable sharing. Once done, plug in the Raspberry Pi to the LAN jack of your PC and you’ll get this LAN as a sharing option in the dropdown.

      Lemme know if that works or not.

      1. Interesting, I don’t see the Dropdown in your image. Is that option locked down by your Admin if that’s an office workstation? Can you see that dropdown for other Networks?

  3. Thanks for the post,

    Unfortunately I am still unable to access the internet. I am using Windows 8 and the only difference in direction was there was no dropdown from Step 4 but after reading elsewhere I don’t believe that is the problem. And from Step 8 “Ethernet adapter Local Area Connection” is “Ethernet adapter Ethernet” instead.

    I’m connecting via SSH which I just got working by editing cmdline.txt. I appended the ip address from Step 8 to the end following directions. However, I still can’t access the internet. When I ping google.com I get “ping: unknown host google.com.” Any ideas?

    Thanks in advance!

    1. I have the same issue. I can ping each other, pc with windows 8 and pi – earlier I can’t ping from pi to pc but I disable windows built in firewall and than start working. But I still can not get access to Internet through my pc. I was googling for bot I can’t get answer.

    1. Internet connection didn’t work for me. When I have the network sharing enabled the Pi connection via Putty closes – am I missing something?

      1. Are you able to reconnect back to the Pi using Putty? Have you given a static IP to the Pi? Can you also try hard rebooting the Pi whilst it’s connected to PC thru Ethernet?

  4. I am having a little problem with connecting to the internet. I followed all the instructions exactly but when I try to ping a website i.e. google i get the error ping: unknown host http://www.google.com. I am using windows 8 with putty. What does this mean?

    1. I was similar problem. I connected PI with PC (Win8) directly via Ethernet cable, and my PC was connected to router via WiFi. I could ping PC and Pi but I couldn’t connect to Internet in my Pi. I decide moved my Pi and connect it to router using ethernet cable. My PI have static IP. I spent a lot of time on it before I could understand everything. If you have posibility to connect your Pi with router, this is the best solution for me. In Windows 8 I achieved only connection between Pi and PC.

  5. for windows 8 users after allowing other computers, u should see ipv4 properties of ethernet network and DONT check”obtain ip automatically”.. instead copy the ip(say 192.168.137.1) and edit cmdline.txt and add ip 192.188.146.205::192.188.146.2…it works.

      1. I did not understand the method Harsh mentioned to work in windows 8. Could you please explain the last line ?
        FYI, I followed all the instruction you mentioned in this guide. But unfortunately it did not connect to the internet. I am using windows 8.1 While using automatically detect ip I got the address as: 169.254.117.79 then in the cmdline.txt I added ip 169.254.117.81::169.254.117.79
        Can you please tell me how to resolve this by not choosing “obtain ip automatically” as Harsh told above? Thank you!

    1. When I don’t check ‘obtain ip automatically’ I get the default-set ip address as 192.168.137.1. In the cmdline.txt file, where should I be adding 192.168.137.1 to? should it be, following your example, ip=192.188.146.205::192.188.146.2::192.168.137.1? or be ip=192.188.146.205::192.168.137.1? Thanks for helping out!

    2. Hi, could you please elaborate a bit? I can’t seem to connect through Putty.
      I left the “Obtain address automatically” unchecked, and indeed it addressed a value of 192.168.137.1 to my RPi. You said to copy that address, but where do I fill it in?
      My network is on the range of 192.168.178.x, and my laptop has 192.168.178.20 (dynamic).
      Now what do I fill in in cmdline.txt and what do I fill in in Putty?
      I’ve tried several combinations but I get either “connection refused” or “connection timed out”.
      Thanks!

  6. hi,

    after fiddling around and watching LOTS of other webpages, I have found a infinitely easier way to get internet working through headless mode (even without editing cmdline.txt)!
    Indeed, go to your wifi settings, check “share connection”. Connect RPi through ethernet, and when you check those ipv4 properties, you will see Windows has probably given it some address like 192.168.137.1. Do not change this, as it will disable the DHCP settings for this connection!
    Now, if you open a terminal and type “ping raspberrypi.mshome.net” you will see it automatically resolves to an IP address.
    You can also use this in Putty to connect! Just type raspberrypi.mshome.net into the test field and voila! It worked on first try and I could even immediately ping http://www.google.com from the pi!

      1. I’m using Windows 8.1, but I guess it will be the same for 8 and 7 (though I haven’t tested that).
        Other forums I read said it should be possible to connect to “raspberrypi” but I could never find that address. Then when someone said it should be “raspberrypi.mshome.net” it magically worked.

    1. I’ve been trying this in win 7.
      raspberrypi.mshome.net hasn’t worked for me.

      what do you mean by test field in putty? did you mean host name?

  7. Hi Having same problem that seems consistent to the above posts
    no drop down box/list with LAN option in wireless sharing check box
    I am able to connect to putty and connect to PI and get vncserver up and running but no internet connection (have windows 7)
    Any help from anyone appreciated have spent quite a bit of time tryib=ng to resolve but with no luck
    Regards
    Sean

  8. Is there any way to use the laptop as a router or switch? I don’t want RPi to have different IP address (169…) than my home network (10.0.0.X). Is it possible?

  9. Hi,
    Firstly, I want to thank for the post. It is useful, indeed. But I have an issue. I’ve done all the things , I can connect my Raspberry Pi through SSH, ping Google successfuly but I can not open internet sites in Midori. It is failing all the time.
    What do you think causes this problem? Am I missing something? I’m using Windows 7. Can you help me? Thanks.

      1. Once I was able to connect google.com and several other sites. That was approximately one or two weeks ago. I haven’t formatted my SD Card or changed any settings as far as I remember.

  10. hi i really need helping to connect my raspberry to internet conection. i use ssh for display rpi. i want sharing internet conection from the laptop to rpi with utp cable. my laptop conect to internet with wifi tethering form my handphone. internet was successfull to access lan adapter from sharing conection. but why if i want to update in my raspberry always failed. thanks for read my question. please for answered :)

    1. My /etc/network/interfaces file would be the default one without any changes :)

      Getting this setup running sometimes takes a dozen tries. Were you able to first get the Direct Access as described in my previous post working?

    1. Hi,

      Thanks for your article. I used to have this working perfectly. Then I set up wifi on the RPi and was connecting using that. Now I’m trying to get headless with shared internet working again…
      The RPi is running Raspian
      My laptop is running Windows 7 Pro 64
      I’ve got the headless part working fine. I can ssh into the RPi and control it from the laptop
      …but I can’t get the shared internet working
      I can ping the RPi from the laptop
      I can ping the laptop from the RPi, but only if I disable Windows Firewall for the public network (which is how the RPi appears). If Windows Firewall is monitoring public network I can’t ping the laptop from the RPi, even though I have enabled ICS and Port 22 in Windows Firewall.
      Even with Windows Firewall disabled, the RPi doesn’t have an internet connection.
      The end of cmdline.txt reads ip:169.254.226.228::169.254.226.226 I tried changing the last number of the first part to 222 and headless still works, but ICS does not.
      I suspect the problem is either in Windows Firewall, or that there is something hanging around in the RPi from when I had wifi working (though I have tried to put /network/interfaces back by #commenting out the wlan lines)- do you have any ideas?

      Thanks for your help
      Ian

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