How do I make dig use a source IP other than localhost while querying a DNS server running locally on my machine? - linux

I am trying to run a coredns plugin https://github.com/coredns/demo that returns 1.1.1.1 for 172.0.0.0/8 or 127.0.0.0/8 and 8.8.8.8 for everything else.
I run the binary and try to make a request from dig using dig example.org #localhost -p1053 +short which returns 1.1.1.1 since the request is sent from localhost
Is there anyway I can send a request from dig to coredns that it might look like to the DNS server that it is sent from another IP and it will return 8.8.8.8 instead?

From dig manual:
-b address[#port]
Set the source IP address of the query. The address must be a valid address on one of the host's network interfaces, or "0.0.0.0" or "::". An optional port may be
specified by appending "#<port>"
Otherwise, if the server supports ECS (EDNS Client Subnet) you can use dig option +subnet=addr to give it to the server and see how its reply changes.

Related

How to make an alias for localhost that has a tld?

I was wondering how I would make an alias for localhost that has a tld.
For example, foo.test wold connect to 127.0.0.1.
I tried just adding a second line to /etc/hosts that also pointed to 127.0.0.1, but that didn't seem to work. Although, I didn't reboot, so that might be why.
The end goal is to have it so that I can test that a request is being sent to a specific subdomain in the Rocket framework for Rust. IE: foo.bar.test instead of baz.bar.test or just bar.test.
The man page for /etc/hosts says:
IP CANONICAL ALIAS ...
127.0.0.1 foo.test localhost
Should be good
But is the host really handling traffic from this IP address ?
Alternatively, the interface specific line can include the aliases
10.0.0.1 foo.bar.test foo
10.0.0.2 baz.bar.test baz

How can I use a custom DNS server in Azure App Services with Linux?

I have a .NET Core API App running in Azure App Services using Windows, but now I want to test it using Linux. The app uses a custom DNS Zone just to map a custom hostname to a specific IP address.
To implement that in my Windows App Service I used the following Application Settings as stated in this page: WEBSITE_DNS_SERVER and WEBSITE_ALT_DNS_SERVER. Although it looks like a workaround, it works pretty well with Windows App Services. But in Linux it seems to have no effect and my app is not resolving the hostname as needed.
How can I use a custom DNS server in Azure App Service with Linux or add a custom hostname like editing the hosts file?
Unlike our App Service Windows, nameresolver.exe is not available and the Application settings for "WEBSITES_ALT_DNS" and "WEBSITES_DNS" do not populate the configuration files within the container. Below are steps are troubleshooting issues for "Alpine" based images since you don’t mention if you are using a Linux container or the default Linux OS.
Install Bind-tools-
apk update
apk add bind-tools
Run Nslookup-
Once bind-tools is installed, you'll see the server that is being used. If bind-tools are not installed, the DNS server will not be shown. Example provided below.
9031977be93a:~# nslookup google.com
Server: 127.0.0.11
Address: 127.0.0.11#53
Non-authoritative answer:
Name: google.com
Address: 216.58.194.174
Name: google.com
Address: 2607:f8b0:4005:801::200e
Update Config file-
To use a different DNS server for testing, update the /etc/resolv.conf file and update the "nameserver" to use a different DNS server. In this example, we're using Googles DNS.
vi /etc/resolv.conf
By default, the following will be in the resolv.conf file.
search reddog.microsoft.com
nameserver 127.0.0.11
options timeout:1 attempts:5 ndots:0cd /etc
If you're not familiar with "vi", press "i" on your keyboard to begin editing the file.
Once you're done, press "esc" and ":wq!" then enter.
search reddog.microsoft.com
nameserver 8.8.8.8
options timeout:1 attempts:5 ndots:0
Running Nslookup again, you'll see the new nameserver being used.
9031977be93a:~# nslookup google.com
Server: 8.8.8.8
Address: 8.8.8.8#53
Non-authoritative answer:
Name: google.com
Address: 216.58.194.174
Name: google.com
Address: 2607:f8b0:4005:804::200e
Hardcoding Hostname-
You can also hardcode the IP address for the hostname in question for testing. To do so, you'll need to update the following file.
vi /etc/hosts
Add the IP address that you would like the DNS to point to. In this example, I'm changing the IP for my custom domain.
127.0.0.1 localhost
::1 localhost ip6-localhost ip6-loopback
fe00::0 ip6-localnet
ff00::0 ip6-mcastprefix
ff02::1 ip6-allnodes
ff02::2 ip6-allrouters
172.20.0.2 9031977be93a
10.10.10.10 www.polytechniks.com
Save the changes and use "ping" or "traceroute" to see the IP being used. NOTE: Nslookup does NOT use the /etc/hosts file so you will still see the IP address associated with the DNS.
9031977be93a:~# ping www.polytechniks.com
PING www.polytechniks.com (10.10.10.10): 56 data bytes
--- www.polytechniks.com ping statistics ---
8 packets transmitted, 0 packets received, 100% packet loss
9031977be93a:~# traceroute www.polytechniks.com
traceroute to www.polytechniks.com (10.10.10.10), 30 hops max, 46 byte packets
1 172.20.0.1 (172.20.0.1) 0.005 ms 0.004 ms 0.004 ms

dnsmasq doesn't resolve internal IP address

I have a openwrt router, and a client linux connected to it. I config the dnsmasq with
resolv-file=/tmp/resolv.conf.auto
For example, when I use nslookup on the client, nslookup google.com is OK, but nslookup bd.ysmood.org says No answer.
How to make the router work properly?
OK, since the bd.ysmood.org is an internal IP address. The dnsmasq's rebind_protection will make the lookup fail.
Edit the /etc/config/dhcp, find the line:
option rebind_protection 1
Change the 1 to 0 will do it.

host doing unnecessary dns lookup for localhost

I have a centOS system(embedded and has very binaries) with the following /etc/hosts.
$cat /etc/hosts
127.0.0.1 localhost localhost
Also the host is assigned a DNS server which returns some invalid IP for the domain name lookup of localhost. But I cannot avoid a connection to this DNS due to some network restrictions.
My question is, when I already have a valid /etc/hosts file why is the system querying the DNS for localhost? And how can I stop that?
Any help would be greatly appreciated.
Check that you have files listed before dns for the hosts entry in /etc/nsswitch.conf.
[me#home]$ grep "^hosts" /etc/nsswitch.conf
hosts: files dns
If dns comes first, then your system will always query DNS to resolve hostnames before falling back to /etc/hosts.

receive all public hostnames in a bind (linux) server

I need to save all public hostnames, that usually can be detected with a dns query, in my dns server (bind9 in a kubuntu distribution), and after I need to open this list to elaborate it in a c++ program.
How is it possible to do this saving operation? Thanks a lot!
You can use host or dig command to run axfr query and redirect output to file:
host -t axfr yourdomain.com > records.txt
or
dig yourdomain.com axfr > records.txt
You can do this directly in dns server or any other host that has Bind's permission to do so.
Note that you have to have tcp port 53 open to your dns server if you use external host to run query.

Resources