comandos GNU/Linux = nslookup

nslookup Command in Linux: 7 Practical Examples
original no linuxhandbook.com/cor da letra roxa/

nslookup Command in Linux: 7 Practical Examples

O nslookup é um dos comandos populares de rede no Linux usado para consultar os registros do Domain Name System (DNS = Sistema de Nomes de Domínio). Não é novidade que nslookup significa lookup de servidor de nomes

Você pode usar o nslookup para consultar o DNS e obter informações como o endereço IP de um site, servidor de nomes, nome de domínio, etc.

Deixe-me mostrar alguns exemplos do comando nslookup.

1. Obtenha o endereço IP de um site

Na sua forma mais simples. sem nenhuma opção, o lookup retorna o nome de domínio e o endereço IP (IPv4 e IPv6). Um dos usos mais populares do nslookup é obter o endereço IP de um site no Linux usando este método.

nslookup <URL>

Aqui está um exemplo de saída:

nslookup linuxhandbook.com
Server: 127.0.0.53
Address: 127.0.0.53#53

Non-authoritative answer:


Name: linuxhandbook.com
Address: 142.93.143.135
Name: linuxhandbook.com
Address: fd00:0:12:13::8e5d:8f87

O endereço 127.0.0.53 na saída do comando acima é o DNS do meu próprio sistema definido pelo systemd. Em alguns casos, pode ser 8.8.8.8 etc.

O que é resposta não autoritativa?

Na saída do comando nslookup, você frequentemente notará "non-authoritative answer". Isso significa que a resposta que você obteve para sua consulta de DNS está chegando para uma fonte não autoritativa.

É porque quando você usa nslookup, a resposta não vem diretamente do servidor de nomes do servidor que você está consultando. Principalmente, ele vem do servidor de nomes do seu provedor de serviços de Internet.

bugre está TRADUZINDO...

2. Get the name server (NS records)

You can also display just the name servers associated with a domain with nslookup. These name servers store various DNS related records. Usually, a domain has more than one name server for backup purpose.

To display just name servers, all you need to do is to specify the type of your nslookup query:

nslookup -type=ns <URL> 

The sample output for Linux Handbook website is:

nslookup -type=ns linuxhandbook.com
Server: 127.0.0.53
Address: 127.0.0.53#53

Non-authoritative answer:


linuxhandbook.com nameserver = dns2.registrar-servers.com.
linuxhandbook.com nameserver = dns1.registrar-servers.com.

Authoritative answers can be found from:

3. Display MX records

MX records in DNS specify the mail server settings for the domain name. This determines which mail server handles the email for the domain in question.

nslookup -type=mx <URL>

A sample output could be like this:

nslookup -type=mx itsfoss.com
Server: 127.0.0.53
Address: 127.0.0.53#53

Non-authoritative answer:


itsfoss.com mail exchanger = 5 alt2.aspmx.l.google.com.
itsfoss.com mail exchanger = 1 aspmx.l.google.com.
itsfoss.com mail exchanger = 10 alt3.aspmx.l.google.com.
itsfoss.com mail exchanger = 5 alt1.aspmx.l.google.com.
itsfoss.com mail exchanger = 10 alt4.aspmx.l.google.com.

Authoritative answers can be found from:

Do note that sometimes, the mail server settings are not defined and in those cases, the mx query with nslookup could return an output like this:

nslookup -type=mx linuxhandbook.com
Server: 127.0.0.53
Address: 127.0.0.53#53

Non-authoritative answer:


*** Can’t find linuxhandbook.com: No answer

Authoritative answers can be found from:

4. Get SOA record with nslookup

You can query and display the SOA (Start of Authority) record with nslookup by specifying the type of query:

nslookup -type=soa <URL>

A sample output would be like this:

nslookup -type=soa linuxhandbook.com
Server: 127.0.0.53
Address: 127.0.0.53#53

Non-authoritative answer:


linuxhandbook.com
origin = dns1.registrar-servers.com
mail addr = hostmaster.registrar-servers.com
serial = 2019051520
refresh = 43200
retry = 3600
expire = 604800
minimum = 3601

Authoritative answers can be found from:

You can read about the various attributes of the SOA record here.

5. Display all DNS records with nslookup

You can display all the above records (that are set) in one single command using the any option.

nslookup -type=any <URL>

And you’ll see a consolidated output of all above commands:

nslookup -type=any linuxhandbook.com
Server: 127.0.0.53
Address: 127.0.0.53#53

Non-authoritative answer:


linuxhandbook.com
origin = dns1.registrar-servers.com
mail addr = hostmaster.registrar-servers.com
serial = 2019051520
refresh = 43200
retry = 3600
expire = 604800
minimum = 3601
linuxhandbook.com nameserver = dns1.registrar-servers.com.
linuxhandbook.com nameserver = dns2.registrar-servers.com.
Name: linuxhandbook.com
Address: 142.93.143.135

Authoritative answers can be found from:

6. Reverse DNS lookup

So far, you have queried the DNS for a certain domain and got its IP address. You can do the reverse DNS lookup and search for the domain name associated with an IP address.

nslookup <IP_ADDRESS>

For example, if I do a reverse DNS lookup with nslookup on Linux Handbook’s server, this is the answer I get:

nslookup 142.93.143.135
135.143.93.142.in-addr.arpa name = 217283.cloudwaysapps.com.

Authoritative answers can be found from:

You didn’t expect this output, did you? It’s because Linux Handbook is hosted via Cloudways. With Cloudways, you can install multiple WordPress websites in a few clicks. When a new WordPress install is created, it is placed at Cloudways’s own URL. The DNS setting is later changed to the intended website’s address.

This is the reason why the output shows the address of Cloudways instead of linuxhandbook.com

7. Query specific DNS server port with nslookup

DNS servers use TCP protocol and thus the port 53 is used by default. If a DNS server used some other port, you can specify the port in your query with nslookup:

nslookup -port=<Port_Number> <URL>

I think that’s enough material for you to know how to use nslookup command in Linux. If you have questions or suggestions, feel free to leave a comment below.

Sem comentários:

Enviar um comentário