Step 1: Assigning Static IP Address
I DONE IT!!. . . *ahem*. . . I mean, ‘I have completed my assignment’.
It was much easier than I was expecting, that’s not to say that I didn’t have problems (damn you permissions! Will you forever be the bane of my life?!)
As it turns out I didn’t need to jailbreak my AppleTV which is useful, as the current version of seas0npass only provides a tethered boot option, which is tedious. Turns out my PS3 can see uPnP devices on the network without any kind of customisation, which is great! The Pi needed a lot of customisation though, and I only got the uPnP side working once I had installed miniDLNA. It’s not perfect, there are still some issues I need to take care of, but for all intents and purposes, IT
LIVES! – I mean, WORKS!
The very first thing I did, and perhaps the most important for admin purposes, was to give the Pi a static IP address. There aren’t words to describe how useful this is. Out of the box, so to speak, the Pi, and almost every other network device you own, gets its IP address assigned dynamically, this is called DHCP. This is fine for normal use, but if you need to connect to a machine via SSH (which we do) then DHCP is kind of a pain. If the machine you want to connect to gets a different IP address every time it boots up, you need to find out what that is before you can connect to it. You can go down the route of adding .local to the end of your SSH command, but I have found this to be unreliable.
By giving your Pi a static IP, you’ll know exactly where your Pi is on the network and exactly how to connect to it. For example, to connect to my Pi on the network, I simply have to type the following command into Terminal, on my Mac, or WebSSH on my iPhone.
ssh -l pi 192.168.1.151
The IP address you’ll have to type in is entirely up to you, so let’s find out how to set that static IP.
From here on out we will be using the ‘sudo’ command. Sudo lets you execute commands as the superuser. To say that sudo is ‘not forgiving’ is an understatement. A simple spelling mistake, or a missed or extra space character while being the superuser could well delete important system files. Check your spelling before hitting return.
First things first. We need to find out what kind of address your router is giving all your wifi devices, for me, for example, my BTHome Hub 2 assigns IPs in this way “192.168.1.x” where x is in the range from .64 to .254. What this means is that there is no sense in me giving my Pi an IP address that ends in .5, because they only start at .64. Likewise I can’t give it an IP greater than .254. Not all routers are the same. Some routers will give local devices “192.168.0.x” addresses, others may assign address beginning with “10.” or “172.”. So check this first and write it down.
While you’re in your router, it will be handy to find out your ‘gateway’ address. This is normally something like “192.168.1.1” or “192.168.0.1” But again, this follows your router’s mapping scheme.
Defining how your Pi uses IP addresses is done in the command line, using ‘nano’ a text editor (others are available). We are going to edit the interfaces file. First, however, it is a good idea to find out what IP address your Pi is currently using. On your Pi, either at the command line or, if you’re seeing the GUI, in LXTerminal (which gives you access to the command line) type this:
You’ll get something that looks a bit like this:
Note that my ‘inet addr’ is “192.168.1.151”, and that it is found in the ‘wlan0’ section. If you are connected to the internet via WiFi, then your IP address will appear here too. If you are connected via ethernet, then your IP address will appear in the ‘eth0’ section.
The next step is to define your own static IP, to do this you type the following command:
sudo nano /etc/network/interfaces
Now, depending on where you got your copy of Raspbian from, this file could be empty, but that’s fine. My file had loads of stuff in, but I just got rid of it all and replaced it with this:
auto lo iface lo inet loopback allow-hotplug wlan0 iface wlan0 inet manual wpa-roam /etc/wpa_supplicant/wpa_supplicant.conf iface default inet static address 192.168.1.151 netmask 255.255.255.0 network 192.168.1.0 broadcast 192.168.1.255 gateway 192.168.1.254 iface eth0 inet static address 192.168.1.150 netmask 255.255.255.0 network 192.168.1.0 broadcast 192.168.1.255 gateway 192.168.1.254
Now you can go ahead and copy and paste that into your file if you want, but if you do do that, remember to change the values for the address, netmask, network, broadcast and gateway to suit your router.
Once you’re happy with your new interfaces file, it is a good idea to reboot the Pi. Being a Mac user, I’m used to rebooting like this:
sudo shutdown -r now
There are other options, I think simply
works fine too, but so does the way I’m used to doing it, and that’s the way I’m going to continue doing it.
Once your Pi comes back up, open up Midori and try to go online. If you don’t get booted into the GUI automatically when you start your Pi, then type:
If all has gone well you should be looking at Google, or whatever webpage you tried to load.
If all has not gone well, then first check that you are indeed connected to the internet. I found my Pi trying to connect to a WiFi network that no longer existed when I first tried this.
If you’re still having no luck, then I would highly recommend this video from Techerudio. (I would also recommend Techerudio in general) This particular video explains how your router works in more detail, and gives you a video demonstration of how you edit the interfaces file. (Note that he uses ‘pico’ instead of ‘nano’. It makes no difference which one you use.)
Now that you’ve got it all working, your next step is to make sure that SSH is enabled. If you’re using Raspbian, then this is quite easy. Either at the command line, or in LXTerminal, type:
Using the keyboard, navigate to ‘Advanced options’ and hit return. Then navigate to ‘SSH’, hit return, select ‘Enable’ and reboot.
Note that ‘raspi-config’ is also where you can enable ‘Boot to Desktop’ mode, meaning you don’t have to type ‘startx’ every time you boot up.
Once your Pi has rebooted, it is time to check that SSH is working. To do this you need to go to another computer on the network. On a Mac you can use Terminal, on Windows you can use a programme such as Putty.
In the command line type the following, the only differences being the IP address YOU set in the interfaces file, and only changing ‘pi’ if the user name on your Pi is not ‘pi’. (by the way, that ‘ -l ‘ is a lowercase L.)
ssh -l pi 192.168.1.151
You’ll get something like this:
Type in the password for your Pi. (default password is ‘raspberry’) Note that you will not get any visual feedback for each letter you type. Just press return when you’re done and you should see something like this:
You may be asked to confirm your RSA fingerprint. Just type ‘yes’ and hit return.
Now that you’re in, you can perform all the commands you want, but from the comfort of your regular (probably a bit quicker) computer. For example a quick ‘ls’ shows us what’s in the directory we’re in, e.g.:
This is normally the first thing I do as it just helps orient me in the filesystem.
One final note before I go. When you want to shutdown your Pi so you can move it, or what have you. Don’t just unplug it. Either from the GUI shut it down from the start-esque menu button, or from the command line type either:
sudo shutdown -h now