Linux – Configuring routing with systemd-networkd via a gateway results in error: Could not set route: Network is unreachable

linuxnetworkingroutingsystemd

I run several LXC containers on my machine, some of which have their own IP address outside a network shared with the host. This IP address, as well as the corresponding network mask and gateway was provided to me by my ISP. I am using systemd 238 and tried following configuration [1]:

[Match]
Name=enpXsY

[Network]
Address=192.168.0.2/24
Gateway=192.168.0.1
IPForward=yes

[Route]
Destination=10.0.0.64/29
Gateway=10.0.0.65

In the systemd-networkd logs I see following error: Could not set route: Network is unreachable, but I cannot really explain this. If I do not specify a gateway, the kernel can route to this network just fine. Thus I would assume it would also be able to route the traffic to the gateway through this same interface. This does not even work, if I specify a route with Destination=10.0.0.65/32 before the route to 10.0.0.64/29, in order to take the kernel by the hand and explain how to reach that network.

UPDATE: In the meantime I changed the host's network configuration significantly, but these were the IPv4 addresses and routes it was configured with [1]:

# ip -4 address
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN group default qlen 1000
    inet 127.0.0.1/8 scope host lo
       valid_lft forever preferred_lft forever
2: enpXsY: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc noqueue state UP group default qlen 1000
    inet 192.168.0.2/24 brd 192.168.0.255 scope global enpXsY
       valid_lft forever preferred_lft forever
4: lxcbr0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc noqueue state UP group default qlen 1000
    inet 10.10.10.1/24 brd 10.10.10.255 scope global lxcbr0
       valid_lft forever preferred_lft forever

# ip -4 route
default via 192.168.0.1 dev enpXsY proto static 
192.168.0.0/24 dev enpXsY proto kernel scope link src 192.168.0.2
10.10.10.0/24 dev lxcbr0 proto kernel scope link src 10.10.10.1 

[1]: I translated the actual IP-addresses into similar addresses in non-routed networks for privacy reasons.

Best Answer

In the systemd-networkd logs I see following error: Could not set route: Network is unreachable, but I cannot really explain this.

Well this tells you what the actual problem is. You need to have the router within the Subnet of one the IP addresses assigned to any one network interface.

In your case, you have an IP address of 192.168.0.2 with and subnet mask of 24. The gateway is at 192.168.0.1 which should be find as it is within the subnet.

The problem occurs within this section:

[Route]
Destination=10.0.0.64/29
Gateway=10.0.0.65

If you do not have other systemd-networkd configuration files that specify na interface with an IP address within 10.0.0.64/29 systemd-networkd does not know how to reach the gateway of 10.0.0.65. Note that the file names regulate the order in which the files are being processed as they are sorted lexically prior to execution. As I stated above, the gateway has to be next-hop which means that it is within a particular subnet known to the host.

Related Question