I need help with a (simple) network configuration with netplan. It is very simple, I have 2 NICs: enp5s0 is ethernet and give access to the company network, and wlp4s0 is WiFi and give access to Internet via a router.
I just want the Internet traffic to be routed via the WiFi connection. The netplan configuration should be something like:
network:
version: 2
renderer: NetworkManager
ethernets:
enp5s0:
dhcp4: true
routes:
- to: 192.168.1.0/24
via: 192.168.1.1
wifis:
wlp4s0:
dhcp4: true
access-points:
"My WiFi Network":
password: "foobar"
gateway4: 10.128.128.128
routes:
- to: 0.0.0.0/0
via: 10.128.128.128
But it is not working. Surprisingly it is very easy to add the routes from the command line:
sudo route add -net 192.168.1.0 netmask 255.255.255.0 gw 192.168.1.1 dev enp5s0
sudo route del default gw 192.168.1.1
sudo route add default gw 10.128.128.128
And this works like a charm. I just want to do that with netplan...
I answer to myself: dhcp may reset the default gateway, and the metrics we could specify in the netplan configuration are also overridden.
This works:
This information should help.
DHCP Overrides
Several DHCP behavior overrides are available. Most currently only have any effect when using the networkd backend, with the exception of use-routes and route-metric.
Overrides only have an effect if the corresponding dhcp4 or dhcp6 is set to true.
If both dhcp4 and dhcp6 are true, the networkd backend requires that dhcp4-overrides and dhcp6-overrides contain the same keys and values. If the values do not match, an error will be shown and the network configuration will not be applied.
use-routes (bool)
Default: true. When true, the routes received from the DHCP server will be installed in the routing table normally. When set to false, routes from the DHCP server will be ignored: in this case, the user is responsible for adding static routes if necessary for correct network operation. This allows users to avoid installing a default gateway for interfaces configured via DHCP. Available for both the networkd and NetworkManager backends.
And read the section:
Routing
source: https://netplan.io/reference