1

I am using systemd-networkd. I have one NIC and I am using the following configuration to create multiple IPs:

[Match] Name=usbceth0 [Network] DHCP=ipv4 DNS=8.8.8.8 DNS=8.8.4.4 # LAN_1 [Address] Label=usbceth0:0 Address=192.168.100.10/24 # LAN_2 (4G-LAN) [Address] Label=usbceth0:1 Address=192.168.50.70/24 

If there is a DHCP, usbceth0 gets an IP and gets a gateway assigned. The two added IPs, usbceth0:0 and usbceth0:1 are created normally. I need those to access different LANs. So far so good.

The network of usbceth0:1 has also a gateway at 192.168.50.1.

How can I add this gateway as-well in my configuration? Configure two gateways, one coming from the DHCP and one the 192.168.50.1. Is it possible?

Thanks!

0

1 Answer 1

3

If I understand correctly your primary route (gateway) would be the one from the DHCP and the second would be a back up. So, you can set a static route with bigger metric, which comes in only if the primary is down. You can check your current metrics with route -n.

Using the systemd-networkd the .network file should look like:

[Match] Name=usbceth0 [Network] DHCP=ipv4 DNS=8.8.8.8 DNS=8.8.4.4 # LAN_1 [Address] Label=usbceth0:0 Address=192.168.100.10/24 # LAN_2 (4G-LAN) [Address] Label=usbceth0:1 Address=192.168.50.70/24 # "Static"-Gateway as backup [Route] Gateway=192.168.50.1 #Destination=0.0.0.0/0 Metric=1025 # The Gateway of the DHCP gets the default 1024 

If it complains you can add Destination= and also you can use RouteMetric for the DHCP route if you want to make a custom metric. Don't forget to restart the systemd-networkd.service.

Or you can do it with ip route add 'Destination' via 'Gateway' metric but this won't stay after a reboot

2
  • Correct Angel! The high level idea is this. But how do I configure this (literally)? Can this be done with systemd-networkd or iptables or some other way? Commented May 2, 2020 at 8:23
  • I have edited my answer with the example but as I said above it is not tested so be careful Commented May 2, 2020 at 11:02

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.