Configure a Static IP Address

By default the Raspberry Pi is configured to request an IP address from your router whenever it starts up. This IP address can change if the Raspberry Pi or the router is restarted. Since we are making this Raspberry Pi a web server, let's give it a static IP address so we always know how to reach it. Note that this is also needed if you plan to run this Raspberry Pi in a private scouting network at competitions.

My router gives out IP addresses from 192.168.1.2 to 192.168.1.50, so I'm going to assign the Raspberry Pi the IP address 192.168.1.75. This will keep it on the same home subnet of 192.168.1.X but avoid conflicting with the IP addresses given out by the router.

To make this change, edit the '/etc/netplan/50-cloud-init.yaml' file. Since this is a system file, you need to edit it as the Super User, so run the following command: sudo emacs -nw /etc/netplan/50-cloud-init.yaml.

In this file you will see dhcp4: true. Here are the changes I made to this file, in RED:

ubuntu@ubuntu:~$ cat /etc/netplan/50-cloud-init.yaml

# This file is generated from information provided by

# the datasource. Changes to it will not persist across an instance.

# To disable cloud-init's network configuration capabilities, write a file

# /etc/cloud/cloud.cfg.d/99-disable-network-config.cfg with the following:

# network: {config: disabled}

network:

        version: 2

        ethernets:

                eth0:

                        dhcp4: false

                        addresses: [192.168.1.75/24]

                        gateway4: 192.168.1.1

                        nameservers:

                                addresses: [71.10.216.1]

ubuntu@ubuntu:~$

I used my routers IP address (192.168.1.1) as the gateway, and I used the nameserver/DNS IP address from my service provider, which was configured in my router, as a nameserver address here. If you can't find this IP address in the router, try running resolvectl status and scroll to the bottom to view the current 'DNS Server' settings. Make sure these settings match your home network, and not my home network!

I also followed the instructions in the file and created the '/etc/cloud/cloud.cfg.d/99-disable-network-config.cfg' file by running sudo emacs -nw /etc/cloud/cloud.cfg.d/99-disable-network-config.cfg and adding the given content:

 

ubuntu@ubuntu:~$ cat /etc/cloud/cloud.cfg.d/99-disable-network-config.cfg

network: {config: disabled}

ubuntu@ubuntu:~$

 

Once I completed these changes, I restarted the Raspberry Pi by running sudo reboot. After giving it a few minutes to boot back up, I reconnected to it by using the new IP address 192.168.1.75.

Copyright 2020
  • Facebook - Black Circle
  • Twitter - Black Circle
  • YouTube - Black Circle
  • Instagram - Black Circle
Follow us on these platforms