Netplan. Adding Routes

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: [1.1.1.1]
            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

See also my articles:
How to add a blackhole route
How to configure networking with Netplan
Configuring the Network in Linux

Leave a comment

Leave a Reply