Tag Info

Hot answers tagged

60

As Heinzi said below, the best way is to use dig with the +short argument. dig +short unix.stackexchange.com If +short is unavailable for some reason, any one of the following should work: host unix.stackexchange.com | awk '/has address/ { print $4 }' nslookup unix.stackexchange.com | awk '/^Address: / { print $2 }' dig unix.stackexchange.com | awk '/^;; ...


59

With host from the dnsutils package: $ host unix.stackexchange.com unix.stackexchange.com has address 64.34.119.12 (Corrected package name according to the comments. As a note other distributions have host is different packages: Ubuntu bind9-host, openSUSE bind-utils, Frugalware bind.)


33

A general solution is the following: { command1; command2; } | some-other-command


23

I was looking for a way to run a program with modified DNS resolution for testing purposes. For me, the solution was using the HOSTALIASES environment variable: $ echo "foo www.google.com" >> ~/.hosts $ HOSTALIASES=~/.hosts $ wget foo See hostname(7).


22

I have a tool on my machine that seems to do the job. The man page shows it seems to come with mysql... Here is how you could use it: resolveip -s unix.stackexchange.com 64.34.119.12 The return value of this tool is different from 0 if the hostname cannot be resolved : resolveip -s unix.stackexchange.coma resolveip: Unable to find hostid for ...


21

I believe if you want to override the DNS nameserver you merely add a line similar to this in your base file under resolv.conf.d. Example $ sudo vim /etc/resolvconf/resolv.conf.d/base Then put your nameserver list in like so: nameserver 8.8.8.8 nameserver 8.8.4.4 Finally update resolvconf: $ sudo resolvconf -u If you take a look at the man page for ...


20

You should be able to get some reasonable information in: $ cat /etc/resolv.conf


16

The UseDNS option is mostly useless. If the client machines are out there on the Internet, there is a high chance that they don't have any reverse DNS, their reverse DNS doesn't resolve forward, or their DNS doesn't provide any information other than “belongs to this ISP” which the IP address already tells you. In typical configurations, DNS is only used ...


15

The following command using dig allows you to read the result directly without any sed/awk/etc. magic: $ dig +short unix.stackexchange.com 64.34.119.12 dig is also included in the dnsutils package. Note: dig has a return value of 0, even if the name could not be resolved. Thus, you'd need to check if the output is empty instead of checking the return ...


14

You can pass multiple names to dig: dig +nottlid -t any bix.hu www.bix.hu | egrep -v "^;;|^;|^$" | sort


14

TL;DR: Recursive queries are part of the way the internet and DNS work, but not all DNS servers should be receiving recursive queries, and when the ones that shouldn't respond do respond you can get problems. Longer version: Recursion, n: See under Recursion. A recursive DNS query happens when the DNS server you asked for the address of, say, ...


13

There is. From inside the instance, you can run: curl http://169.254.169.254/latest/meta-data/public-ipv4 To get the public DNS hostname, you can change that to: curl http://169.254.169.254/latest/meta-data/public-hostname You can get the private IP for the instance, too: curl http://169.254.169.254/latest/meta-data/local-ipv4 As a side note, you ...


13

Beside the LD_PRELOAD tricks. A simple alternative if you're not using nscd is to copy libnss_files.so to some location of your own like: mkdir -p -- ~/lib && cp /lib/x86_64-linux-gnu/libnss_files.so.2 ~/lib Binary-edit the copy to replace /etc/hosts in there to something the same length like /tmp/hosts. perl -pi -e 's:/etc/hosts:/tmp/hosts:g' ...


12

According to Flush dnsmasq dns cache: dnsmasq is a lightweight DNS, TFTP and DHCP server. It is intended to provide coupled DNS and DHCP service to a LAN. Dnsmasq accepts DNS queries and either answers them from a small, local, cache or forwards them to a real, recursive, DNS server. This software is also installed many cheap routers to cache dns queries. ...


11

What the RFC says is actually immaterial here. The RFC specifies what goes on at the DNS level, but that's moot if ping doesn't make a DNS query in the first place. When ping receives an all-numeric argument, it interprets it as an IP address. IPv4 addresses are technically 32-bit numbers. They are almost always written in dot-decimal notation, so-called ...


11

The solutions given so far mostly work in the simpler case: the hostname directly resolves to a single ip address. This might be the only case where you need to resolve hostnames, but if not, bellow is a discussion on some cases that you might need to handle. Chris Down and Heinzi shortly discussed the case where the hostname resovles to more than one ip ...


11

To avoid the problem with aliases and always get a single IP address ready for use: python -c 'import socket; print socket.gethostbyname("www.example.com")'


10

Put only 127.0.0.1 as a name server in /etc/resolv.conf, and run a DNS cache locally. I recommend Dnsmasq, it's lightweight and easy to setup. On distributions such as Debian and Ubuntu, I also recommend installing the resolvconf package, which takes care of maintaining /etc/resolv.conf when you aren't running a local DNS cache, or of maintaining the DNS ...


10

I think you can also query DNS and it will show you what server returned the result. Try this: dig yourserver.somedomain.xyz And the response should tell you what server(s) returned the result. You can also tell dig to query a specific DNS server.


10

Here's how I do it: nm-tool | grep DNS


10

The hostname command outputs the hostname of the system from the systems local hostname configuration (could be /etc/hostname or /proc/sys/kernel/hostname or other depending on OS). The command ping -c 1 <hostname> is going to perform a lookup through the libc resolver (which may or may not be DNS. e.g., /etc/hosts is not DNS) of the <hostname> ...


9

You can write a wrapper around the libc function to resolve hostnames and look them up in a different file than /etc/hosts. Then run any application you'd like to use your hosts file with LD_PRELOAD=wrapper.so firefox


9

dig uses the OS resolver libraries. nslookup uses is own internal ones. That is why ISC has been trying to get people to stop using nslookup for some time now. It causes confusion.


9

Sure, this arrangement is commonly called "stealth master". For example, see the article Why you should use stealth master DNS. The DNS system does not make a distinction between "primary" and "secondary" DNS servers. There are simply a bunch of NS records listed for each domain, their order or priority is not relevant (they are all presumed to contain the ...


8

The configuration file /etc/resolv.conf contains information that allows a computer connected to a network to resolve names into addresses. Change it to: nameserver 8.8.8.8 nameserver 8.8.4.4 Also check that your dhclient is activated. http://www.malgouyres.fr/linux/configreseau_en.html#resolv


8

The easiest way is to install Bind locally. Most distros default install of Bind will be non-autoritative caching-only. Simply add a logging {} config block (as described in the Bind 9 Configuration Reference) then set your system to use 127.0.0.1 or ::1 as the DNS resolver.


8

Assuming your configured nameserver does not have any cached results at its disposal, how many nameservers must your nameserver query in order to resolve maps.google.com? What command(s) would you use to find all these nameservers? List one from each level and explain why this level is needed. Well, let's pick this one apart. "Assuming your configured ...


8

The first DNS reply isn't ignored. getaddrinfo() didn't return until it received the response to the first AAAA query (ID: 26090). So the real problem here is why your machine hasn't immediately received the response to the AAAA query, while it has received the response for the A query (ID: 54755). One of the differences between getaddrinfo() and ...


7

The reason why you are missing the cache hits is that dig queries the DNS directly. You can try and see whether the cache works with the getent command: getent hosts host.example.com Running a separate caching DNS is a good idea, but you should consider running it on the network level if possible. If each host cache the data separately they will still run ...


7

The local resolver you've set up will not use your ISP's resolver at all by default. It'll starting asking the root directly for answers for everything it needs. The root will hand back answers that say things like "I don't know where www.example.com is; you should go talk to com and here are a set of addresses for how to talk to com" (and off you'd go ...



Only top voted, non community-wiki answers of a minimum length are eligible