[Update] As of Ubuntu 18.04 LTS (server), netplan
is the default wrapper for network management. Configuring Netplan is done through a YAML file, by default /etc/netplan/01-netcfg.yaml
(more details here).
Routing metric is defined by the "metric
" option, which expects a positive integer (100
is the default value generally). Here's the example from the reference page:
network:
version: 2
renderer: networkd
ethernets:
eno1:
addresses:
- 10.0.0.10/24
- 11.0.0.11/24
nameservers:
addresses:
- 8.8.8.8
- 8.8.4.4
routes:
- to: 0.0.0.0/0
via: 10.0.0.1
metric: 100
- to: 0.0.0.0/0
via: 11.0.0.1
metric: 100
The route with the lowest metric
(path length) becomes the "preferred" gateway. (Use: sudo netplan try
to enable changes)
Note that in a roaming environment (multiple connections, going on and off), you might want to set the optional
(boolean) parameter to true
(default is false):
network:
version: 2
ethernets:
enred:
dhcp4: yes
dhcp4-overrides:
route-metric: 100
engreen:
dhcp4: yes
dhcp4-overrides:
route-metric: 200
# this is plugged into a test network that is often
# down - don't wait for it to come up during boot.
optional: true
Notice the slightly different syntax for route metric in the case of DHCP connections.
You can also use NetworkManager
as a renderer, which I suppose (haven't tested myself yet) would let you see/edit that part of the configuration also via GUI tools.
renderer
(scalar)
Use the given networking backend for this definition. Currently supported are networkd
and NetworkManager
. This property can be specified globally in networks:
, for a device type (in e. g. ethernets:
) or for a particular device definition. Default is networkd
.
(The very last 'big' example on the reference page shows such a hybrid use of both renderers).
See also this question (askubuntu).