Super Easy…Direct Network Connection

In an attempt to make the whole direct connection process a little easier, I’ve provided some quick scripts for switching the settings.


The direct connection script assumes that your Network Adaptor on your PC is usually set to AUTO – see the other Direct Network Connection pages for details on how to check this.

Also, it is recommended if you change any settings on your PC, that you take detailed notes, so you are able to undo them (including IP address and gateway settings).

The settings:

We will be able to set-up and switch between three configurations.

  1. Auto DHCP – cmdline.normal

This is the standard settings for networking.  By default (if you’ve not changed it anywhere else) this will allow you to simply connect a network cable to a home network and use it (assuming it does that normally).  The Raspberry Pi will automatically be given an IP address by the network.  To connect using SSH you will need to know this IP address (or you might be able to use the hostname (default: raspberrypi)).

  1. Direct –

This setting forces the Raspberry Pi to have a fixed IP address (default: which when connected directly to another computer, should allow a direct network link.  To connect using SSH, just use this IP address (assuming your network adaptor is set to auto/DHCP).

  1. Internet Connection Sharing – cmdline.internet

This setting requires some additional configuration, as when you enable ICS to share the internet from one network device (i.e. Wifi) to another (i.e.Wired) it will provide a suitable address for the device to use.  The Raspberry Pi will need to have its own IP address set in the same range (i.e. 1st 3 numbers matching) AND the IP address of the shared connection (i.e. the address of the Wired adaptor).

A note for N.O.O.B.S. users:

Users of NOOBS (the New Out Of the Box Software) will have a slightly different SD-Card structure.  The NOOBS system (once installed by running on a Raspberry Pi the first time) will create multiple partitions on the SD-Card (typically 4 for a single OS install).  You will need to run the NOOBS setup on your Raspberry Pi before the boot partition (which contains the CMDLINE.TXT is created).

Unfortunately, Windows is only able to see the partition which has the NOOBS recovery system on it.  This means if you use NOOBS you can no longer change the CMDLINE.TXT file for the Raspberry Pi by plugging in your SD-Card and changing the files in Windows.  You will still find the /boot/CMDLINE.TXT on the Raspberry Pi in the same location, so you can still use the same scripts for that when running the Raspberry Pi.

If you REALLY need to change the CMDLINE.TXT using windows (because you don’t have another screen/keyboard), then you can use a Linux Live CD or a Virtual Machine to read the SD-Card and change the CMDLINE.TXT as required.

Alternatively, if you have a spare SD-card you could set that up with a normal image to use a direct connection and modify the NOOBS card by using a SD-card reader on the Pi (find the card located in the /mnt/ folder).

Installing and using the scripts:

On windows:

If you’ve not already put the files on the SD-card:

  1. Download the following zip file ( and unzip it to your SD-card – you end up with a single folder called “network” and this must be located on the SD-Card itself.   The “network” folder should now contain the scripts and files (around 9 files currently).

Once the files are on the card:

  1. Ensure you update the cmdline.internet file if you intend to use this (see below).
  2. Depending on the setting you require, run one of the WINset–.bat files within the network folder.  NOTE: It may require you to “Run as administrator” – on the right-click menu (if executable files are blocked from being run on external media).
  3. Safely Eject the SD-Card from Windows Explorer.
  4. For Direct or ICS: Connect the Network cable DIRECTLY between the RPi and the PC.
  5. Ensure you put your SD-Card back in.
  6. Power up the RPi.
  7. Use Putty SSH to connect using the IP address set in the files (Direct IP address is a default of
  8. If you have problems, you may need to disable the PC’s WIFI initially (to stop Putty trying to use that for the connection).  You can re-enable it after.

On the Raspberry Pi:

If you’ve not already put the files on the SD-card:

1. Download the files using the following command: 


  1. Extract the files to the /boot directory:

sudo unzip -d /boot/

  1. Optional, remove the zip file (no longer needed):


Once the files are on the card:

  1. Ensure you update the cmdline.internet file if you intend to use this (see below).

  2. To switch IP address settings:

. /boot/network/

  1. If you change the setting, you will need to reboot to apply the change:

sudo reboot

Internet Connection Settings – cmdline.internet:

NOTE: You MUST update this file with the settings that get given to your PC’s network adaptor AFTER ICS is enabled.

ICS is still experimental – I will update these instructions if found to work.

  1. You will need to enable ICS on the connection with your internet connection (the WIFI) and link it to your direct connection to the RPi (the Wired connection).  You will then need to take a look at the Wired Connection’s settings (which will have changed to allow ICS to work).

  2. Change the ip= part of the file as follows:

ip=A.B.C.10::A.B.C.D (where A.B.C.D is the PC’s network LAN adaptor settings (AFTER ICS is enabled)).  The A.B.C parts must match!

Where A.B.C.10 is RPi address and A.B.C.D is PC address – which the Raspberry Pi will use as its internet Gateway.


These setting may change when you change networks or next time you enable ICS (so ensure you double check if you have problems that the adaptor setting hasn’t changed).

Please let me know how well this works for you in the comments below.  Thank you!

  1. anwaarullah says:

    The Internet Sharing part works pretty awesome for me! Thanks meltwater, this helped me a lot and also prompted me to write a step-by-step tutorial.

    Thanks again🙂

  2. Ben says:

    Thanks a lot for your tutorial ! It’s almost working for me.

    The direct connection works for me (the raspberry is SSH connected to my laptop using ICS and the right IP config), but i can’t access the internet on the raspberry (i.e. when I SSH “ping“, I obtain : “ping: unknown host“)

    Do you have any idea to work this out ?

    • Ensure you have set the laptop’s IP as the gateway on the RPi. Also see if you have a firewall which may be blocking. Finally, if you have a proxy (school/work) you will still have to set that on the RPi too.

      • mark says:


        I have the same problem. The internet connection is working it can however not resolve the names, so it looks like there is a DNS problem…?
        note: I can ping (the ip address to which resolves)

        any idea on how to solve this?

      • Networking can get rather complicated to sort out. It does sound like DNS problem, is your router acting as a DNS server? Any idea what your laptop is using, can you ping the same DNS servers? Alternatively, if you can ping googles DNS servers you may be able to add them as DNS servers on the RPi to use (just remember to use IP addresses to specify them or you can end up with the DNS settings trying to use itself to get the servers…).

  3. mark says:

    Thanks, I replaced the nameserver in /etc/resolve.conf with (google’s public dns) and everything is working now!

  4. vasanthkumar says:

    im using raspberry pi model b
    i want it to connect on the network of my college i do require the procedure in order to do so
    i have edited the bashrc file but couldnot resolve it

    • Are you trying to use direct connection (via a network cable direct to a computer or remote connections, using his network)? Or are you having problems with getting internet?
      In each case you can check connections using Ping to see which devices you can connect to, once you can ping things you have a fighting chance.

  5. vasanthkumar says:

    sir ive been using a dhcp network whose ip is varying randomly
    more over i need to configure the proxy on to the raspberry pi
    for installing the updates as well as to put it on the network for the Master degree project work.

    • You can set a fixed IP on the router if you have access.
      When you set the ip address using cmdline.txt that will give you a fixed IP, but you will have to make sure it is available on the network (some routers will have a range of static addresses available outside of the DHCP range). If you are lucky though you may be able to use the Raspberry Pi hostname for connections (find it with “hostname” default is raspberrypi). For me it depends on the network and what connection type to if it is found.
      A basic solution is to set the Raspberry Pi to send you the ip address each time it starts. You could even use a console cable to ssh directly while it is on the network.

      Also try out a program called Bonjour, which is designed to help with network discovery (I’ve not used it myself though), but that may help hostnames to work correctly.

      I think the instructions for the proxy on here should work for you if you have the proxy details. Again, check using ping that you can connect to other computers on the network, that you can ping the proxy and finally you can ping outside.

  6. Akhilesh says:

    hi meltwater,
    I followed the steps that you have given but still i get the error “Unkonwn host
    Please suggest some remedy.


  7. domdog says:

    Thank You!
    Used this and your Raspberry Pi Remote Connections – Without A Network! page for connection from my Mint 15 to my Rpi Bv2. It’s much simpler on Mint(thanks to the ubuntu comment on the short version of the above mentioned page) the address did start with 10.x.x.x. My samba share is all screwed up but I just ignored that after I saw the ping was working both ways. This saved me getting a wifi dongle. I just didn’t see the point since I wasn’t intending to use my Rpi on the web too much. It did allow me to get it updated. Once again thank you.

  8. Mike says:


    Thanks for your explination. I am using ubuntu 13.10. I would connect my raspberry pi to use internet via LAN sharing with my laptop.

    How do I follow your post?

    Now I can use ssh on the pi but can’t use internet.

    I have files on the SD-card. The file cmdline.txt has been copied and renamed to cmdtext.normal,

    add ip address for pi on the file.

    Do i need to put other files ?

    Please help

    Thanks a lot

  9. Menna says:

    I am using windows 8 I went through the steps
    My pi’s ip
    The lx session shows that the last login from
    i can ping put nothing else

    • Menna says:

      pi@raspberrypi ~ $ netstat -nr
      Kernel IP routing table
      Destination Gateway Genmask Flags MSS Window irtt Iface UG 0 0 0 eth0 U 0 0 0 eth0

  10. Jeppe Rask says:

    So i can see others have issues with the internet as well as me. When i change my laptop’s IP-adress to (one i’ve chosen), and with the gateway, i’m not allowed to go on the internet, eventhough the Wireless-Card in my laptop is still set to optain an IP-adress automaticly. So i have to disable the wireless in order to talk to my Pi. Next up, when i connect my pi directly to the internet, its neither able to connect. Is there a way to make it possible to both go online, and to keep the connection between the pi and the laptop? This goes for both the pi and the laptop, eventhough i cannot have both cable for laptop and internet in the pi. Hope this is not too confusing. Thanks in advance.

    • Disabling the wifi only seems to be required for initial connection (the computer treats the first active connection as a primary connection).
      Adding internet is a slightly different process.
      Have you gone through the steps using ICS? That will allocate a new IP address which internet should be available on and this should be set as the gateway. Just remember that the Raspberry Pi will need a suitable IP address in the same range.

  11. Ken DeWitt says:

    Have you tested this on arch linux for raspberry pi?

    • I haven’t, since I don’t use Arch Linux that often. The principle should be the same, the direct LAN address selected by your PC should always be the same, so if you set your Pi to be in the same range it should work.
      Let me know how you get on.

  12. Chinmay says:

    Sir, I followed all your steps but still unable to connect to internet. IP of Rpi is and static ip of my Ethernet connection is set up to When I use automatic address then it assigns ip What to do in such cases ? If I assigned static ip then what should be default gateway ?

    • If your PC has been allocated by your router, then that should be the gateway you set on the Raspberry Pi. Remember you’ll probably need to set your Pi IP to 169.254.118.xx (if your subnet mask is, if it is you may be fine with your original IP).
      Hope that works for you!

  13. Daniel says:

    Thanks very much for this – I am trying really hard to follow it and am stuck with finding the cmdline.txt file. I was using Windows but couldn’t find it on my SD card, so installed Ubuntu and opened my pre-purchased Raspberry Pi SD card with that. However, I STILL can’t see the cmdline.txt file there. Should I be able to see it by just opening the SD card through UBUNTU or do I need to use a program?
    Trying really hard to get started with my Pi and 3 days have gone by without even being able to boot it. I would really appreciate your help!

    • Once you have run the NOOBS install your sd card will contain multiple partitions. Windows is only able to see a single partition on an SD card.

      Ubuntu should allow you to see all the partitions, one will have the boot files. You can confirm this by running gparted and checking the card.

      If you have not installed NOOBS then your card will just contain those files only. It will need to be installed using a RPi before you can access the boot files.

      See the NOOBS github site on how to do an automatic install if that is the case.

      • Daniel says:

        I don’t have a monitor, so I haven’t ever run the RPi. And no, in Ubuntu, I can only see the exact same files as when I open it on windows… by chance I have 2 copies of the NOOBS sd and its the same with both of them. I am not normally this hopeless with setting things up! So just to be clear… if I haven’t ever used my RPi… will copying the ‘network’ directory to the USB change anything? Thanks again!

      • Daniel says:

        ok.. I think I understand what you are saying now – a huge misunderstanding on my part. Please ignore other comments

      • No problem at all. Those guides were written before NOOBS was released so I only adapted the instructions. (I’ve added a little extra to the instructions to make it clearer).

        But yes, to be clear, NOOBS needs installing first on a Raspberry Pi before you can adjust the network settings.

  14. Daniel says:

    So, here is what I have done and it isn’t working. I am using Windows. I have checked my adapter (tcip 4) and it is set to auto, as you stated. I have a NOOBS card, which I have unzipped and added the ‘network’ directory to. I have chosen the ‘direct’ method and run the .bat file. I installed Xming on my laptop and have also run Putty, putting in the IP info for ‘direct’. I have also disabled my wifi. I connected my network cable between my laptop and put the sd back into my pi and booted it. It comes up as an ‘unknown network’ but ultimately won’t connect to it. I load my putty SH settings (for direct) and it says no connection and I am left with a terminated black screen. I have no idea what I have done wrong – this is extremely frustrating. Can you please help?

  15. I am having trouble executing the line ./boot/network/ is there something that i have to put before this. for example sudo ifconfig eth0?

  16. embeddedlinux says:

    Hi This looks actually quite good. I think you are saying add the “network” folder is in the “boot” section that is left as FAT32 in Raspberian this is important because in Windows you can only see into the boot folder. The Linux File systems cannot be seen.

    Now I want to point out that locked down laptops (which have McCaffee boot encryption and such like) will not let you use the Wireless adapter to share with to the wired adapter in Windows 7 Pro. Per the below link. I hear similar issues happen in Windows 8.1 as a matter of course.

    Changing boot from the hard drive to a Flash drive with Windows 7 pro installed works just fine but it will no longer work on the corporate network. At that point you know it was a script from some corporate networking item that just does not work in a known way.


    • Unfortunately, NOOBS moved the boot partition so you can’t see it any more on a windows PC, so what was a nice useful work around become more difficult.

      Yes there are issues if you do not have admin-rights, at some point you have to accept perhaps they are set for a reason etc. There is always serial, video-in adaptors or some other way.

      My own preferred method is to use a wifi dongle on the raspberry pi and use my phone as an AP (or with a router when at home). Added bonus is you then just need to power on the Pi and that is it.

      Of course you end up with the catch-22 of how to enable and setup wifi on the Pi without doing it manually with keyboard and display.

      Well…that is where the Pi-Kitchen comes in, it sets it up for me (plus everything else). I’m happy it works for me, so now in the process of sharing it!

      • embeddedlinux says:

        I really meant it. This is a beautiful thing. I appreciate the time you spent with it and as an embedded developer I like commenting on what does work, (The whole thing) what doesn’t work (Locked down laptops with dns typically showing a list of pre-given routes and not saying automatic on IPV4 properties DNS Advanced) to avoid other people having to work out what is happening. I am looking forward to your pi kitchen. I have other laptops that I am the administrator that don’t have any problems with Win 7 Pro. My best guess is that the firewall on McAfee is not only not settable but you can’t find it. It’s hidden in McAfee AV?

      • Sorry about the delay with Pi-Kitchen, I have the next parts ready to go.
        However, currently preparing for a workshop I’m running next week for Digimakers @Bristol.

  17. sararahmati says:

    Thank you for this beautiful tuturial it worked 😊😊

  18. Girish says:

    I followed all your steps and was able to connect to internet three months ago.
    But now I could not.Dont know why!
    I could ping my laptop with pi using ssh and the other way also.I am using my android phone as wifi hotspot.I could connect to internet in my laptop using that.But not from pi.😦
    Could You Please help me as soon as possible.I need to install softwares.Please help me.

    • Will see if I can think of something. Have you started using a newer version of Raspbian?
      I’ve also used this setup previously so will see if it still works for me too.
      One thing you could try is to connect your laptop to the internet via your phone and then use internet connection sharing to share it with the Pi (use a direct wired connection to the laptop and set the IP address of the laptop -when ICS is enabled- as the gateway on the Pi).

      • Girish says:

        No.. it is the same version as i used before.The gateway of Pi is the same as that of laptop IP already. Do i need to set it again even then?

      • Enabling ICS will change the IP address of the laptop so make sure it is the same.

        An alternative is to use a wifi dongle and connect directly to the phone from the Raspberry Pi (although issue would be you will probably need to install drivers from internet…).

        You could try downloading the .deb files you need and manually installing. See the Pi-Kitchen recipe 006 for Wifi Drivers which uses this method.

  19. Girish says:

    This is the kernel version i use:
    Linux raspberrypi 3.12.22+ #691 PREEMPT Wed Jun 18 18:29:58 BST 2014 armv6l

  20. Girish says:

    After enabling ICS,the IP address of the ethernet adapter remains the same though the IP address of the Wireless LAN adapter is different.Which address i should use now?

  21. Girish says:

    I have the following in cmdline.txt,

    here is the IP address of the laptop set by ethernet adapter,which is also the gateway of pi. Is that right?
    In my windows 7 laptop, the ip address for both wireless and ethernet address has been set to “obtain an address automatically”.

    I used NOOBS to install Raspbian on my pi.
    Please help me soon.

    • Yes, the gateway is the IP address of the laptop connection. Your settings look fine.
      What is the setup? Are you using a direct wired link between the PC and the Pi, with a wifi connection to your phone (acting as an access point).
      The only other thing would be if the PC firewall is causing issues.

  22. Girish says:

    Ya.. I am using Ethernet cable to connect my laptop and pi and SSH into pi.
    My Android phone is enabled as a wifi hotspot. I could connect to internet from my laptop .
    I checked with firewall too,firewall is turned off.😦

  23. James says:


    Thanks for the useful tutorial. As a Pi newbie, this really helped get me started. I had problems getting my RPi to share the internet connection in a headless setup with my Windows 8.1 laptop, but have since got it working. Haven’t seen any solutions so figured I would share!

    I followed the above tutorial initially. Like others who have commented here, my ethernet port was assigned an IP of:


    so I added ip=169.254.X.Z::169.254.X.Y to cmdline.txt. I was able to connect from my laptop to my Pi using Putty/XMing, but the Pi was not able to connect to the internet.

    On further internet reading, apparently IP addresses in the range 169.254.X.Y are “Local-Link Addresses” (, and part of IPv4 protocol prevents routers from communicating with “Local-Link Addresses” – hence why I couldn’t get internet access.

    In Windows 8.1, when I enabled my Wireless connection to be a shared connection, I noticed that the Ethernet connection > Properties > Internet Protocol Version 4 (TCP/IPv4) > Properties had been changed from “Obtain an IP address automatically” to “Use the following IP address”:

    IP address: 192.168.A.B
    Subnet mask:
    Default gateways and preferred DNS servers were blank.

    So figured I’d try adding ip=192.168.A.C::192.168.A.B to the cmdline.txt file, fired up the Pi and it was able to connect to the internet. Hooray!

    Hope this helps someone!

Leave a Reply

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

You are commenting using your 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