Like most people, I want to run my Pi 'headless' - i.e. I want to connect to it remotely using my laptop keyboard and screen. It means that I don't have to hook anything up to the Pi, and I don't need to get a second screen and keyboard. There's several ways of doing this - using VNC for example, or Putty (for a command line interface) and there's lot of information on the web about how to set these up. However, if like most people, you are behind a broadband router that assigns dynamic IP addresses, then you will find that the IP address of your Pi keeps changing. This means that you can't connect to it remotely unless you know the IP address - and to find that out you have to connect a screen, which rather misses the point of trying to run headless!
Fortunately its fairly easy to do this - there's several pieces I found on the 'Net, and the following is a record of my own successful attempt. If this doesn't work its probably because of the way your router is set up, and you will need more help than given in this article - but this worked for me!
The first thing you need to do is to find out what range of addresses is available to you. If you do an ipconfig command on your PC you find out what its IP address is, and that will give you an idea of the range of IP addresses being used assigned by your router.
As you can see below the IP address for my PC is 192.168.1.3 - so my router is assigning addresses in the range 192.168.1.nnn
There are a couple of other bits on information which we will need in a minute - the subnet mask and the gateway - circled below in red.
I picked an IP address to assign ion the range that the router is using, but high enough so that it wouldn't assign it to a device I was already using. That isn't the most scientific way of doing it, but it seemed to work for me! I decide to use 192.168.1.10 for my Pi.
Logging on to the PI, all I e to do was to edit file /etc/network/interfaces as follows;
At a command prompt on the pi enter sudo nano /etc/network/interfaces
In the file you will see the line iface eth0 inet dhcp as shown below
Edit the line iface eth0 inet replacing dhcp with static
Then add the following lines
address the ip address you are going to use
netmask the subnet mask shown in tthe PC ipconfig screen
gateway the default value shown in the PC IP config scree
e.g.
address 192.168.1.10
netmask 255.255.255.0
gateway 192.168.1.1
The file should look like this
Thats it! - save the file and reboot your Pi. You should now be able to access it using the IP address you have decided - as a test, ping it from your PC, and you should see something like this;
Top Comments