How to Get domain nameservers from commandline in Ubuntu Linux

By | July 22, 2020

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

$ dig -t ns

; <<>> DiG 9.11.5-P4-5.1ubuntu2.2-Ubuntu <<>> -t ns
;; global options: +cmd
;; Got answer:
;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 14408
;; flags: qr rd ra; QUERY: 1, ANSWER: 2, AUTHORITY: 0, ADDITIONAL: 1

; EDNS: version: 0, flags:; udp: 65494
;               IN      NS

;; ANSWER SECTION:        6727    IN      NS        6727    IN      NS

;; Query time: 0 msec
;; WHEN: Wed Jul 22 14:52:32 IST 2020
;; MSG SIZE  rcvd: 95

Shorter version

$ dig +short -t ns

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 name server name server


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.

About Silver Moon

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].

Leave a Reply

Your email address will not be published. Required fields are marked *