Linux get name servers

What DNS servers am I using?

The Linux kernel itself is not aware about DNS services. To answer it’s better to know your userland. What distribution are you using? Ubuntu? Debian GNU/Linux? Centos?

14 Answers 14

You should be able to get some reasonable information in:

However, please be aware that (on modern Linuxen) the contents of /etc/nsswitch.conf dictate what name services are used (DNS, LDAP, etc) and in what order. Say fgrep hosts: /etc/nsswitch.conf . If it only references DNS, /etc/resolv.conf is the right place to look for your nameservers. But chances are you’re also using mDNS (aka ZeroConf, aka Avahi, aka Bonjour, etc), etc. In that case, things depend on what you’re using.

This file typically points at 127.0.1.1 on Ubuntu — it’s the local DNS cache server, not the actual upstream.

See the answers by @G32RW or @Lonniebiz for a more robust approach under various circumstances, e.g. when you get an answer like 127.0.0.53

This solution is no more up to date. I find the systemd-resolve —status suggested by @G32RW most up-to-date solution for this problem.

( nmcli dev list || nmcli dev show ) 2>/dev/null | grep DNS 

On Debian, you need to have the network-manager package installed.

This one is usefull if you are using VPN and NetworkManager. Your /etc/resolv.conf will point to your machine, with dnsmasq resolving names as configured by NetworkManager.

nm-tool is not available in newer linuxes. for example it is not in the ‘network-manager’ package of debian 8.

This did not work for me on an Ubuntu VM. nmcli dev show did not have the DNS info. However, systemd-resolve —status did have the real DNS server. unix.stackexchange.com/a/434756

On systems running systemd use:

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. The output you’re interested in will look something like this:

;; Query time: 91 msec ;; SERVER: 172.xxx.xxx.xxx#53(172.xxx.xxx.xxx) ;; WHEN: Tue Apr 02 09:03:41 EDT 2019 ;; MSG SIZE rcvd: 207 

You can also tell dig to query a specific DNS server by using dig @server_ip

Читайте также:  Все команды mysql linux

If you use any DNS masking/caching service that is run on your local machine, it will hide the real DNS servers.

This only tells you which server was used for that query. It doesn’t tell you all the DNS servers that your host might use.

Beware that this obviously fails if the DNS server is not available. That’s not a common thing, but I’ve managed to get a bad result or timeout when looking for a DNS server running on IPv6 (using dig -6 ).

Just do an, nslookup . Part of its results include the server that it’s using.

In the example below, it shows that the DNS server used is at 8.8.8.8.

$ nslookup google.com Server: 8.8.8.8 Address: 8.8.8.8#53 Non-authoritative answer: Name: google.com Address: 172.217.22.174 

On a recent Ubuntu, this again points to the local cache server 127.0.0.1 as already hinted at in this comment

In CentOS 7 it quits with error, but it is a vm so I did nslookup google.com in the Windows host and I found the nameserver. Add it in /etc/resolv.conf like: nameserver xx.xx.xx.xx and restart service network , and all is fine. Praise you.

With the new network-manager command nmcli , do this:

nmcli --fields ipv4.dns,ipv6.dns con show [connection_name] 

On newer versions of network-manager (such as in Ubuntu 16.04), the field names are slightly different:

nmcli --fields ip4.dns,ip6.dns con show [connection_name] 

If you don’t know the connection name, use:

nmcli -t --fields NAME con show --active 

For example, on old versions of nmcli :

$ nmcli --fields ip4.dns,ip6.dns con show 'Wired connection 1' IP4.DNS[1]: 172.21.0.13 IP4.DNS[2]: 172.21.0.4 

Returns Error: invalid field ‘ip4.dns’; allowed fields: NAME,UUID,TYPE,TIMESTAMP,TIMESTAMP-REAL,AUTOCONNECT,AUTOCONNECT-PRIORITY,READONLY,DBUS-PATH,ACTIVE,DEVICE,STATE,ACTIVE-PATH.

to get the first DNS SERVER (IP only) :

cat /etc/resolv.conf|grep -im 1 '^nameserver' |cut -d ' ' -f2 
  • cat will output DNS config
  • grep filters only nameserver
  • -i grep ignore case
  • -m 1 grep stop after first match
  • cut take the ip part of the row (second column with ‘ ‘ as separator)

To put DNS ip in an environment variable, you could use as follow:

export THEDNSSERVER=$(cat /etc/resolv.conf|grep -im 1 '^nameserver' |cut -d ' ' -f2) 

To lighten the pipeline even more, capture groups with Perl regexp is very neat, and grep takes a file argument: grep -Pom 1 ‘^nameserver \K\S+’ /etc/resolv.conf . Just wrote up Capture groups with grep perl regular expression

Читайте также:  Kubuntu linux 64 битные дистрибутивы linux

There’s both IPv4 and IPv6 DNS servers. Also, secondary servers exist for a reason. Which one this command returns? Is it advised to take the first one, and just ignore the others?

Using resolvectl

$ resolvectl status | grep -1 'DNS Server' DNSSEC supported: no Current DNS Server: 1.1.1.1 DNS Servers: 1.1.1.1 1.0.0.1 

grep option: -C NUM , -NUM , —context=NUM Print NUM lines of output context.

For compatibility, systemd-resolve is a symbolic link to resolvectl on many distros as for Ubuntu 18.10:

$ type -a systemd-resolve systemd-resolve is /usr/bin/systemd-resolve $ ll /usr/bin/systemd-resolve lrwxrwxrwx 1 root root 10 nov. 15 21:42 /usr/bin/systemd-resolve -> resolvectl $ type -a resolvectl resolvectl is /usr/bin/resolvectl $ file /usr/bin/resolvectl /usr/bin/resolvectl: ELF 64-bit LSB shared object, x86-64, version 1 (SYSV), dynamically linked, interpreter /lib64/ld-linux-x86-64.so.2, for GNU/Linux 3.2.0, BuildID[sha1]=09e488e849e3b988dd2ac93b024bbba18bb71814, stripped 

Источник

How to Get domain nameservers from commandline in Ubuntu Linux

Nameservers are special servers running a DNS service to provide the ip address of a particular domain name. Different domains have different nameservers.

Usually the nameservers are hosted and managed by the hosting server provider. If you are hosting your website on Bluehost for instance, the nameservers would be those of bluehost. Whereas if you are hosting your website with hostgator, the nameservers shall be of hostgator.

Besides the ip address, nameservers also provide lots of dns related information like cname records, TXT records, SOA records, MX records etc.

To check the nameservers of any given domain name from the command line you can use commands like dig and host. Lets take a look at a few examples

1. dig command

The following command will check the NS (nameserver) records of binarytides.com

$ dig -t ns binarytides.com ; > DiG 9.11.5-P4-5.1ubuntu2.2-Ubuntu > -t ns binarytides.com ;; global options: +cmd ;; Got answer: ;; ->>HEADER
$ dig +short -t ns binarytides.com may.ns.cloudflare.com. dave.ns.cloudflare.com.

The "-t" option specifies the type of record to fetch. It can be ns , a , soa , cname etc. These are the different types of dns records related to a domain name.

2. host command

The host command is similar to the dig command. It can also fetch dns records of any given domain name. Here is a quick example:

$ host -t ns binarytides.com binarytides.com name server may.ns.cloudflare.com. binarytides.com name server dave.ns.cloudflare.com.

Conclusion

Checking nameservers is important when you are setting up a new website or domain and need to check if the nameservers are visible correctly on the internet. Without the correct nameservers, the domain name will not be able to resolve to the correct ip address.

This means that the browser shall not be able to open the website contents. It is also needed when you are moving your website from one hosting provider to another. Then you have to change the nameservers and this usually takes few hours to take effect on the internet.

A Tech Enthusiast, Blogger, Linux Fan and a Software Developer. Writes about Computer hardware, Linux and Open Source software and coding in Python, Php and Javascript. He can be reached at [email protected] .

Источник

How to find the domain name of a server?

I'm having trouble finding the domain name of my school's server, I read another question similar to this but their commands didn't work. I tried to use nslookup and then when I was prompted I entered server . I get the following output. I don't understand where the domain name is stored. I'm using a wired LAN connection from my university.

Default Server: 127.0.01 Address: 127.0.0.1#53 Default Server: ::1 Address: ::1#53 

please would you clarify [. ] and then when I was prompted I entered server , you do know the server ip right? thx

3 Answers 3

You should nslookup the IP. It will return. Example.

[nazu@healer ~]$ nslookup > bro-ns-01 Server: 10.100.1.2 Address: 10.100.1.2#53 Name: bro-ns-01.angelsofclockwork.net Address: 10.100.1.2 > 10.100.1.2 Server: 10.100.1.2 Address: 10.100.1.2#53 2.1.100.10.in-addr.arpa name = bro-ns-01.angelsofclockwork.net. > 

I'm assuming you're using dnsmasq or otherwise, because your server address is set to your localhost. If that's the case, it should still be transparent enough to pull the information.

You could also look at /etc/resolve.conf if you're on the same network. You're more than likely being given a reverse DNS entry that has the same domain suffix of static servers.

[nazu@healer ~]$ cat /etc/resolv.conf ; generated by /usr/sbin/dhclient-script search angelsofclockwork.net. nameserver 10.100.1.2 

Источник

Оцените статью
Adblock
detector