mirror of
https://github.com/mageddo/dns-proxy-server.git
synced 2026-04-25 09:25:56 +03:00
[GH-ISSUE #244] Breaks DNS resolution within containers #99
Labels
No labels
bug
confirmed
discussion
duplicate
enhancement
feature
feature-request
not-planned
pull-request
secondary-feature
stale
triage
waiting-feedback
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set.
Reference
starred/dns-proxy-server-mageddo#99
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Originally created by @hydrargyrum on GitHub (Jun 24, 2022).
Original GitHub issue: https://github.com/mageddo/dns-proxy-server/issues/244
What is Happening
Without DPS:
While DPS is running (wait a few seconds):
As soon as I quit DPS, containers can resolve hosts again.
What is expected
DNS resolution should work fine in containers regardless of DPS being run.
Steps to Reproduce
docker-compose.ymlto run DPS:docker run --rm -it alpine nslookup docker.ioshould expose the problemSpecs:
20.10.5+dfsg12.19.0@sh3bang commented on GitHub (Oct 6, 2022):
I've found the problem .... we should start DNS Proxy within the same Network as any Service that wants to reach the DNS Proxy ;-)
Create a new Network:
docker network create foobarStart DPS within the Network:
Test within the Nework:
docker run--rm --network=foobar -it alpine nslookup docker.ioResult:
@71walceli commented on GitHub (Feb 6, 2023):
Well, the last one is a workaround that requires every container to connect to a shared Docker network, which requires invoking containers with given net or declare the external in docker-compose of all my services. I don't really want to make this container be accessible by others, just using it for the convenience of typing hostnames in my browser and having it automatically resolve, not for any other containers to talk to each other.
This is my config for this container, as suggested by the docs:
The annoying part is:
But I have port 53 published in my config, with which I expect the last entry to point to localhost:53, passing the DNS queries to actual localhost, then, by extension, every other container should be able to connect, right?
That might still break docker isolation, even allowing for leacage of other container records. Then I tried setting it to run with host network mode, like this:
With that, I get the following resolv.conf:
This lets normal DNS work fine, but then mageddo doesn't do its magic, i.e. I can't just resolve any docker container anymore, though Internet access is all good.
Another side effect is:
Then DNS might actually be broken... I'm still stuck! What now?
@mageddo commented on GitHub (Feb 25, 2023):
Update: deleted that comment as it won't contribute to the discussion
@hydrargyrum commented on GitHub (Feb 25, 2023):
After the
&&, it runs on the host, not in the container. The shell parses it into 2 commands:docker run --rm -it alpine sleep 0.5nslookup google.com@mageddo commented on GitHub (Feb 25, 2023):
@71walceli as you are exposing port 53, it would be better to not volume
/etc/resolv.confand you manually configure it to nameserver127.0.0.1, actually DPS won't understand that 127.0.0.1 would be a better option on that case, maybe someday?@mageddo commented on GitHub (Feb 25, 2023):
wow, my mistake, so hold on.
@mageddo commented on GitHub (Feb 25, 2023):
Because of docker network isolation,
docker-compose upcontainers runs at one subnet anddocker run..runs containers at other, that's why the containers can't talk with each other and also can't talk with DPS container.Scenarios where you won't get the issue
docker run ...As @71walceli said, run dps on host mode or something like that should fix the issue but didn't though, I think that's because the poor DPS integration with
system-resolvedas pointed in https://github.com/mageddo/dns-proxy-server/issues/248 , so I will try to do integration withsystem-resolvedusing the right way and see what happens.Can any of you confirm if you are using
system-resolved? Probably yes...@mageddo commented on GitHub (Feb 25, 2023):
By using systemd-resolved instead of overwrite
/etc/resolv.confseems to solve all my issues, so try the following:docker-compose.yml
Then try some queries
Or even
client.yml
👋 But first, you need to configure systemd-resolved:
How to configure systemd-resolved:
=> 1 Start a DPS container by using the previous yaml I provided
=> 2 Choose one of the following IPs which will be logged at the
server.dns.UDPServerPool m=start ...line=> 3 Put the chosed IP at the resolved conf file
=> 4 Restarts systemd-resolved
You can check
cat /run/systemd/resolve/resolv.confto see how the servers are configured, DPS IP must be in the first line.Done.
Additional information:
If you configure DPS docker service with
restart: unless-stoppedyou will only need to run this process once, DPS will start after every reboot and the IP won't change as the host machine IP is being used.You can also run DPS without host network mode, like this:
I will write a feature (#248) to automatically configure
systemd-resolvedwhen available at the OS but it will only possible when DPS is not running in a container becausesystemd-resolvedrestart is required on the host and I can't do that inside a container.Wow, I've learned a lot here, can you try it out and give me some feedback please?
Best regards.
@mageddo commented on GitHub (Feb 25, 2023):
Also will update the running it docs to mention that after the pull request
@mageddo commented on GitHub (Feb 26, 2023):
The feature is alive at DPS 3.4, please check it out and give me a feedback if possible. See #321 for some instructions of how to use it, I will update the docs later.
I'm using the following command:
@71walceli commented on GitHub (Feb 26, 2023):
Anyway, I resorted to startng it up with following
docker-compose.yml. though I'm looking towatd trying @mageddo's proposed workaround.To set it up only for my host OS, I needed to get its IP by issuing command
docker inspect mageddo-dns:# ...is other datails about the container, of which there are a lot. One only needs to get the container IP by looking forNetworkSettings > Networks > mageddo_default > IPAddress. If you ran mageddo usingdocker run ..., it would beNetworkSettings > Networks > bridge > IPAddress.Then I edited
/etc/resolvconf/resolv.conf.d/headand added it's IP, leaving it like this:So i made
/etc/resolv.confbe updated to:This is the way I'm running for now. I thik this still isn't good enough, since Docker containers can't really connect to mageddo, so they might stall for several seconds, but haven't really tested or measured it. Of course, Google and Cloudfrare mane servers come next. Putthng
8.8.8.8and1.1.1.1before mageddo-dns works OK for the Web, but anytime I query any internal domain, anNXDOMAINerror is raised, which causes Linux's resolvconf to stop there, never actually reaching172.18.0.2@71walceli commented on GitHub (Feb 26, 2023):
Would you mind explaining how I might help by editing the docs?
@mageddo commented on GitHub (Feb 26, 2023):
You just need to edit the *.md at docs dir, this table needs to be updated for example,
@mageddo commented on GitHub (Feb 26, 2023):
Give a try at version 3.4 @71walceli and run DPS as I showed, you probably won't need to manually configure IPs, also all features must work.
I'm not updating docker latest tag as DPS 3 is still in beta, I would say it's more stable than 2.x already, a final release should come shortly.
@mageddo commented on GitHub (Feb 28, 2023):
The docs were updated, I'm considering this issue as fixed, if you have any update please re-open it