Making a static IP

The Pi-Lib package relies on a fixed IP-address when asking for help. It uses that address to send a package containing a message to a specific computer, that computer (the server) has to read the package and display it’s content. This can only be done when the IP of this server is known to the nodes and is sure to remain static. You can compare this to a networked printer, it will only work if the computer sends the print-job to the correct IP; otherwise it will fail. Ensuring the IP is correct can be done by making it static. This means that it won’t change over time.

There are two ways to do this; the first method would involve your network configuration, this is the most technical way to tackle this problem. Another way is to make the Raspberry Pi ‘decide’ its own IP; this ensures the same result without having to tinker with your network settings.

Please note that you can make more than one server (for instance one per floor/department), if you do this, every static IP has to be unique. You will have to remember the IP address(es) when you configure your nodes.

  • Open two terminal windows. This is how your screen should look like.
  • In one windows type:
    sudo leafpad /etc/dhcpcd.conf
  • After pressing enter, a text document opens, let it be for now.
  • In the second terminal window type:
    ifconfig
  • After pressing enter, type:
    netstat -nr
  • In the terminal window where you typed ‘ifconfig’ and ‘netstat –nr’ look for the desired interface. Simply put, this is the technology used to connect to the internet, there are two options ‘wlan0’ which is the wireless connection and ‘eth0’, which is a wired connection. You can ignore ‘lo’.
    • If you are unsure about the interface you have to choose, go to the wireless/wired icon on the top right of your screen and hover over it.
      • It will say which interface is working and which isn’t.
      • Obviously, choose the one that is working.
  • Now go to the text file that opened by typing in the first terminal.
  • Go to the bottom of that file and type the following:
    interface wlan0
    static ip_address=192.168.137.131/24
    static routers=192.168.137.1
    static domain_name_servers=192.168.137.1

The red parts in the above box are the parts you’ll have to adapt yourself: follow the rest of the instructions to determine what's what.

 

  • On the first line, type the correct interface this can be wlan0 or eth0 (there is no letter o in here, but it’s the number 0 (zero))
    • Remember: wlan0 is for wireless connections, eth0 is for wired connections.

 

  • On the second line, type the correct IP address, type it exactly as you see here and on your Raspberry Pi.Since I use wireless, I have to look at wlan0.
    • There is no <Space> in ip_address=192.168.137.131/24
      • Write down the IP address without the '/ and everything behind.
    • Look in the terminal window where you typed ‘ifconfig’ and look for the correct interface, in that interface look for ‘inet addr:xxx.xxx.xxx.xxx’ (there will be a number there in stead of a bunch of x's.)
    • Type those numbers in the textfile followed by ‘/
    • After the ‘/’ type the number that you find by hovering over the wireless/wired icon on the top right of your screen and append it to the line you are working on.

 

  • On the third line we need to tell the Raspberry Pi the IP of our router. There are a few ways to retrieve that address, but it’s already on your screen.
    • Look for the terminal where you typed ‘ifconfig’ and look at the bottom of that terminal.
    • There you can see a routing table. A routing table, look for 'Iface' and 'Gateway'.
    • Look for the word ‘Gateway’ and the numbers below it. If applicable choose the correct interface, in the routing table it’s abbreviated by ‘Iface
    • The IP of our router can’t be 0.0.0.0, so it’s the other one.
    • Type this on the third line after: ‘static routers=
      • Please note that there is only a <Space> between ‘static’ and ‘routers’.

 

  • On the third line we need to set our DNS servers; unless you’ve configured them yourself you can type the same number as in step 3.
    • Type: ‘static domain_name_servers=
      • Please note that there is only a <Space> between ‘static’ and ‘domain'.
    • Append the address after that.  The correct settings to assign a static IP, these settings are for my own device/network combination and will be different from yours.
      • If you have configured your DNS servers yourself, you will need to append the correct address yourself.
  • Save the text file, the bottom of the file should look like this (use your own values), then close it.

 

  • Close all terminals.
  • Reboot the Raspberry Pi and verify if your settings have taken effect.
    • Hover over the wireless/wired icon on the top right of your screen and verify if these settings are what you’ve configured.
  • Test your internet connectivity by browsing the internet.

 

 

Next: Auto-start the server