Chapter 5 Fixed IP address, what is it?
So, the Pi is ALIVE! Let's do a few more things. First off, what's a fixed IP address and why do I want one?
Every computer on the internet has an IP address, in the format of A.B.C.D (This is IPv4. There is also an IPv6, but 4 will work and is easier to deal with). Each of the letters is replaced with a number between 0 and 255. Your cable company gave your modem an IP address, for example, 34.206.54.121. So to the outside world, you look like 34.206.54.121. And Sears might be 206.67.233.27. And Macys might be 21.89.104.45. You used to have to put the numbers in to get to Sears or Macy's. Then, somebody made a "Telephone Directory". Servers, called DNS servers, would see Sears.com and convert it to 206.67.233.27 for you. And, Sears would respond with your number because you called them.
So, then you wanted to connect more than one computer up to the internet. Enter a new device called a Router. It keeps track that your computer is talking to Sears, and the other computer is talking to Macy's. To do that, your router assigns each one of your computers it's own internal IP address, and keeps track of all your computers and what they are connected to. Your router typically has an IP address of 192.168.1.1. So, all your computers will have an address of 192.168.1.D, D being a number assigned by the router. This number can change, but the router keeps track of it and you don't need to know it to deal with Sears or Macys.
You now add your Raspberry pi. Your router assigns it 192.168.1.121. Fine, you can now access your pi at 192.168.1.121. But then, your router can change that number at any time without notice. Where did your pi go? It's no longer 192.168.1.121. Enter Fixed IP address! Your pi can be set up to tell your router what number it wants. Usually, any number between 2 and 99 is fine as long as nothing else claimed it.
Prepare the pi for playing well with others:
Click the Raspberry Icon in the upper left corner. Click Preferences, Raspberry Pi Configuration.
A window pops up.
Click the System tab. From here, you can change the host name. Useful later when you set up many pis. You can also change the password here.
Click the Interface tab. Check SSH to remotely log in. Check other boxes for interfaces you will need...camera, serial, dio, etc.
Click OK and reboot
You can now log in from another computer using the IP assigned by the router.
Mouse over the wifi Icon, upper right. It should show you what wifi you connected to, and the IP address in use. If not, open a terminal (an icon on the upper taskbar, and type ip a.
Right click the wifi icon. Click Wireless & Wired Network Settings.
Click arrow on empty box, and select eth0 (Wired)
Enter IPv4 value (192.168.1.20 for example) assuming your router is set up for 192.168.1.1.
Enter Router (192.168.1.1) assuming that is your router's base address
Click Apply You are now fixed at 192.168.1.20 for your Wired interface, but 192.168.1.121 for wifi
Click to change eth0 to wlan0
Enter IPv4 value 192.168.1.20
Enter router 192.168.1.1
Click Apply You are now fixed at 192.168.1.20 for wifi too.
Click the Raspberry, upper left, then shutdown, then reboot. Your changes have now been implemented.
If you check /var/log/syslog and see repeated requests for an ip, you need to edit the config file. Open a terminal and type:
sudo nano /etc/dhcpcd.conf
change your data to the following
SSID nnnn your wifi SSID
static ip_address=192.168.n.nn/24 your desired ip address, replace the n's with numbers
static routers=192.168.n.1
static domain_name_servers=192.168.n.1
noipv6
Control o to save, Control x to exit.
Reboot
You can now open a terminal on another computer and type in ssh pi@192.168.1.20. or whatever address you put in above. First time, it will ask you to accept the key it found. Type Yes. It will now ask you for the password. Type the password, Enter and you're in! You can enter linux commands here. By default, Raspbian sets up a user, pi. You can add users, and delete the user pi as you see fit. In the example above, substitute pi for the user you want to be if you set up other users.
Now, you can call up a project on your laptop, open a terminal to the pi with ssh, and you can copy commands from the project write up and paste them in the terminal connected to the pi to execute the commands. Saves a lot of typing and typos!
So, we now have a feeling for the Pi and Linux, and know how to download, install, update and configure the operating system. We know how to set up a fixed IP address and remotely log in from another computer. This is the starting point for virtually all projects. From here, you can install and set up application software to do your project.
Yes, it seems like a lot to understand, BUT, as you do it a couple of times, it becomes easier. Google has a lot of info to help you. And, worst case, erase the SD card and start over. Nothing lost!
Have Fun!!!
Jim Albrecht, K2BHM