I want to use loopback alias IP for all outcome IP traffic from my Ubuntu server directed to some subnets.

In /etc/network/interfaces that can be done by post-up statement with something like:

/sbin/ip route add via src

Is there a way to do that with Netplan and Networkd?


For information about configuring source-based policy routing in netplan, see: https://netplan.io/examples#source-routing

|improve this answer|||||
  • This is not source-based policy routing, it's destination base pbr with src-ip replacing. I want It to simulate some cisco-like logic with loopback address as source IP for outgoing packets. – user1227888 Jun 1 '18 at 10:04

The 'from' property of routes does the equivalent of src in ip route. I think your route would be:

     - to:

Be aware that:

  • Because of LP: #1767849, this doesn't work at all until you get netplan 0.40. As of 2018-09-27, this hasn't been released for Bionic yet, only the still in-development Cosmic.
  • even with that fix, it doesn't work reliably for IPv6, because of systemd bug #5882. (You can work around this by running 'netplan apply' late in boot.)
|improve this answer|||||

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.