Binding client socket to device (e.g. using dig)

Robert Edmonds edmonds at mycre.ws
Wed May 23 17:46:25 UTC 2018


Aleksander Morgado wrote:
> I tried to use the "-b IP#PORT" option in dig to bind the queries to
> the IP addresses of either eth0 or wwan0, but that is only making the
> source packets bind to a specific IP address, the actual packet gets
> still routed via the default route with lowest metric.

> Is there any other way to achieve the same thing? (without adding
> additional explicit routes to the DNS servers...)

Hi, Aleksander:

I have this working nicely using the kernel's routing policy database. I
use a multipath default route but I think it should work fine with
multiple default routes with different metrics.

See the LARTC HOWTO for details, e.g.
http://lartc.org/howto/lartc.rpdb.multiple-links.html.

    root at 845s:~# ip route show 0.0.0.0/0
    default
        nexthop via 204.77.234.45  dev onering0 weight 1
        nexthop via 73.43.56.1  dev xfinity0 weight 256

    root at 845s:~# ip -4 addr show dev onering0
    7: onering0 at eno4: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc noqueue state UP group default qlen 1000
        inet 204.77.234.46/30 brd 204.77.234.47 scope global onering0
           valid_lft forever preferred_lft forever

    root at 845s:~# ip -4 addr show dev xfinity0
    8: xfinity0 at eno3: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc fq state UP group default qlen 1000
        inet 73.43.56.148/21 scope global xfinity0
           valid_lft forever preferred_lft forever

    root at 845s:~# dig +short +norec @ns1.fastly.net whoami.fastly.net -b 204.77.234.46
    204.77.234.46

    root at 845s:~# dig +short +norec @ns1.fastly.net whoami.fastly.net -b 73.43.56.148
    73.43.56.148

    root at 845s:~# ip rule show
    0:	from all lookup local
    [...]
    25358:	from 73.43.56.148 lookup 1
    [...]
    25360:	from 204.77.234.46 lookup 3
    [...]
    32766:	from all lookup main
    32767:	from all lookup default

    root at 845s:~# ip route show table 1
    default via 73.43.56.1 dev xfinity0 proto static

    root at 845s:~# ip route show table 3
    default via 204.77.234.45 dev onering0 proto static

--
Robert Edmonds


More information about the bind-workers mailing list