When installing the server, you have likely installed the SSH server, or have another way to directly connect to the server.
If you followed our guide to setup the server, you are all set
Once you connect to the server, either through SSH or directly. You can edit
the following file. We used nano
but you can use VI
or any other editor already present. Every Ubuntu installation provides at least Nano and VI.
For Ubuntu 24.04 use:
sudo nano /etc/netplan/50-cloud-init.yaml
For Ubuntu 22.04 use:
sudo nano /etc/netplan/00-cloud-init.yaml
On a straight, un-customized, installation, like the guide, the contents of that file will be
You can leave the comments but you would replace the dhcp4: true
line with something like
In the example we would assign ourselves the IP address 1.2.3
.4 on a subnet of 255.255.255.0
(/32). Also for this example, the router’s IP address is 1.2.3.255.
Below an example to copy/past
# This file is generated from information provided by the datasource. Changes
# to it will not persist across an instance reboot. 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:
ethernets:
eth0:
dhcp4: no
addresses: [1.2.3.4/32]
nameservers:
addresses: [8.8.8.8,8.8.4.4]
routes:
- to: default
via: 1.2.3.255
version: 2
Just a note, but don’t use TAB
in this file. It does not allow it, a TAB is really just 2 spaces.
We can now save and exit nano (CTRL+o, CTRL+x), and apply our netplan.
sudo netplan apply
That’s it, you now are using a static IP address.
Just a note for those on the SSH connection, you will be disconnected the instant you hit the apply command. You will have to reconnect to the new IP address in order to get back on the server.
Leave a Reply