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.
screencast
create a new files at: /etc/cloud/cloud.cfg.d/99-disable-network-config.cfg
with the following content:
network: {config: disabled}
*note: not a bad to back up the files somewhere first
rm /etc/netplan/*.yaml
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.
$ netplan --debug generate
$ netplan --debug apply
You should have internet at this point.
$ curl https://travisshears.com
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
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, 🇩🇪
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