UDP replies use wrong network interface in multihomed configuration

The device has two WAN connections with different metrics. The TCP services hosted on the device are available on both WAN IPs.

UDP services hosted on the device:

  1. UDP service responds via eth0 if incoming packet came in throw the eth0 and this is as expected.
  2. UDP service also responds via eth0 even if incoming packet came in throw the eth1 (checked with tcpdump). As a result the service is unavailable on the second WAN IP.

How to make UDP services available on both IPs?

ip r
default via 17.150.87.225 dev eth0 proto static src 17.150.87.233 metric 5
default via 172.16.99.1 dev eth1 proto static metric 100
...
2: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc fq_codel state UP group default qlen 1000
    link/ether xx:xx:xx:xx:xx:xx brd ff:ff:ff:ff:ff:ff
    inet 17.150.87.233/27 brd 17.150.87.255 scope global eth0
  ...
3: eth1: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc fq_codel state UP group default qlen 1000
    link/ether xx:xx:xx:xx:xx:xx brd ff:ff:ff:ff:ff:ff
    inet 172.16.99.102/24 brd 172.16.99.255 scope global eth1
       valid_lft forever preferred_lft forever
...

You can try using policy based routing e.g. setup a routing table with default routing via eth1 and make a rule to route traffic by port or ip address via that routing table

1 Like

ever wondered why dns and dhcp uses one listener per IP address?

Thanks for your advice. There was insufficient diagnosis on my part. There is no problems with udp multihoming on OpenWrt. It turned out that the problem was with exactly one service - OpenVPN (https://community.openvpn.net/openvpn/ticket/442). Configuration option --multihome resolves the issue.