1

Basically what i want to do is:

~$ ip addr add 51.255.174.122/32 dev eth0
~$ ip route add 51.255.68.1 dev eth0
~$ ip route add default via 51.255.68.1

what i tried is: /etc/systemd/network/wired.network

[Match]
Name=eth0

[Network]
Address=51.255.174.122/32
Gateway=51.255.68.1

when i tried ip route there is no output. What have i done wrong and what is the correct way to do this ?

  • 1
    The solution to this question works for me. http://serverfault.com/questions/667319/systemd-networkd-and-direct-routes. However i cant understand it. –  Nov 11 '16 at 15:16
  • In theory, that isn't possible, but it has been done in practice. The idea of a gateway is that it is the network address in your network to where traffic destined for a different network gets sent. if the gateway address is in a different network, your address should not know how to get to the gateway address because it is on a different network. Basically, to get to a different network, you use the gateway, but the gateway is on a different network, so you must use the gateway to get to itself. – Ron Maupin Nov 11 '16 at 15:49
  • @Shankar this works because a Point to Point network literally only has _one_ place to send packets to. So it just sends them to the other end of the link and crosses its fingers that the receiver knows how to deal with it. This has been done on some networks I've read about that run /31 or /32 _everywhere_ on ethernet links, essentially eliminating L2. But it also usually involves running a routing daemon on each node. The exception is Point-to-point protocols like, uuh, PPP (which stands for Point to Point Protocol). It's very common on DSL connections. – Mark Henderson Nov 11 '16 at 15:55

2 Answers2

1

Gateway=51.255.68.1 try with GatewayOnLink= in route section it should work. https://www.freedesktop.org/software/systemd/man/systemd.network.html#GatewayOnlink=

user29005
  • 11
  • 1
0

I had a similar issue, where I needed to setup systemd-networkd with a gateway on a completely different subnet (because of the addresses the ISP gave me).

The answer by user29005 pointed me towards the solution. Here's how I got it working in Arch Linux.

/etc/systemd/network/20-wired.network:

[Match]
Name=ens18

[Network]
Address=51.0.0.1
DNS=XX.XX.XX.XX

[Route]
Gateway=37.0.0.254
GatewayOnLink=true

The GatewayOnLink=true line solves the 'unreachable next-hop' error.

Hope that helps,

D

Danyright
  • 203
  • 1
  • 7