Setting a Static IP on Pi - 08-19-20

This week I’ve been setting up a home Raspberry PI 4b server. I struggled to get the static ip for it on my local network. Now that I’ve figured it out I’m making this tutorial to help other avoid the pain.

*note: I’m using a Raspberry PI 4b running Ubuntu Server 18. Other setups might require different steps.

Video

screencast

Steps

Disable the clound init netplan configs

create a new files at: /etc/cloud/cloud.cfg.d/99-disable-network-config.cfg

with the following content:

network: {config: disabled}

Remove existing netplans

*note: not a bad to back up the files somewhere first

rm /etc/netplan/*.yaml

Add a new netplan with dhcp4 on

Add/Edit /etc/netplan/01-network-card.yaml as follows:

network:
version: 2
renderer: networkd
ethernets:
  eth0:
    dhcp4: yes

This will set the PI to have a dynamic ip assigned by the router.

Apply the plan

$ netplan --debug generate
$ netplan --debug apply

Test and make sure internet is working

You should have internet at this point.

$ curl https://travisshears.com

Collect connection info

Now that the you are connected to the internet you have to copy he info recived via dhcp4.

Ip Address:

$ ip addr

Gateway:

$ ip route show

DNS:

$ systemd-resolve --status

Update your router to setting a static ip for your pi’s mac address

Usually in order to actually keep your ip on the local network you need to configure your router as well.

my router ip config page, 🇩🇪

my router ip config page, 🇩🇪

Update netplan to be static

Again edit /etc/netplan/01-network-card.yaml but this time using the info from the previous steps and turning off dhcp4.

network:
version: 2
renderer: networkd
ethernets:
  eth0:
    dhcp4: no
    addresses:
    - 192.168.1.2/24
    gateway4: 192.168.1.1
    nameservers:
      addresses:
      - 192.168.1.1
      search:
      - localdomain

tutorial topics: [pi] [ubuntu] [screencast]