To set a static IP address, we are going to use netplan.
First make sure that it is installed using this command:
sudo apt install openvswitch-switch-dpdk
Next we need to figure out what interface our server is using. To do that we need to run:
ip route show
After we run the command we are looking for the interface. When I ran it, I got this:
default via 192.168.1.1 dev ens18 proto dhcp src 192.168.1.110 metric 100
192.168.1.0/24 dev ens18 proto kernel scope link src 192.168.1.110 metric 100
192.168.1.1 dev ens18 proto dhcp scope link src 192.168.1.110 metric 100
We need to find the line with 192.168.1.0/24. So my interface is going to be ens18
Next we need to make the configuration file. I am going to use nano to do this.
sudo nano /etc/netplan/99_config.yaml
In the configuration file we need to add this:
network:
version: 2
renderer: networkd
ethernets:
ens18:
dhcp4: no
addresses:
- 192.168.1.5/24
routes:
- to: default
via: 192.168.1.1
nameservers:
addresses: [192.168.1.1, 8.8.8.8, 8.8.4.4]
Be sure to change the line under ethernets to your interface like I have here. Under addresses, this is where we are going to put the IP address we want to use: 192.168.1.5/24. If you are using nano, press Ctrl+X then Enter to save the file.
After we make the configuration file, we need to set the permissions for the file. To do that we use this command:
sudo chmod 600 /etc/netplan/*
This will set all the configuration files in that directory to have the correct permissions.
Now all we need to do is run this command:
sudo netplan apply
This will apply the configuration, now your IP address is set.
One last thing that I like to do, is to remove this 192.168.1.1 dev ens18 proto dhcp scope link src 192.168.1.110 metric 100 configuration. To do that we need to run:
sudo ip route del 192.168.1.1
This will delete that configuration. Now everything should be set.