I’ll give an example of adding routes in the Netplan configuration.
To add a route, it is enough to specify in the block of the desired interface (there must be two spaces before via, tab cannot be used):
routes: - to: 10.0.0.0/24 via: 10.10.55.2
I will give a general example:
network: ethernets: ens4f0: addresses: - 10.10.20.2/24 gateway4: 10.10.20.1 nameservers: addresses: [18.104.22.168] routes: - to: 10.0.0.0/24 via: 10.10.55.2 - to: 10.0.1.0/24 via: 10.10.55.2 - to: 172.17.0.1 via: 10.10.55.2 on-link: true version: 2
To verify the configuration, execute:
sudo netplan try
And for confirmation, press the “ENTER” key, if the connection is lost and not press “ENTER”, then after 120 seconds the previous configuration will be restored.
Check the route:
ip route get 172.17.0.1