I did try with the ip
method shared here, but it did not survive reboots. So, I figured, since the Network Manager was managing stuff, things went back to default 🌊
Change ip
and netmask
with nmcli
Network Manager is installed by default on ubuntu machines so you have access to nmcli
. Here is what might work for you:
Check current settings with executing only nmcli
. Take note on connection type (e.g. ethernet), DNS Configuration (i.e. servers), and the interface you are connecting to.
Create a new connection
Let's assume you want to create a connection which has the following properties:
- Name: SOME_NAME
- Interface: enp0s31f6
- The interface enp0s31f6 is a cable connection, so type is: ethernet
- You want to set the static ip
172.18.1.30
, so set it as ip4
value and also set ipv4.type
as manual
.
- The default gateway and dns are already shown when entering
nmcli
, if you are not planning to change it, just copy them here as values after gw4
and ipv4.dns
,
Note that autocomplete should work, so you can simply check for things such as interface-name by pressing TAB
twice.
nmcli # check the previous settings
sudo nmcli connection add connection.id "SOME_NAME" \
connection.interface-name enp0s31f6 \
type ethernet \
ip4 172.18.1.30 gw4 172.18.1.1 \
ipv4.dns "8.8.8.8" \
ipv4.method manual
sudo nmcli connection up SOME_NAME
nmcli # check the current settings
sudo systemctl restart networking.service
Now, the changes should be permanent 🔒
This answer was inspired by this HTG post.