Skip to content
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

How does DNS resoluton work? #67

Open
ur5us opened this issue Oct 14, 2020 · 6 comments
Open

How does DNS resoluton work? #67

ur5us opened this issue Oct 14, 2020 · 6 comments
Labels
question Further information is requested

Comments

@ur5us
Copy link

ur5us commented Oct 14, 2020

I’d like to map a few domains/hosts to certain IP address, e.g. to load test a new server. I tried the following things:

  • docker run --rm -it --add-host example.com:10.0.0.1 nakabonne/ali ali example.com
  • docker run --rm -it -v $(pwd)/hosts:/etc/hosts nakabonne/ali ali example.com with a custom hosts file mapped into the container
  • docker run --rm -it --network=host nakabonne/ali ali example.com with a modified hosts file on the docker host

but none of the above worked for me. Instead, ali would always hit the original server.

@nakabonne
Copy link
Owner

@ur5us Hi, sorry for the delay. I'm planning to support the --resolvers option which specifies custom DNS resolver addresses to use for name resolution instead of the ones configured by the operating system. It may be resolved with it.

@nakabonne nakabonne added the question Further information is requested label Oct 18, 2020
@nakabonne nakabonne added good first issue Good for newcomers and removed good first issue Good for newcomers labels Nov 16, 2020
@nakabonne
Copy link
Owner

nakabonne commented Nov 16, 2020

@ur5us It may be an issue related to golang/go#22846. Could you give it a try to do this solution? Alternatively, try to use cgo-enabled Go binary which can be installed with go get github.com/nakabonne/ali.

@nakabonne
Copy link
Owner

@ur5us I'd say the root cause is the DNS cache. Clearing the cache and then running it should reference the domain in the hosts file.

For instance, on macOS:

$ sudo killall -HUP mDNSResponder
$ docker run --rm -it -v /etc/hosts:/etc/hosts nakabonne/ali ali http://example.com

@ur5us
Copy link
Author

ur5us commented Nov 16, 2020

@nakabonne If you look at the 2nd example this is exactly what I did!

docker run --rm -it -v $(pwd)/hosts:/etc/hosts nakabonne/ali ali example.com

The only difference is that I used a custom hosts file ($(pwd)/hosts) instead of /etc/hosts. That custom hosts file simply contains one line with the custom entry I needed. Note, the whole issue only occurred with Docker. I haven’t tried running it on the host (without Docker). However, I did try modifying the host’s /etc/hosts file as per 3rd example. On the host itself using curl for instance or other programs would correctly resolve as per /etc/hosts file! Thus, I don’t think I’ve tried clearing the DNS cache as everything DNS related worked as expected otherwise. I don’t know if Docker ignores/bypasses the host’s /etc/hosts entirely but then again that’s why I tried mapping a custom $(pwd)/hosts file into the Docker container which didn’t work either. I’ll try a few more scenarios and explicitly clearing the host’s DNS cache though I’d still expect a custom hosts file mapped to /etc/hosts in the container to always work no matter what.

@nakabonne
Copy link
Owner

nakabonne commented Nov 16, 2020

@ur5us Your 3rd example (with modifying the host’s /etc/hosts file) was worked for me! What error does it emit? Your example looks to lack the http:// scheme. It may be why.

docker run --rm -it --network=host nakabonne/ali ali http://example.com

@nakabonne
Copy link
Owner

And I was able to repro the issue about custom hosts file mapped into the container with v $(pwd)/hosts:/etc/hosts. While I don't get in detail, Docker looks to refer to the host's /etc/hosts file by default.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Further information is requested
Projects
None yet
Development

No branches or pull requests

2 participants