Guide To…Direct Network Connection

UPDATE – March 2017

Raspberry Pi Remote Connections – Without A Network!

No keyboard or screen available for your Raspberry Pi, but you have a laptop?  There is now a very easy solution!

There are often times when a HDMI monitor is not available to use with your Raspberry Pi.   To overcome this I’ve often set-up my phone to be a portable Wi-Fi hotspot, but you do have to ensure the details are set-up ready on my Raspberry Pi beforehand.

So what happens if it is a new or someone else’s Raspberry Pi?

In those circumstances it can be very useful to remote connect using a nearby network and a laptop (see the Guide to…Remote Connections).  You have two options here:

  1. If you have a wired connection available you can simply plug into it and look up the IP address on the router.
  2. If you have a wireless connection available, you can now place a file on the SD-Card with the required settings which should be transferred on start-up to the system (I’ll create a guide to this at some stage).

However, sometimes when you are travelling, at an event or perhaps in a school classroom there isn’t a network available either!

So how can we make use of a laptop screen and keyboard when there is no network?

As discussed previously (in the Guide to…Remote Connections), there is the option of using a (console) TTL-serial cable, however this only provides rather slow access.  The serial connection won’t support X11 (which as we have seen, allows us to run graphical programs too), and you won’t be able use VNC or shared folders if you have them set-up.

The answer is a simple network cable!

Connect and use your Raspberry Pi with just a Network Cable, SDCard and Power!

Connect and use your Raspberry Pi with just a Network Cable, a standard Imaged SD-Card and Power!

It is advisable to set this up before you need it so you can be sure that it is configured and working correctly.  Once you do you can use the methods described in the Guide to…Remote Connections to access your Raspberry Pi as if it was on a standard network (if you already have a network available you can just connect to that instead).

Remember if you need the wired network for your computer (i.e. to get to the internet) then you shall have to make a choice about which one you wish to use (or get an extra network port by adding a USB network dongle).  If you use wireless connections, then you can still have both!

What you will need:

  • Raspberry Pi (Model B, B+, 2B or 3B)
  • Micro USB Cable & Power Supply
  • Micro SD-Card (loaded with NOOBS see below)
  • A network cable

Any standard network cable should be suitable (needs to have a male RJ45 connector on each end), most cables available will be fine for our needs.

Note: You can use a normal network cable since the Raspberry Pi LAN chip is smart enough to reconfigure itself for direct network connections (in the past older computers would have needed a special “cross-over” cable).

Don’t worry if you don’t have NOOBS setup already, it is possible to do everything you need without a screen or keyboard attached to the Pi… Just configure the SD-Card and add power (see the section below for automated installs).  If you are already set-up with a recent NOOBS/Raspbian install then it couldn’t be simpler.

Connect and go!

Previously this process was rather difficult without a screen and keyboard attached to the Raspberry Pi.  This was because, by default, the system would not set-up an IP address when a cable was connected. This meant you had to configure the Raspberry Pi manually to have a fixed IP address appropriate for the temporary network.

Thankfully, things have finally moved forward and the latest installs of Raspbian include software which detects a new network connection and automatically assigns a suitable IP address.  This is a HUGE help!

The final piece of the puzzle, is now we have a valid network link we still need to know what IP address the Raspberry Pi had given itself so we can tell our software to connect to it.

Fortunately Apple have this covered with their aptly named “Bonjour” service which checks the addresses on the network and ensures their hostnames are valid.  A hostname is simply like a nickname given to a computer so you don’t need to remember it’s full address, just call the nickname instead.

If you don’t want/can’t install Bonjour then you will have to find the IP address either directly on the Pi using “hostname -I” or using a network scanner such as Fingbox (https://www.fingbox.com/download).

This means you can now use the Raspberry Pi by just referring to it’s hostname, by default this is set to raspberrypi.local or raspberrypi.

Hello Bonjour

If you have a OSX Mac you will have Bonjour running already. On Windows you can either install iTunes (if you haven’t got it) which also includes the service, or you can install it separately (via the Apple Bonjour Installer).

We now have a simple network just for two, allowing SSH, X-forwarding, file shares etc etc.  We can now do all the lovely networky things we like to do, as detailed in the Guide to…Remote Connections page.

Scratch

Scratch running nicely inside a window using X-11!

There’s even more good news for the Pi-Zero

This method has been used in the Pi-Zero network device video for excellent results.  It is particularly special since we use the Pi-Kitchen to pre-configure the USB to act as if it is a network device – allowing us to make a simple network link using just a standard micro-USB cable (which will also power it!).

PiZeroNetworkDevice

Raspberry Pi Zero with Micro SDCard and Micro USB Cable.

 

Installing NOOBS to your SDCard

Update: In order to put security first, the default operating system install (such as the one provided by NOOBS) no longer has SSH enabled.

https://www.raspberrypi.org/blog/a-security-update-for-raspbian-pixel/

If you want to later use SSH you will need to add a file called “ssh” to the boot partition on the Raspberry Pi.  This can be done with the following command:

sudo touch /boot/ssh

This means that although you can perform an automated install without using a screen, you won’t be able to connect to it!  Unfortunately, in the name of improved security, this method for running a Raspberry Pi headless has been broken (although I shall see if this can be fixed in newer versions of NOOBS).  There IS a work around if you are brave (thanks to Procount).  Another option is to add vncinstall to the end of the recovery.cmdline file.

Note: If you already have an up to date install you can skip this!

Load SD Card with NOOBS:

  1. Download NOOBS.zip from the RaspberryPi.org website.
  2. Format the SD-Card using the SD-Card formatter (SDFormatter)
  3. Extract NOOBS.ZIP to the SD-Card

Note: Your SD-Card should look something like this (with all the files in the root of the SD-Card and not in a directory).

SDCard

NOOBS files on the SD-Card

Automated Headless Install:

Option A: Using NOOBS

Although not a commonly known feature, NOOBS is able to automatically install a selected operating system without the need for a keyboard or screen.

To perform an automated install of Raspbian, you will need to edit the recovery.cmdline file on the SD-Card.

Note: If you are editing this file in Windows it is recommended that you use an editor which supports Linux format files (such as the freeware Notepad++).

Change the recovery.cmdline file:

runinstaller quiet ramdisk_size=32768 root=/dev/ram0 init=/init vt.cur_default=1 elevator=deadline

By adding silentinstall to the file (keeping everything else the same):

silentinstall runinstaller quiet ramdisk_size=32768 root=/dev/ram0 init=/init vt.cur_default=1 elevator=deadline

Option B: Pi-Kitchen

Set up Pi-Kitchen & select Auto Install (see the Pi-Kitchen pages for more details).

Note: The Pi-Kitchen allows complete customisation of the install and allows you to define multiple “flavours” set-up in whatever way you like.

Power Up & Install:

  • Insert the SD-Card into the Raspberry Pi
  • Connect the network cable between the computer and the Raspberry Pi.

Note: The network port on the Raspberry Pi will sense the connection type and automatically provide a cross-over for direct networking.  Therefore we can use any standard RJ45 cable.

Add power and wait…and wait…and wait some more. You should see the activity LEDs flash while the OS installs.  Depending on your SD-Card this can take up to 40-60 minutes.  If this is your first go it is helpful to connect a screen so you can observe the installation progress.

Check your network settings…

While the OS is installing you can check your computer’s network settings are set to automatic. And if required we can  enable Internet Connection Sharing (ICS) so we can use the host computer’s internet (assuming it usually connects to the internet via Wi-Fi).

Note: Most network set-ups will be set to automatic but if not ensure you write down the automatic, but if not ensure you write down the original settings so you can restore them later.

Set each of the settings to automatic which will allow the network to configure it.

Settings

Network Settings

Enable Internet Connection Sharing (ICS):

Select the ICS tab and select share this connection, and if needed select the network adaptor which your Raspberry Pi is connected to.

InternetConnectionSharing

Internet Connection Sharing

That’s it, when the Raspberry Pi starts it should detect the settings and configure the internet gateway to match the IP address of the host computer.

 

Ready to connect?

When the Raspberry Pi has finished installing you should notice that the network adaptor will report “limited connection”.

NOTE THE FOLLOWING:

  1. You will need to wait for your computer to finish detecting the network settings (you may see a small networking icon flashing in your system tray while it does, or open up the network settings to see when it has finished and has an IP address) – it can take around 1/2 minute.  Your computer may report the connection as  “limited or no connection” when connected to the Raspberry Pi in this way, this is normal as indicates it is a direct computer to computer connection rather than a standard network (where it would expect to find an internet connection).
  2. If you are using multiple wired network adaptors (i.e. Using an extra USB-LAN dongle) on your computer you may find you have to unplug the other network cable and reattach afterwards (my Windows XP machine needed this before it would connect through the direct link).

 

Summary

Now you should be able to do most of the things you would normally do when connected to a network.

One VERY useful thing to do is to set up “Putty” and “Xming” to allow you to control the terminal and graphical programs directly from your laptop/computer.

Scratch running nicely inside a window!

Scratch running nicely inside a window using X-11!

See the main Guide to…Remote Connections for links for how to set-up VNC and shared folders, and X-11 on other computers.

Install Putty and Xming Server (for SSH and X11)

I am assuming you are using the latest version of Raspbian which has SSH and X11 Forwarding enabled by default (if not see the bottom of this post to enable them if things don’t work).

1. Install and run a X-Windows server on your computer

Download and run http://sourceforge.net/projects/xming/ from the Xming site.

Follow the installation, including installing “Putty” if you don’t have it already.  You can also download “Putty” separately from http://www.putty.org/

An alternative X-Windows server is available called mobaxterm, this provides a little more control, keeps your X-Windows together and handles your sessions etc.  You can get it from http://mobaxterm.mobatek.net/.  (Thanks to Mike for this tip).

2. Ensure your SSH program (Putty) has X-11 enabled.

In the PuTTY configuration, find “Connection”, “SSH”, “X11” and tick the check-box for “X11 forwarding”.  If you leave the X display location blank, it will assume the default “Server 0:0” (you can confirm the server number by hovering your mouse over the Xming icon in the system tray when it is running).  You can save your set-up within Putty so you will won’t have to do this each time.

Putty Configuration for X11 Forwarding

Putty Configuration for X11 Forwarding

3. Enter the Raspberry Pi’s IP Address

Putty Configuration for IP 192.168.1.69

Putty Configuration for given IP

Enter the IP Address of the Raspberry Pi in the Session settings above (you may also find that you can use the Raspberry Pi’s hostname here instead (default: raspberrypi)).

Save the setting using a suitable name (RaspberryPiDirect) and press “open” to connect to your Raspberry Pi.  You will likely get a warning pop-up stating you haven’t connected to the computer before (allows you to check you have everything right before continuing).

All being well, you should be greeted with a prompt for your username and password (remember the defaults are pi and raspberry).

4. Using X11 and Xming

Ensure you have Xming running, by starting the Xming program from your computers start menu and then in the terminal window, type a program which normally runs within the Raspberry Pi desktop (such as “leafpad” or “scratch”).  Wait a little while and the program should appear on your computers desktop (if you get an error you have probably forgotten to start “Xming”, so run it and try again).

  1. If you want to run an X program, but still be able to use the same terminal console for other stuff, you can run the command in the background with &:

i.e. leafpad &

Just remember that the more programs you run, the slower everything will get.  You can switch to the background program by typing “fg”, check for background jobs with “bg”.

  1. You can even run a full desktop session through X-11, although it isn’t particularly user-friendly and VNC will produce better results.  To do this you have to use “lxsession” instead of “startx”.
  2. If you get the following error (or similar) when running PyGame or Tkinter scripts:
_tkinter.TclError: couldn't connect to display "localhost:10.0"

Use the fix below:

cd ~
sudo cp .Xauthority ~root/

More details and links are in the main Guide to…Remote Connections.

Additional Information / Troubleshooting

  1. To switch on (or off) SSH you can access raspi config (just type “sudo raspi-config” from the terminal) and select SSH in the menu (it seems like SSH is already enabled by default for some distros).
Enable/Disable SSH via Raspi-config
Enable/Disable SSH via Raspi-config
  1. Ensure X-11 forwarding is enabled on the Raspberry Pi (again, a lot of distros now have this enabled by default).

Use nano with the following command:

sudo nano /etc/ssh/sshd_config

Look for a line in the /etc/ssh/sshd_config file which controls X11Forwarding and ensure it says (with no # before it):

X11Forwarding yes

Save if required (ctrl+x,Y, enter), and reboot:

sudo reboot

What is an IP Address / Hostnames / Pinging / Subnets?

An IP Address is like your phone number or post code, it simply allows other computers to find that particular computer in the network and ensure any messages it sends goes to that one in particular.

Often, IP Address’s can be replaced with hostname’s so that we can ask for a specific computer without knowing all the numbers (like the contacts list on your phone, the computer looks up the name and uses the number for you).  For instance, http://www.google.com, is a hostname, where it’s IP address is 173.194.45.49 (probably depending on where you are).  We can “ping” the address using the following command, which simply sends some short messages to see if there is another computer on the other side to respond to them.

ping www.google.com

or:

ping 173.194.45.49

Subnets:

Networks use subnets to help handle the fact that there could be a HUGE number of computers on a network (like the internet) and it would be impossible for a computer to listen to and respond to any computer in the address range 0.0.0.0 to 255.255.255.255.

To handle this, networks will use a subnet mask, this ensures that a computer only needs to respond to computers with are within the same SUBSET, which is defined by the SUBNET MASK setting.

The mask is a series of flags which defines which range of addresses the computer will respond to (by filtering out any which are not within the allowed range):

255.255.255.0

Means it will respond to computers which have IP addressing matching at least the 3 first numbers.  So a computer with an address of 192.168.1.90 and subnet mask of 255.255.255.0 will only talk to other computers with addresses in the range 192.168.1.0-192.168.1.255 (except 90 of course!).  Large networks often use SUBNETs to split up larger networks into sections so that they run more efficiently.

Note: You will not be able to set the SUBNET MASK to wider than 255.0.0.0.  The Raspberry Pi defaults to a subnet mask of 255.255.0.0, which is perfect for most situations.

 

Trouble-shooting:

Steps to check:
1. Check the IP address which get set on both machines (both should be in range 169.254.x.x).

On RPI use one of the following commands:

hostname -I
ifconfig

On PC use the following (or look it up from the Network & Sharing Center and look at the adaptor properties):

ipconfig
  • If this fails, check the cmdline.txt file is right/cable connected etc.  You can use the following to force the IP address on the RPI (for testing the rest – but this won’t be set next time you reboot):
sudo ifconfig eth0 169.254.0.2
  1. Check you can ping each of the addresses from the other computer (where 169.254.0.xxx should match the computer you want to talk to).  Test both directions.
ping 169.254.0.xxx
  • If this fails, check PC’s firewall and disable wifi (sometimes the ping command will try using the PC’s wifi instead)
  1. Check you can connect via SSH (using putty)
  • This should work if you can already ping the other machine (it is unlikely to work if you can’t ping it).

 

References:

Thanks to fellow MagPi – Colin Deady for testing out on Mac for me.

Thanks to the following sites for providing various parts of the puzzle (in no specific order):

www.kernel.org – kernel documention

http://learn.adafruit.com/adafruits-raspberry-pi-lesson-6-using-ssh

http://people.arsc.edu/~murakami/xming/

http://jeremy-nicola.info/portfolio-item/ssh-x-forwarding-on-windows/

http://en.wikipedia.org/wiki/Subnetwork

http://en.wikipedia.org/wiki/Link-local_address

http://www.raspberrypi.org/phpBB3/viewtopic.php?f=29&t=22716

http://www.raspberrypi.org/phpBB3/viewtopic.php?f=27&t=24993

http://www.raspberrypi.org/phpBB3/viewtopic.php?f=32&t=26934

Advertisements
Comments
  1. Arun says:

    Hi.looks like someone else is having the same issue.Here are the steps I tried. I connected the RPi to my laptop(tried with both wi-fi and without it too), tried manually setting an ip address for the laptop and tried obtaining ip address automatically.Tried setting the ip address for my devices including the pi in the router so it would be auto-allocated. tried swapping the cable ends and even the cable. tried it on a different laptop.tried it with general cables and cross line cables. The laptop just does’nt recognise the device strangely.. I usually wait for more than 10 mins just to see if any establishment of connection. When I try to ping the device, i either get destination host unreachable or it just times out.

    • It does work promise! 😀
      What OS are you using?
      Do you have Windows firewall enabled or any others?
      Can you remote connect through the normal network?
      Only found one computer (mac) it didn’t work on and didn’t have chance to find out why.

      • Arun says:

        I am using Windows 7 Ultimate and i did try without the firewall too.same result. I am trying to connect it through a Linux Distro now. Thought of using Ubuntu but as far as the previous comments go, Ubuntu makes things harder. Please suggest me a Linux distro you think that works fine with the connection.

      • I shall try a ubuntu live cd tonight and see what happens. I am starting to suspect that it could be the LAN adaptor which is the issue, everything else seems like it has been ruled out.

      • UPDATE:
        Didn’t have ubuntu just Slax. Result was it didn’t allocate an IP address just had 127.0.0.1. Setting the RPi to 127.0.0.2 didn’t work (although ping did, ssh didn’t).

        But manually setting the static IP to 169.254.69.68 (when the RPi was set to 169.254.69.69) worked fine…static IP might be the way to go if IP isn’t allocated.

    • PRAVEEN KUMAR SUKUMARAN says:

      Not sure if the below help
      a) Run WindiskImager as administrator
      b) Also there is a blank line at the end of cmdline.txt by default. Do not delete this line.

      I also had the unreachable host issue. After following the above two steps, the unreachable host issue was resolved for me.

  2. Enol says:

    Hi, thanks for this guide. I just got my first raspberry pi then followed the steps here and booom!!!! it worked just fine.

  3. JackP says:

    Hi,

    I’ve tried with Windows and putty gets frozen when attempts to connect to the ip included in cmdline.txt, after an error message appears saying “timed out”. Ip adress is obtained automatically and I ensured that there are just two lines in cmdline.txt with no blank lines between them. I have not found anything that works on previous comments.

    any clue?

    thanks in advance!

  4. JonD says:

    Hi, I’m using a Mac (Mavericks), have downloaded Xquartz, added Putty etc and can ge through to the Pi, which is new today. I’ve plugged the Pi in to my TV and it works fine, have changed the password etc. However, when I try to logon using the Mac the Pi username and/or password aren’t correct. They work fine when I boot on to the TV, so the login is correct on the Pi. Any ideas? Have also tried typing the password in to the username field and it displays correctly, so no strange keyboard entry issues. Thanks in advance

    • Not sure I’ve seen that before. Check that SSH is enabled via raspi-config, just in case it is that causing it.

      • Alexandr says:

        Hi. I have the same problem on my Ubuntu 14.04 – I can ping the RasPi but cannot login using default username “pi” and password “raspberry”, as mentioned everywhere. Were you able to find a solution for this? I cannot check the ssh on the RasPi, since I just cannot login there.

  5. haziq says:

    hey i tried your method and i gave my rpi an ip address and everything worked fine 🙂 but now i want to connect my ip to internet and somehow its not connecting !!! i think there may be some problem because of fixing the ip !!!! can you help with it ????

  6. Walter says:

    Like someone said, the guide worked “out of the box”, without any further googling…
    Thank you very much for the time and the effort you spent in writing this guide.
    Cheers!!

  7. Agustin says:

    Great! Thank you very, very much!

  8. haziq says:

    hey meltwater2000 everything is working fine now 🙂 thank you so much for you help buddy ❤ now i also have used ics but i am a bit greedy you see 😛 now i wanna learn to use ethernet port for display on my laptop and use a usb dongle for wireless connection for internet ….. as far as my knowledge is concern i think there will be a conflict in ip !!! see for display we have fixed an ip and using this ip to connect to laptop through ethernet so now when we connect rpi with wireless dongle to router for internet , the router will try to give an ip to the rpi but the rpi has already a fixed ip which would be different from the one that router would give dynamically !!!!!! am i right ?? if yes what would be the solution?????

    • In theory you should be ok since you get an ip for each network adaptor. Recommend getting wifi working without direct connection, and then give it a try!
      The main issue I think is how does it know which one to use for internet.

      Good luck.

  9. JC1 says:

    Hi,
    I don’t see any file on the flash card named “cmdline.txt”. I’m frankly having persistent doubts that I’ve created my NOOBS_v1_3_4 SD card properly, even though I’ve followed the included documentation to the letter. I wish I could verify that I have an actual working Pi SD card, but I don’t have a separate keyboard and monitor and was hoping to use this method to get around that. Catch-22. Ugh . . .

  10. Fin_H says:

    can you provide me with a solution so that i can pass the internet connection of my mac through the cable to the pi, because at the moment i cant use the internet on the pi with this set up

  11. I followed your tutorial and am successfully using it with putty and xming on my windows 8 laptop directly with an ethernet cable connected between my laptop and pi. But the problem with which I am stuck currently is not being able to use internet on my pi (using with xming gui). I have shared my wifi connection over ethernet which alloted an ip 192.168.137.1 to my pc which I have changed to 192.168.74.158 which is my actual id to be used in my college lan network. I am using ssh login directly via a single ethernet cable because ssh port 22 is blocked in our college lan network. I also have to put these things along with my PC’s ip

    Ip Adress:192.168.74.158
    Subnet Mask:255.255.255.0
    Default Gateway:192.168.74.1
    Preferred Dns server:192.168.254.1
    Alternate Dns server:192.168.254.2
    So, after choosing to share wifi over ethernet I have changed the alloted ip(.137.1),Mask,Gateway… to above mentioned adresses

    Then coming to pi I have made my pi’s ip static with ip 192.168.74.2

    Then I have changed the /etc/network/interfaces to static as follows….

    auto lo

    iface lo inet loopback
    iface eth0 inet static

    address 192.168.74.2
    netmask 255.255.255.0
    gateway 192.168.74.1

    allow-hotplug wlan0
    iface wlan0 inet manual
    wpa-roam /etc/wpa_supplicant/wpa_supplicant.conf
    iface default inet dhcp
    as suggested in some other threads…

    I am able to ping 192.168.74.158 (my pc) from pi using putty and also 192.168.74.2 (my pi) using command prompt on my pc. But I am not able to ping http://www.google.com or any other ip other than 192.168.74.xxx series …

    Is something related to port 22 blocking or is there something else to do or something wrong I have done? The wifi shared was actually shared by another PC connected to the same lan server (Ip 192.168.74.156) with connectify-me software. So does that affect it. Also note that I am able to surf internet on my pi with a monitor connected for display via HDMI (I dont have access to this now)

    • Networks are hard to diagnose via messages, and I’m not a network expert by any means.
      1. Try it first with the allocated settings before you change things – always easier to change once you are sure everything else is working.
      2. The subnet mask may need to be 255.255.0.0 for it to use the DNS addresses you have set.
      I don’t think Port 22 will cause an issue with SSH but shouldn’t cause problem with ping, again check if you can ping using other machines.

  12. thank u for your reply…. I figured out that i did not append the ip of my pc in cmdline.txt file…
    Its working…

    • Always glad to hear it is working.
      Enjoy!

    • gowrav says:

      Hi manjith,I have a similar problem of using my lapto internet connection to raspbeery pi.Could you explain in detail what needs to be done…i have connected laptop-Pi via ehternet cable and could ping each other.Am using wirless internet connection in my laptop,but would like to use internet connection for my raspberry pi from here

      • The summary is as follows:
        1. Enable ICS on PC
        2. Set RPi IP address to one which is similar IP allocated to PC
        3. Set RPi gateway to same IP as PC
        This is what the post should allow you to do.

  13. lulin says:

    “lxsession” is not working for me… I can enter the shell of my Pi using putty, but when I enter “lxsession” I got the error message:”Only one lxsession can be executed at a time”, which was solved by changing the to “Console text console”. Now the error message is gone, but when I enter “lxsession” on my laptop, I still don’t get the GUI desktop started on my PC… Anyone knows how to solve this problem?

    • Ensure you have your Xming server running. I’ve not seen the error message before. If you are creating background processes, ensure you don’t have another running.

      • lulin says:

        Xming is running on my PC, and I can see the “X’ icon in the system tray, when I hover my mouse on it, it shows “Xming Server:0.0”. I can ping from Pi to my PC, and from my PC to Pi, but when I run “leafpad” in the terminal on my PC, it says “leafpad: Cannot open display:”, when I run “lxsession”, it gives “Only one lxsession can be executed at a time”…

      • I wonder if it is similar to the “localhost” error, try using first:
        sudo cp ~/.Xauthority ~root/

      • lulin says:

        Still the same…

      • Odd, unfortunately I’ve not seen this before. Do you normally have it set to auto load the desktop when you power up?

      • lulin says:

        No when I power up it shows the command line interface, the I have to enter “startx” to load the desktop. However, before I load the desktop, if I run “lxsession” on my PC, the error is gone, but nothing happens… if I run “leafpad” on my PC, it gives the same error…

      • I’ll have to test this tonight in case something has changed recently. Although I use X-Forwarding a lot so would have noticed.
        Have you enabled X-Forwarding in Putty and in sshd_config?

      • lulin says:

        Yes I have ticked the checkbox, by the way, how do you save this so you don’t have to check it every time you open Putty? X11 forwarding is enabled in sshd_config by default.

      • Worth checking sshd_config just in case.

        Set it up, then put a name in the “Saved Sessions:” box, and press save. You can then double click to run it!

      • lulin says:

        X11forwarding is enabled in sshd_config. (without # before)
        I just found out that I can start the desktop on the moniter my Pi is connected to by using “startx” on my PC.

      • Ah yes it might start a local desktop fine, although that would be controlled with local keyboard.

      • lulin says:

        If only I could start it on my laptop…

      • Have you managed to get anything to show up via X-Forwarding? I typically don’t use it with the full desktop as it is much quicker with individual applications.

      • lulin says:

        I could use nano for example, I guess I cannot use programs that need to display user interface on the desktop. I got the error message “cannot open display”

      • That sounds very much like it isn’t connecting to the xserver program. I can confirm it later, when I have a Pi available.

      • lulin says:

        On the screen shot, I saw that you entered 192.168.1.69 in Putty, as Pi’s IP address. Where does that IP come from, shouldn’t it be 169.254.x.x? Maybe this is the problem, because I entered 169.254.0.2 as my Pi’s IP…

      • No as long as you are connected via SSH you have the correct IP (yes it is the Pi’s IP). XForwarding works via a standard network and via a direct cable link.

      • Confirmed, if XForwarding and the Xserver isn’t running correctly you get:
        “leafpad: Cannot open display:”

        You can try putting the server info in the box in the putty config, perhaps that will help. Otherwise I wonder if your firewall is blocking the Xserver program.

      • lulin says:

        Where exactly should I put the server info in the putty config? I turned the windows firewall off already, in order ping from the Pi to my PC.

      • lulin says:

        It worked suddenly!! This is what I changed: I right clicked on the Xming server icon in the system tray and unchecked “Hide Root Window”, then used Alt+Tab to switch to the Putty command line window, then I entered “lxsession”, everything just worked fine. Thanks you very much for you help!! 🙂

      • Glad you got it working! Shall watch out for that.

      • domagojhack says:

        Hi well Lulin’s fix is not working for me (same problem with “lxsession”, x-forwading is on in ssh_config). Xming and Putty does not communicate on my laptop how can I fix this?

  14. SHREE HARSHA S says:

    Im not being able to edit the in the SD card; it shows write protected., while setting IP Address for raspberry PI.

  15. Tyler says:

    My computer and raspberry pi are now connected together via ethernet. How can my pi now access my computer’s wifi?

  16. Vishal says:

    Hello,

    I recently ordered for a RPi with 512MB with berryboot configured on my SD card.I am able to SSH through putty but it asks for username and password when loin through the same.Have provided username as pi and password as raspberry but every time it says access denied.What can be the issue
    ?

    • This could be a firewall issue. I’ve not used Berryboot, but that shouldn’t make much difference unless they have different login details for the distro you are accessing.

  17. rohit says:

    hi…
    I am facing a issue which I will explain…
    I have allotted IP=169.254.0.2 to my raspberry pi.(my Ethernet lan address came to be 169.254.81.1)
    when I ping this address through cmd, I get host unreachable message
    also, it pings from 169.254.81.1 and not to what Ip I have allotted to the pi. not clear why.
    (in cmd I am writing- ping 169.254.0.2)
    I have turned the WiFi off and also tried.
    4 or 5 led glow on the screen.
    plz help…badly needed.

    • rohit says:

      plzzzz reply

    • You can check your subnet settings, but they should automatically be 255.255.0.0
      Confirm the IP has been set on the Raspberry PI (either with hostname -I or view the devices on your router). See if you are able to ping the PC from the RPi, and vice-a-versa.
      Sorry about taking a while to reply, have been very busy finishing off the book.

      • alikkk says:

        IP on pi I m writing by change in cmdline.txt but when I ping it..it is not pinging

      • Can you confirm the IP address has been set on the Raspberry Pi by using a monitor/screen? Ensure you don’t have any errors in the cmdline.txt (should all be on one line, and not have any windows characters in – make sure you use a linux friendly editor rather than notepad).

  18. jim lewis says:

    HI, firstly, thanks for this. Toting my laptop and monitor cable/keyboard/mouse for the pi was a pain (I hooked up to my setup at work to fiddle with the Pi), this is neatly avoided with this how to guide.

    However, flushed with success I had a go at writing the script to automate the IP selection process.

    AFAI can see it is correct, however, when I try to run it I get ‘permission denied’. I’m logged on as Pi/Raspberry which I thought was root level anyway. SUDO./switchip.sh doesn’t work, neither does simply typing switchip(with or without .sh)

    Any suggestions?

    I’m able to open Xming and Putty sessions no problem.

    Thanks

    • It has been a while since I’ve run that script, perhaps the permissions have changed on the latest versions of Raspbian. I’ll give it a try on my own setup and let you know my results.

  19. Cidtek says:

    What is the power up sequence of the laptop and Pi

    • Typically:
      1. I have the laptop running.
      2. Ensure the settings are correct on laptop and RPi.
      3. Connect the network cable.
      4. Power up the Raspberry Pi.

      If you power up the Raspberry Pi without network cable connected, then it will take about 1-2 min looking for the network before fully booting. I think after that, it will auto-connect if plugged in (although I suggest you test it before relying on it).

  20. Daniell says:

    Hello i installed arch linux latest version on my Raspberry Pi. I append ip 169.254.0.3 address end of cmdline file. I cannot run ssh using putty . Is there any solution ?

    • I’ve not tried it on Arch Linux, it will depend if it uses a similar command-line method on start-up.
      You will have to confirm (using a keyboard/monitor) if the IP is getting set correctly or not.

      If you know the commands to set the IP address in the terminal, you could always set that on startup instead.

  21. Jobo says:

    I am using this configuration and I need to undo it so I can use a monitor with my raspberry pi

    • That should be no problem. This does not change the display settings. The display is set in the config.txt file, located in the same space. [on power up keep pressing shift to start NOOBS and 1,2,3 or 4 if nothing is displayed.

      You can edit the cmdline.txt file from NOOBS, or directly on the Raspberry Pi;
      sudo nano /boot/cmdline.txt

      If you are not using NOOBS you can even edit this file directly on your PC.

      You can then remove the ip=169.254.x.x setting and your network connection should be back to normal.

  22. Snowman7784 says:

    Works great thank you very much!

  23. Chinmay Upadhye says:

    I worked as per your forum’s steps for 3 days, and rectified problems using references in comments & VOILÀ….! it worked.
    Thanks for such great forum.

  24. Chinmay Upadhye says:

    I want to change the boot OS while using remote server. What commands should I use in “LXTerminal” ?

  25. Hrishikesh says:

    Thanks a lot for this great tutorial.

    I followed all the steps given and can ping from both the sides (i.e Raspi and laptop) but ping http://www.google.com is showing unknown host. My internet connection is via Wifi on laptop and in sharing mode in Win 8. Any good suggestions are welcome.

    Thank you.

    • Ensure that you have set the PC IP as the gateway and check it is set via ifconfig. Ensure you can ping your router too.
      (I will have to assume win8 sharing mode is the same as ICS in Win7).

  26. Oz says:

    Thanks a lot for this guide; it’s been somewhat helpful, but I’d really appreciate some help here – I’ve followed all these steps completely with a brand new Pi and a Win XP laptop.

    I’ve managed to set the Raspi IP correctly for sure (checked with ifconfig) and I can ping the laptop. But the laptop is not able to ping the Pi, even with WiFi and firewalls disabled completely. What could be going wrong here,

    Thanks so much for your help! 🙂

    • Oz says:

      Also, note that I’ve got the latest version of Raspbian installed on the Pi, and a USB WiFi dongle in the Pi, just in case that affects it. 🙂

      • I would suggest keeping it as simple as possible, no other network devices enabled on either computer, checking the assigned IP addresses on each machine. Ensure the IP that is assigned on the PC is in the same address range as the RPI. You can also try setting the IP manually on both. Trying with other setups may also help you isolate what the problem is (and prove which part is working!).

        Networks sometimes can take a fair bit of tinkering to get working if they are being difficult, so it is hard to say what the specific issue is.

        Sorry I can’t be of more help.

      • Oz says:

        Thanks a lot for the reply. I managed to get the whole setup working by simply playing around with the IP addresses on my PC and Pi, and eventually for some reason one of the combinations seemed to work! Anyway, I’ve switched to a Linux desktop now, so now it’s time to figure out how to do the same on that. -_- (!)

  27. theobligingyardstick says:

    I followed the steps and my rPI device was definitely assigned an ip address, but when I try and SSH into my device using PuTTY it claims “Connection Refused”. Running Raspian as it is the only one I know that automatically enables SSH. Why can’t I connect!?

  28. Awesome! Got this working in about 30 minutes. I was using the NOOBS distro so couldn’t edit cmdline.txt from my laptop on the SD card directly. But I did it using method 2 will zero issues. THANKS!

  29. Erwick says:

    Hi I run Windows 8 on my Laptop and cannot juggle with the LAN settings!
    Any workaround?

  30. Dusiue says:

    i plugged my pi into my win 8 laptop but when i try and connect to it using putty it waits 10 seconds then just says connection timed out.
    I tried to ping the 169.254.0.2 and this is what i get:

    Pinging 169.254.0.2 with 32 bytes of data:
    Reply from 169.254.105.90: Destination host unreachable.
    Reply from 169.254.105.90: Destination host unreachable.
    Reply from 169.254.105.90: Destination host unreachable.
    Reply from 169.254.105.90: Destination host unreachable.

    Ping statistics for 169.254.0.2:
    Packets: Sent = 4, Received = 4, Lost = 0 (0% loss),

    Please help!

    • First thing is to confirm your PCs subnet mask is 255.255.0.0 not 255.255.255.0 or you’ll not get anywhere (it’ll ignore any address which isn’t 169.254.105.xx if set to 255.255.255.0). Also you’ll have to check if you have a firewall enabled, that might be blocking it.
      If you have a screen available, see if you can ping from the Pi back to the PC too.

  31. RedFox says:

    It works! It works!
    Thanks so much. Took awhile for someone who is new to this stuff, but it’s a clear and nice guide.

  32. slade says:

    You have the most comprehensive guide out there and I don’t mean to be a pain. Could you review the below and point out what the error is as I cannot connect putty.

    Running Vista.
    Have turned the Firewall Off.
    Have edited cmdline.txt to reflect:

    dwc_otg.lpm_enable=0 console=ttyAMA0,115200 kgdboc=ttyAMA0,115200 console=tty1 root=/dev/mmcblk0p2 rootfstype=ext4 elevator=deadline rootwait ip:169.254.48.210
    *** One line and one space before/after “ip:169.254.48.210” ***

    When RPI plugged into laptop, ipconfig shows:

    Link-local IPv6 Address . . . . . : fe80::9478:9781:20e5:30cb%10
    Autoconfiguration IPv4 Address. . : 169.254.48.203
    Subnet Mask . . . . . . . . . . . : 255.255.0.0
    Default Gateway . . . . . . . . . : (blank)

    A ping 169.254.48.210 shows:

    Reply from 169.254.48.203: Destination host unreachable (4x)
    Packets: Sent = 4, Received = 4, Lost = 0 (0% loss),

    Correct me if I am wrong, but the laptop is talking to the RPI since there is 0% packet loss, right? What is preventing me from connecting putty? I can fire up putty when I just connect the RPI to my router and SSH remotely, but haven’t been able to connect it directly to his laptop.

    • The last bit should be ip=169.254.48.210
      Hopefully that is the problem! 🙂
      It is a tricky thing without a screen since you can’t be sure the IP has worked.

      This should be available as a Pi-Kitchen Recipe very soon.

  33. oneasterisk says:

    I found a temporary fix.

    I edited etc/network/interfaces from [iface eth0 inet dhcp] to reflect:

    iface eth0 inet static
    address 169.254.48.210
    netmask 255.255.0.0

    I successfully connected to the RPI from the laptop via Ethernet.

    • Perhaps see how your file is different from the example ones, don’t forget to use a UNIX friendly editor.

      Also Pi-Kitchen Recipe 001 will bake the direct-network files into a new install automatically. Will be posting details soon.

  34. Dirk-Jan says:

    As a beginning programmer, who doesn’t always has acces to an extra screen, this guide was a godsend! thank you so much for writing it in such a way that even a novice like me can use it!

  35. SaberWriter says:

    Raspbian FYI – Your article states that we can remove the SD card from RPi, read it from our windows machine and find the \boot directory and edit cmdline.txt. However, you cannot read those files because they are in the “boot image” and are not accessible. I tried adding the cmdline.txt file directly to the root of my boot image (created using NOOBS) and it doesn’t work. I went over booted up the RPi using my image, traversed to the root, found the \boot directory under there and found the cmdline.txt file. I mv the file to new file name that I could edit via sudo. I then added the ip=169.254.0.2 to cmdline exactly as you stated. mv the orig file to cmdline.old then mv the new file to cmdline.txt. I shut it down brought it back to my Windows8 (Win8) laptop. Connected the network cable to laptop and RPi then connected power to USB and waited. It recognized it and connected easily using ssh (i’m running vncserver on my RPi). All is good now. So, keep in mind you have to run the actual RPi image to edit the cmdline.txt.

    • The original article was written before NOOBS was created, which as you say, has moved the location of the os boot files. As mentioned in the other articles you can use a Linux computer or live CD or VM to change the files (after the SD card has been installed using NOOBS).
      However you can still write raw images to an SD card, as before without NOOBS and use this method.
      Also, by using Pi-Kitchen we can now inject the required files to where we want them, even before we have installed the OS using NOOBS.

  36. SaberWriter says:

    @meltwater2000 You are correct. I should’ve explained that first of all I really appreciate you explaining how to do this because you’ve made things so much easier and the way you’ve explained it _does_ work fine. It’s just in the case of NOOBs setup that the cmdline.txt file isn’t in the root. I just went and imaged an SD card using the other (direct) method and I saw the cmdline.txt file in the root just as you said.
    Thanks again for explaining how to do this. It works fantastically on my Win8 machine. Great writing and fantastic detailed explanation that you’ve provided. I never would’ve figured this out without your explanation.

  37. Avineshwar says:

    Being able to use our Pi through a PC/Laptop is a cool thing (actually life savers for many without a HDMI display). My point is lets say I am using my lappy to display the Pi and connection is successful and I am able to use it on my lappy and the same lappy is connected to some WiFi network and internet is working fine on it. So, since our Pi is connected to a laptop with an internet connection (WiFi), will it be possible to access internet on the Pi even though we have used an ethernet cable to make the connection with our lappy ?

  38. IAmHis says:

    This makes no sense:

    For network settings where the IP address is fixed, use an address which matches the laptop/computers address except the last one.

    Except the last one? Last what – digits of the IP? Please refine what you wrote so that it makes more sense. Thank you.

  39. JordanP says:

    Hello, I have managed to get my connection established via Ethernet, and pinging the RPi through Windows command line (laptop) is successful (with the LNK light blinking off, corresponding with the ping return message), albeit I have no idea how to actually show the RPi on the screen.

  40. SonofEarl says:

    I just did all of the steps you had listed but when I logged onto my pi and executed ‘scratch’, to open scratch it simply said:
    Executing: /usr/lib/squeak/4.10.2-2793/squeakvm -encoding UTF-8 -vm-display-x11 -xshm -plugins /usr/lib/scratch/plugins/:/usr/lib/squeak/4.10.2-2793/ -vm-sound-alsa /usr/share/scratch/Scratch20131203.image
    Could not open display `(null)’.
    I am not sure what to do and any help would be appreciated.

    • Are you trying to remote connect using X11? If so you may need to run the following command on the PI first:
      sudo cp ~/.Xauthority ~root/

      However…the most recent version of scratch I’ve used has an additional error where “=” characters are send triggered in X11 (so it makes writing text very difficult). Until this is fixed, the best solution is to use VNC instead when using Scratch.

  41. Paulix says:

    Hey Meltwater – thanks for the guide, I’ve plugged the SD card into my computer, but the cmdline.txt file is not present.

    Anny ideas?

    • Unfortunately cards installed using NOOBS have this file on another partition (which why you can’t see it in Windows). You can use a Linux live CD to see and edit it, or if you have a screen, you can edit it on the Pi.

  42. Uirsalan says:

    Umm I am sorry but i am having difficulty doing this. Can someone help me(meltwater especially)? I am using the raspberry pi model b+ with raspbian. Unfortunately in my house i don’t have any hdmi-input taking devices, neither did my 4-pole av cable work. I have just put the os on the sd card and nothing else. Please help me cause I have wanted the pi for a lot of time, and have got it after a very long time, and at quite a high price($56 for pi only), so I want it to work so I can create projects with it. Any help would be appreciated. Thanks inadvance

    Uirsalan

    • Hi.
      Don’t worry you have a number of options which may work for you.

      1. AV Cable – There a few variations in how these cables are wired, so you may find that you get video OK through the Red connection instead. The way to test this is to copy the NOOBs files to to the SD-Card, run the Pi which will start by running NOOBS and press 3 (for PAL) or 4 (for NTSC) on your keyboard – if not sure which just switch between them and see which works. You can then try each of the av outputs to see which one is correct. For info, from sleeve to tip it is Video/Ground/Right/Left.

      2. Use a raw Raspbian image and SDImager. This will put Raspbian directly on the SDCard without NOOBS which means the cmdline.txt file will be visible on the SDCard (on NOOBS installs you would only see the NOOBS files).

      3. Use a USB-Serial TLL Console cable – You’ll probably still need to use a raw Raspbian image but you will be able to connect using Putty and access the commandline of the Raspberry Pi.

      4. Use Pi-Kitchen! When setup you will be able to not only use the direct network configuration but also get it to boot directly to analogue video output.
      The example given in the Pi-Kitchen: Quick Start should have you setup with Direct Network (you’ll need the automated install version).

      Let me know if you need further help with these options.

      • Uirsalan says:

        Thanks bro, really, however I am very new to the raspberry pi, so can I talk to you on a social network? I have google hangouts, facebook, twitter, skype, etc. If you don’t want to give your own social profile name, tell me, I will give my username of the particular social network, so that you can add me. I would really appreciate your help. Thanks in advance.

        Uirsalan

  43. altairpearl says:

    It worked like a charm 🙂 Thanks for the detailed tutorial.

  44. vinsh says:

    Can we connect the HDMI cable to the HDMI port of the laptop without any adjustments and problems so that the laptop screen can be used as a monitor for the Pi?

  45. JC says:

    I made the changes on the Pi’s SD card, checked the X11 box on putty, put in the IP address for automatic (169.254.0.x)

    My progress is the command line window opens on my laptop but does nothing.

    • I assume you have a terminal connection working, this means you can now use the Remote Connections guide to run vnc or use X11 forwarding.

      • JC says:

        Actually with a lot of messing around, I figured out how to fix the IP address on my laptop and then I managed to ssh to the pi. I was using a Linux system anyway so once I knew to do that (and how to do it) it was very easy.

        Thanks for your guide.

  46. Priya says:

    sir if i connect my laptop to raspberry pi with Ethernet cable such that laptop uses wifi connection,will your above guide will work?

  47. Adithya.N.S says:

    Hi there! I’m new to raspberry pi.see though this method can I switch my laptop screen for my lap and raspberry pi any time

  48. MutantSurvivor says:

    I can’t seem to get this to work.

    Using a MacBook and a Pi with NOOBS

    I connected first with the Pi connected to my router and was able to ssh in (using the terminal) and then edited the /boot/cmdline.txt to add ip=169.254.0.0 then restarted the pi

    Once it had restarted I was unable to ssh

    I then connected the ethernet cable direct to my laptop and was able to ping 169.254.0.0 but when I try to ssh pi@169.254.0.0 I get

    ssh: connect to host 169.254.0.0 port 22: Permission denied

    any ideas?

    • I would try something other than 0.0 just in case it is a special number in the IP world.
      Also if you can ping, then that may suggest you have port 22 blocked for local IP addresses. Unfortunately I don’t have a MAC to know where to start with settings of that. Sorry.

      • MutantSurvivor says:

        OK, I’ll try another ip address.

        If port 22 was blocked by my laptop’s on firewall then surely I wouldn’t have been able to ssh to the pi via the network (I have since also managed to do this with a usb wifi dongle as well) or am I misunderstanding how these things work?

      • It is possible to block based on IP, but I do not know what are typically blocked by default even if that is it.

  49. Point.Less says:

    Okay, so this will probably sound really dumb, but how do I actually USE the laptop as monitor and keyboard after following the tutorial (Until Step 2, Option 1)? It is connected, but should it work automatically?

  50. I followed the steps to use my laptop’s screen and keyboard as Raspberry Pi B+’s, but I’m getting an error message from Putty saying network error: Connection refused. I’m using the Raspberry Pi B+ for the first time.

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