Host command and a little about DNS
- Gerar link
- X
- Outros aplicativos
Of course you already know the host command but let's go over what we know, because a review is never too much.
To resolve a name to an IP:
$ host www.intelligencesoftware.com.br
www.intelligencesoftware.com.br has address 199.36.158.100
Okay, but how did he get this information? I have a linux here and the DNS servers are stored in the "resolv.conf" file, in practice this file is no longer used, it was used in older versions, now who manages the nameserver is the network manager. The resolv.conf file follows for example.
$ cat /etc/resolv.conf
nameserver 127.0.0.53
options edns0 trust-ad
You could configure nameservers (which are dns resolvers) manually with the directives:
nameserver (server IP)
But in my case it is configured to automatically search the nameservers by dhcp, running this command it shows who my dns is:
$ nmcli device show wlp2s0 | grep IP4.DNS
IP4.DNS[1]: 192.168.1.254
Where wlp2s0 is is the network interface. But what about setting up static nameservers now? This you do in the directory
/etc/netplan
and editing the file
01-network-manager-all.yaml
, there are ways for you to edit this file to set the network settings in a fixed way and then yes you can indicate the dns addresses.
Well now we know that when executing the host command above it makes a query using the nameserver configured on the machine itself, either fixedly or by dhcp, but before that it makes another query it looks for entries in the file
/etc/hosts
in this file you can insert your own dns entries to resolve local names, here is an example of the file:
$cat /etc/hosts
127.0.0.1 localhost
127.0.1.1 nevermind
192.168.1.64 test.com
# The following lines are desirable for IPv6 capable hosts
::1 ip6-localhost ip6-loopback
fe00::0 ip6-localnet
ff00::0 ip6-mcastprefix
ff02::1 ip6-allnodes
ff02::2 ip6-allrouters
See that there is a test.com entry pointing to 192.168.1.64, this one I added to test a web application that could be accessed only with a DNS note because it used virtualhost. This /etc/host file is a first form of dns that came up, it is present in windows too. It was created because we remember names better than numbers and was the first alternative to translate names to IPs, but with the growth of the network it became impossible for each new service made available to have to add a new entry in the hosts on each of the computers belonging to the network that was when the domain system emerged and evolved into what it is today, so there is better management of how to register new domains and applications.
Ok. To do a dns query, it is first searched in the /etc/hosts file after it searches in the nameserver that is on the machine, be it fixed, ie by dhcp. And that's it, that's it for a dns query to be done. But there's more, and if I want to indicate a name server for my query, I use the host command like this:
$ host www.intelligencesoftware.com.br 8.8.8.8
Using domain server:
Name: 8.8.8.8
Address: 8.8.8.8#53
Aliases: www.intelligencesoftware.com.br has address 199.36.158.100
See that now, instead of asking the question for the dns configured on the machine, he asked for the google DNS, this answer was the google DNS and not the dns configured on the machine.
Ok. But there are other commands besides the host, there is also nslookup, there is dig, and dns has other types of input like A, AAAA, NS, MX and others.
Yes there is a lot more about DNS but for now we're left with that, see you in a next post where I intend to talk more about other issues and go even further with DNS.
- Gerar link
- X
- Outros aplicativos
Comentários
Postar um comentário