netplan generate: `gateway4` has been deprecated, use default routes instead
netplan generate I kept on getting an error message:
gateway4has been deprecated, use default routes instead.
For static IP address assignments in netplan, I’ve always used the structure:
network: version: 2 renderer: networkd ethernets: eno1: dhcp4: false dhcp6: false addresses: - 192.168.10.10/24 gateway4: 192.168.10.1 nameservers: addresses: [192.168.10.1]
gateway4 is referencing
gateway4: 192.168.10.1, but how do we fix it?
The current syntax to replace
For the netplan above based on the
192.168.10.0/24 network, it would be:
routes: - to: default via: 192.168.10.1
So the whole config would be:
network: version: 2 renderer: networkd ethernets: eno1: dhcp4: false dhcp6: false addresses: - 192.168.10.10/24 routes: - to: default via: 192.168.10.1 nameservers: addresses: [192.168.10.1]
Currently there’s a very good reference full of practical examples at:
One other tip when working on netplan files,
yamllint can save you a lot of trouble.
sudo apt install yamllint sudo dnf install yamllint sudo pacman -S yamllint
For example, I introduced a small formatting error:
- to: default via: 192.168.10.1
Then when I run
yamllint, I’ll get a line number that should help track down where the errors are.
28:9 error syntax error: expected <block end>, but found '?' (syntax)
If you have any syntax errors (for example spacing issues) yamllint will give you the line numbers of your problems.
Hopefully this has made your
netplan generate and
netplan apply go smoothly!
sudo netplan generate sudo netplan --debug apply