I want to change my default gateway just to see how nmcli command works. So this is what I do.
I find out what my default gateway is :
ip route
default via 192.168.1.254 dev wlp9s0 proto dhcp metric 600
169.254.0.0/16 dev wlp9s0 scope link metric 1000
192.168.1.0/24 dev wlp9s0 proto kernel scope link src 192.168.1.216 metric 600
192.168.122.0/24 dev virbr0 proto kernel scope link src 192.168.122.1 linkdown
I then bring my connection down
nmcli con down Telia-2F1C
Afterwards I try to change a default gateway but I get an error message, why ?
nmcli con mod Telia-2F1C ipv4.gateway 192.168.1.222
Error: Failed to modify connection 'Telia-2F1C': ipv4.gateway: gateway cannot be set if there are no addresses configured
or I add a subnet mask to a command and I get a different error message, but still nothing works
nmcli con mod Telia-2F1C ipv4.gateway 192.168.1.222/24
Error: failed to modify ipv4.gateway: invalid gateway address '192.168.1.222/24'.
How do I change the default gateway ?
You are adding a subnet mask at the end of the gateway IP address. You only use subnet mask '/24' to determine the size of a network with your IP address. For example, if you want to change your IP address on a you would write:
Note the '/24' at the end of the address which tells the computer how many IP addresses are in that network.
If you want to change the gateway you would write:
Note that there is no need to add the subnet at the end.