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<<- opcode: QUERY, status: NOERROR, id: 14408 ;; flags: qr rd ra; QUERY: 1, ANSWER: 2, AUTHORITY: 0, ADDITIONAL: 1 ;; OPT PSEUDOSECTION: ; EDNS: version: 0, flags:; udp: 65494 ;; QUESTION SECTION: ;binarytides.com. IN NS ;; ANSWER SECTION: binarytides.com. 6727 IN NS may.ns.cloudflare.com. binarytides.com. 6727 IN NS dave.ns.cloudflare.com. ;; Query time: 0 msec ;; SERVER: 127.0.0.53#53(127.0.0.53) ;; WHEN: Wed Jul 22 14:52:32 IST 2020 ;; MSG SIZE rcvd: 95
$ 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.
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.