-
Notifications
You must be signed in to change notification settings - Fork 618
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add DNS server to host-agent to use native host resolver #281
Conversation
I have not been able to redirect this to port 53 on a loopback IP, to put it into root@lima-default:~# iptables --flush
root@lima-default:~# iptables -A FORWARD -d 192.168.5.2 -i eth0 -p udp -m udp --dport 8053 -j ACCEPT
root@lima-default:~# iptables -t nat -A PREROUTING -d 192.168.5.2 -p udp -m udp --dport 8053 -j DNAT --to-destination 127.0.53.53:53
root@lima-default:~# iptables -t nat -A POSTROUTING -o eth0 -j MASQUERADE
root@lima-default:~# iptables -vnxL
# Warning: iptables-legacy tables present, use iptables-legacy to see them
Chain INPUT (policy ACCEPT 0 packets, 0 bytes)
pkts bytes target prot opt in out source destination
Chain FORWARD (policy ACCEPT 0 packets, 0 bytes)
pkts bytes target prot opt in out source destination
0 0 ACCEPT udp -- eth0 * 0.0.0.0/0 192.168.5.2 udp dpt:8053
Chain OUTPUT (policy ACCEPT 0 packets, 0 bytes)
pkts bytes target prot opt in out source destination
root@lima-default:~# dig @127.0.53.53 google.com
; <<>> DiG 9.16.8-Ubuntu <<>> @127.0.53.53 google.com
; (1 server found)
;; global options: +cmd
;; connection timed out; no servers could be reached Help wanted! Also cross-compiling for Linux with
|
I forgot to mention that Ubuntu also needs this:
Still didn't work though... |
3f67969
to
15a4350
Compare
I believe the only outstanding issue with this PR is the cross-compilation problem with It looks like cross-compilation for But otherwise I'm pretty pleased with how this turned out. When |
15a4350
to
1cd3aa6
Compare
SGTM.
|
BTW if we can just fix libslirp to use the sane resolver, that will be helpful for non-Lima QEMU users and we can avoid CGO. https://gitlab.freedesktop.org/slirp/libslirp/-/blob/v4.6.1/src/slirp.c#L244 |
I'm afraid that is not as easy as it sounds. Afaict libslirp doesn't implement a DNS server; it simply looks up nameserver addresses, picks one (at random?), and then forwards the traffic to that server. And since it is just forwarding packets, it can't even fail over to another server if the chosen one fails. The line you linked to gets the nameserver address from https://gitlab.freedesktop.org/slirp/libslirp/-/blob/v4.6.1/src/slirp.c#L138 Afaik the local resolver on macOS is not exposed via DNS, so you would have to include a DNS server & client implementation inside libslirp, and we obviously couldn't use the Go library for that. So while this would be great to have, I'm not volunteering to work on it, given that it seems to be a rather huge effort. With systemd-resolved you get this out of the box: you configure the resolver, and it then exposes the resolver via DNS again at For Lima I think this PR provides all the functionality we need (famous last words alert). You can even add names to |
f09603a
to
11ba276
Compare
@AkihiroSuda I think the PR is now ready for final review. I will test the darwin-aarch64 binaries tomorrow; but don't have real hardware to test the linux-arm64 binaries right now. If you think everything looks fine, maybe you could create a |
This is is required to correctly resolve hostnames while using conditional forwarding (split-DNS) when connected to a VPN. The hostagent must be compiled with CGO_ENABLED=1 to use the native resolver. Signed-off-by: Jan Dubois <[email protected]>
Cross-compiling from amd64 to arm64 with CGO_ENABLED=1 seems to only work when GOOS is the same between compile host and target. Signed-off-by: Jan Dubois <[email protected]>
11ba276
to
703d9c8
Compare
I've tested the jan@m1 ~ % echo "1.2.3.4 foobar.example.com" | sudo tee -a /etc/hosts
Password:
1.2.3.4 foobar.example.com
jan@m1 ~ % lima host foobar.example.com
foobar.example.com has address 1.2.3.4
Host foobar.example.com not found: 3(NXDOMAIN)
Host foobar.example.com not found: 3(NXDOMAIN) So I think this is ready for merging 😄 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks
This is is required to correctly resolve hostnames while using conditional forwarding (split-DNS) when connected to a VPN.
The hostagent must be compiled with CGO_ENABLED=1 to use the native resolver.
The DNS server is listening for UDP connections on the same port number used for SSH:
It is then forwarded via iptables to
192.168.5.3:53
, replacing the DNS supplied by QEMU.Fixes #270
See also rancher-sandbox/rancher-desktop#702