You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I have 2 network interfaces (ethernet and WiFi or 3G) and configure DNS servers on specific interfaces. When I ask resolved to resolve using the 3G or WiFi interface, I want the request to be send through that interface, to the configured server.
Unexpected behaviour you saw
When I ask resolved to resolve on a specific interface (e.g. 3G or WiFi) it will use the expected DNS server, but the request will be sent through the ethernet interface (which has the default route with the best metric). When using 3G dongles, you sometimes have a DNS server with a public IP (i.e. Linux thinks it can be contacted with any default route), but this server will only accept requests coming from the 3G network. In this case, I am unable to resolve requests in 3G when I am also connected in Ethernet.
Steps to reproduce the problem
Set different DNS servers on the different interfaces. Ask resolved to resolve using the WiFi interface when you are also connected in Ethernet. Using wireshark, you can see that the request will be sent through the Ethernet interface, to the 3G's DNS server.
I am not sure I follow. If you want traffic to some server or subnet routed to some interface, the right approach is to define a route for it.
resolved honours IP routing, and I am very convinced that that's the right approach, and it really shouldn't override regular IP routes. If they aren't set up correctly, then that's a local configuration problem, no? Why not configure and fix that properly? that way it will be solved fully generically, for all programs, and fully correctly, in the original way issues like this are supposed to be fixed.
In my opinion it makes more sense to use the interface associated to a DNS server. Yes my problem could be resolved using routes, but when the DNS servers are received through DHCP the user would have to set the routes manually or to write a plugin to networkmanager (in my case) or networkd to set the routes. I think it would be more user friendly if resolved used the desired interface for DNS servers associated to a link.
In my case this is really problematic with resolved running on an embedded system with an ethernet connection and a 3G dongle for backup (which is a quite common usage). With some mobile network operators, the received DNS servers have a public IP, but can only be accessed through the 3G connection. When no routes are configured just for this specific IP, resolved cannot resolve using this server.
It would also be problematic if one configured resolved with the same DNS server (e.g. 8.8.8.8) in 3G and in ethernet for backup purposes. Resolved would switch between the two servers but would always use the same interface, which would be less resilient.
It seems you are already trying to bind to the interface when creating the socket :
static int dns_scope_socket(
[...]
if (s->link) {
be32_t ifindex_be = htobe32(ifindex);
if (sa.sa.sa_family == AF_INET) {
r = setsockopt(fd, IPPROTO_IP, IP_UNICAST_IF, &ifindex_be, sizeof(ifindex_be));
if (r < 0)
return -errno;
Somehow the setsockopt doesn't return an error (I added some logs to be sure), but the request isn't sent through the desired interface.
But doesn#t that sound as if we should teach networkd a new trick: for all DNS servers configured for an interface add an explicit route to that iface, too. @yuwata@ssahani what do you think? i.a. implicitly synthesize an explicit route for all DNS servers listed in the DHCP lease in addition to the explicitly listed routes in the dhcp lease?
Somehow the setsockopt doesn't return an error (I added some logs to be sure), but the request isn't sent through the desired interface.
hmm, iirc that sockopt is mostly a hint, and relevant only for datagram based stuff, but i don't now the details. it's not really documented unfortunately. (linux...)
From an user's perspective, when I ask resolved to resolve using the interface x, I expect it to send the request on that interface. When reading the doc, it seems pretty clear it should work like that :
ResolveHostname() takes a hostname and acquires one or more IP addresses for it. As parameters it takes the Linux network interface index to execute the query on, or 0 if it may be done on any suitable interface.
It's true, the doc concerning the setsockopt IP_UNICAST_IF is very limited, But from what I've read 1, 2, this is not only a hint and works with UDP and raw sockets. Since resolved is trying to contact the NS server in UDP, this should work.
It seems the DNS requests are send in UDP (seen with wireshark and after adding some logs)
int dns_transaction_go(DnsTransaction *t) {
[...]
if (t->scope->protocol == DNS_PROTOCOL_LLMNR &&
(dns_name_endswith(dns_resource_key_name(t->key), "in-addr.arpa") > 0 ||
dns_name_endswith(dns_resource_key_name(t->key), "ip6.arpa") > 0)) {
/* RFC 4795, Section 2.4. says reverse lookups shall
* always be made via TCP on LLMNR */
r = dns_transaction_emit_tcp(t);
} else {
/* Try via UDP, and if that fails due to large size or lack of
* support try via TCP */
r = dns_transaction_emit_udp(t);
if (r == -EMSGSIZE)
log_debug("Sending query via TCP since it is too large.");
else if (r == -EAGAIN)
log_debug("Sending query via TCP since UDP isn't supported.");
if (IN_SET(r, -EMSGSIZE, -EAGAIN))
r = dns_transaction_emit_tcp(t);
}
From what I've read, it seems the setsockopt should be done with different parameters to make sure it's not overwritten by the routing rules : setsockopt(fd, SOL_SOCKET, SO_BINDTODEVICE, ifname, strlen(ifname));
ifname being the interface's name
I tried to do this, but the setsockopt fails with the following error returned: Operation not permitted
This options needs the CAP_NET_RAW capability, which should be granted to resolved from it's unit file: CapabilityBoundingSet=CAP_SETUID CAP_SETGID CAP_SETPCAP CAP_CHOWN CAP_DAC_OVERRIDE CAP_FOWNER CAP_NET_RAW CAP_NET_BIND_SERVICE
Nevertheless, when I run pscap on the target I can't see any capabilities applied to resolved. What am I missing here ?
Activity
poettering commentedon Mar 11, 2019
I am not sure I follow. If you want traffic to some server or subnet routed to some interface, the right approach is to define a route for it.
resolved honours IP routing, and I am very convinced that that's the right approach, and it really shouldn't override regular IP routes. If they aren't set up correctly, then that's a local configuration problem, no? Why not configure and fix that properly? that way it will be solved fully generically, for all programs, and fully correctly, in the original way issues like this are supposed to be fixed.
What am I missing?
antoinefaure commentedon Mar 11, 2019
In my opinion it makes more sense to use the interface associated to a DNS server. Yes my problem could be resolved using routes, but when the DNS servers are received through DHCP the user would have to set the routes manually or to write a plugin to networkmanager (in my case) or networkd to set the routes. I think it would be more user friendly if resolved used the desired interface for DNS servers associated to a link.
In my case this is really problematic with resolved running on an embedded system with an ethernet connection and a 3G dongle for backup (which is a quite common usage). With some mobile network operators, the received DNS servers have a public IP, but can only be accessed through the 3G connection. When no routes are configured just for this specific IP, resolved cannot resolve using this server.
It would also be problematic if one configured resolved with the same DNS server (e.g. 8.8.8.8) in 3G and in ethernet for backup purposes. Resolved would switch between the two servers but would always use the same interface, which would be less resilient.
It seems you are already trying to bind to the interface when creating the socket :
Somehow the setsockopt doesn't return an error (I added some logs to be sure), but the request isn't sent through the desired interface.
poettering commentedon Mar 11, 2019
But doesn#t that sound as if we should teach networkd a new trick: for all DNS servers configured for an interface add an explicit route to that iface, too. @yuwata @ssahani what do you think? i.a. implicitly synthesize an explicit route for all DNS servers listed in the DHCP lease in addition to the explicitly listed routes in the dhcp lease?
poettering commentedon Mar 11, 2019
hmm, iirc that sockopt is mostly a hint, and relevant only for datagram based stuff, but i don't now the details. it's not really documented unfortunately. (linux...)
poettering commentedon Mar 11, 2019
I filed #11961 as an RFE bug for this.
I am not sure there's anything actionable here otherwise?
antoinefaure commentedon Mar 11, 2019
From an user's perspective, when I ask resolved to resolve using the interface x, I expect it to send the request on that interface. When reading the doc, it seems pretty clear it should work like that :
antoinefaure commentedon Mar 11, 2019
It's true, the doc concerning the setsockopt IP_UNICAST_IF is very limited, But from what I've read 1, 2, this is not only a hint and works with UDP and raw sockets. Since resolved is trying to contact the NS server in UDP, this should work.
poettering commentedon Mar 11, 2019
resolved uses TCP too
antoinefaure commentedon Mar 11, 2019
It seems the DNS requests are send in UDP (seen with wireshark and after adding some logs)
antoinefaure commentedon Mar 11, 2019
More details on IP_UNICAST_IF
antoinefaure commentedon Mar 12, 2019
Hello,
From what I've read, it seems the
setsockoptshould be done with different parameters to make sure it's not overwritten by the routing rules :setsockopt(fd, SOL_SOCKET, SO_BINDTODEVICE, ifname, strlen(ifname));ifname being the interface's name
I tried to do this, but the
setsockoptfails with the following error returned:Operation not permittedThis options needs the
CAP_NET_RAWcapability, which should be granted to resolved from it's unit file:CapabilityBoundingSet=CAP_SETUID CAP_SETGID CAP_SETPCAP CAP_CHOWN CAP_DAC_OVERRIDE CAP_FOWNER CAP_NET_RAW CAP_NET_BIND_SERVICENevertheless, when I run
pscapon the target I can't see any capabilities applied to resolved. What am I missing here ?poettering commentedon Mar 12, 2019
SO_BINDTODEVICE does not affect routing iirc, all it does is filter ingress datagrams by iface and ignores all datagrams not matching the iface.
antoinefaure commentedon Mar 14, 2019
Hello @poettering
I opened a pull request which solves my issue : #12004
SO_BINDTODEVICEworks for outpound connections as well, and makes sure the socket goes through the desired interfaceI had to keep the capability
CAP_NET_RAWthough160 remaining items
net-next: Fix IP_UNICAST_IF option behavior for connected sockets
net-next: Fix IP_UNICAST_IF option behavior for connected sockets
net-next: Fix IP_UNICAST_IF option behavior for connected sockets
net-next: Fix IP_UNICAST_IF option behavior for connected sockets
net-next: Fix IP_UNICAST_IF option behavior for connected sockets
net-next: Fix IP_UNICAST_IF option behavior for connected sockets
net-next: Fix IP_UNICAST_IF option behavior for connected sockets
net-next: Fix IP_UNICAST_IF option behavior for connected sockets
net-next: Fix IP_UNICAST_IF option behavior for connected sockets
net-next: Fix IP_UNICAST_IF option behavior for connected sockets
net-next: Fix IP_UNICAST_IF option behavior for connected sockets
net-next: Fix IP_UNICAST_IF option behavior for connected sockets
net-next: Fix IP_UNICAST_IF option behavior for connected sockets
net-next: Fix IP_UNICAST_IF option behavior for connected sockets
net-next: Fix IP_UNICAST_IF option behavior for connected sockets