Routing – How to Set Route in Netplan on Ubuntu 18.04

netplanrouteroutingubuntu-18.04

I'm trying to add a route on an Ubuntu 18.04 machine, but I'm missing something.
Traffic to 89.19.153.0/24 needs to go through 10.32.57.142.

This is the config I'm trying in /etc/netplan/99-netcfg-vmware.yaml

enter image description here

After this I run:
netplan apply

Nothing happens.

When I check the routes with route -n I get this:

enter image description here

When I run "sudo netplan –debug generate" I get:

imgae of command result

I realize I'm doing something wrong, but since I'm new to netplan I haven't been able to google up the result.

Thank you for reading.

Best Answer

I also make it a habit to configure the metric. I am not sure if it is necessary!

Remove the gateway4 option and configure them using routes manually if you want to use multiple gateways. (Not needed in this case)

At last. The IP address 10.32.57.142 is not in your subnet. So we need to provide an additional route to it.

Your configuration would become something like:

network:
    version: 2
    renderer: networkd
    ethernets:
        ens192:
            dhcp4: no
            dhcp6: no
            addresses :
                - 10.32.57.8/28
            gateway4: 10.32.57.1
            routes
                - 10.32.57.142/32
                  via 10.32.57.142
                  scope: link
                - to: 84.19.153.0/24
                  via: 10.32.57.142
                  metric: 100
            nameservers:
                addresses:
                    - 8.8.8.8