GICT knowledge base
dig and nslookup Commands: Simple DNS Tools for Linux Users
Published
Working with DNS can be hard. When websites don’t open or email stops working, you need good tools to find out what’s wrong. That’s where dig and nslookup help you. These commands help system admins and developers fix network problems every day. Learning how to use them right can save hours of trying to find bugs.
What DNS Tools Do
DNS changes domain names into IP addresses. It’s like looking up someone’s phone number – but we’re dealing with websites and servers instead of names and numbers. When you type google.com in your browser, DNS finds the right IP address so your computer can connect to Google’s servers. If DNS breaks, websites won’t work.
dig (Domain Information Groper) is a strong tool that gives you lots of details fast. The output might look scary at first, but all those details help once you learn them. nslookup has been around for many years. It’s easier than dig and works well when you need simple answers. Many admins like it because the results are clean and easy to read.
Both tools ask DNS servers questions about websites and show you what they find. You can use either one, but they work a bit differently.
Installing These Tools
You need to install these before you can use them. Here’s how to do it on different systems:
- Ubuntu and Debian systems:
sudo apt update sudo apt install dnsutils - CentOS and RHEL (older versions):
sudo yum install bind-utils - Newer CentOS and Fedora:
sudo dnf install bind-utils - Arch Linux:
sudo pacman -S bind-tools
Installing works fine on most Linux systems. Both dig and nslookup come together in these packages, so you get both tools at once.
How to Use dig
Simple Queries
Start with something easy:
dig google.com
You’ll see lots of info come back. Don’t worry about understanding everything right away. The important part is the IP address in the ANSWER section.
The output shows you things like:
- How long the query took
- Which DNS server answered
- The IP address you asked for
- Other technical details
Getting Short Results
Sometimes you only want the IP address:
dig +short google.com
This gives you just what you need without extra stuff. It’s great for scripts or when you want a quick answer.
Different Types of Records
DNS has many types of records. Here are the ones you’ll use most:
- Mail servers (MX records):
dig google.com MX - Name servers (NS records):
dig google.com NS - IPv6 addresses (AAAA records):
dig google.com AAAA - Text records (TXT records):
dig google.com TXT
Using Different DNS Servers
Your internet provider’s DNS might be slow or broken. Testing with public DNS servers often helps:
dig @8.8.8.8 google.com
dig @1.1.1.1 google.com
Google’s DNS (8.8.8.8) and Cloudflare’s (1.1.1.1) usually work fast and give good results. You can also try other public DNS servers:
dig @208.67.222.222 google.com
Advanced dig Options
Want to see how DNS works step by step?
dig +trace google.com
This shows the whole path from root servers down to your target domain. It’s like watching DNS do its job in slow motion.
For reverse lookups (finding domain from IP):
dig -x 8.8.8.8
This tells you which domain owns that IP address. You can also ask for multiple record types at once:
dig google.com ANY
This tries to get all available records for that domain.
How to Use nslookup
Simple Lookups
Basic use is easy:
nslookup google.com
You get the IP address and some basic server info. The output is cleaner than dig but has less detail.
Using Specific DNS Servers
nslookup google.com 8.8.8.8
This asks Google’s DNS server instead of your default one.
Interactive Mode
This is where nslookup really shines. Type nslookup and press enter:
nslookup
> google.com
> set type=MX
> google.com
> server 8.8.8.8
> google.com
> exit
Interactive mode lets you run many queries without typing the command over and over. You can:
- Change record types with
set type=MX - Switch DNS servers with
server 8.8.8.8 - Query different domains
- Exit when you’re done
Different Record Types in nslookup
In interactive mode, you can check different types:
set type=MXfor mail serversset type=NSfor name serversset type=TXTfor text recordsset type=Afor regular IP addresses
Reverse Lookups
Just type the IP address:
nslookup 8.8.8.8
This finds the domain name that goes with that IP.
Picking the Right Tool
dig gets used more by experienced people. It’s faster, gives more info, and works better in scripts. The output format stays the same, making it easier for programs to read.
nslookup works great for quick checks. When you need to check something fast or help someone new to DNS tools, nslookup often works better.
Here’s when to use each:
- Use
digwhen:- You need lots of technical details
- You’re writing scripts
- You want fast results
- You’re doing serious troubleshooting
- Use
nslookupwhen:- You want simple, easy-to-read results
- You’re new to DNS tools
- You need quick IP lookups
- You like clean output
Fixing Common Problems
Command not found errors mean the tools aren’t installed. Go back and install the right package for your system.
Timeouts usually mean DNS server problems. Try a different server like 8.8.8.8 or 1.1.1.1.
Different results from different servers can mean DNS changes are still spreading. Changes take time to reach all servers around the world.
No answer might mean the domain doesn’t exist or the DNS server won’t talk to you.
Slow queries could mean your DNS server is overloaded. Try public DNS servers for better speed.
Real-World Uses
Here are some ways these tools help in real situations:
- Website migration – checking if DNS changes worked:
dig +short mywebsite.com - Email problems – checking mail server settings:
dig mycompany.com MX - Speed testing – comparing different DNS servers:
dig @8.8.8.8 example.com dig @1.1.1.1 example.com - Domain verification – making sure DNS points to the right place:
nslookup mysite.com - Troubleshooting – finding why a website won’t load:
dig +trace problem-site.com
Helpful Tips
- Start with
nslookupif DNS tools are new to you. The output looks friendlier and less scary. - Learn
digonce you understand basic DNS ideas. It becomes your main tool for serious problem-solving. - Always test from multiple DNS servers when fixing problems. Different servers might give different answers while DNS changes spread.
- Use the
+shortoption withdigwhen you need quick answers without extra information. - Keep a list of good public DNS servers:
8.8.8.8,1.1.1.1,208.67.222.222work well for testing. - Practice with websites you know work correctly. Try different record types and DNS servers.
- Learn what the output means. Understanding DNS records helps you spot problems faster.
Understanding DNS Records
Different record types do different jobs:
Arecords point domains to IPv4 addressesAAAArecords point domains to IPv6 addressesMXrecords tell where to send emailNSrecords show which DNS servers control the domainTXTrecords hold extra information like verification codesCNAMErecords make one domain point to another domain
Summary
These tools are basic for anyone dealing with web servers, email systems, or network management. They get used regularly across the industry for fixing problems and checking things.
Start practicing with websites that work right. Try different record types and DNS servers. More practice leads to better understanding of reading and figuring out the results.
DNS problems can be annoying, but having the right tools makes all the difference. dig and nslookup help find problems quickly and get systems working again faster.
Remember that DNS is the foundation of how the internet works. Without it, nothing would connect properly. These tools help you see what’s happening behind the scenes and fix things when they break.
Whether you’re a system admin, web developer, or just curious about how the internet works, these commands will serve you well. Take time to learn them properly, and they’ll save you lots of trouble later.Learn how to use dig and nslookup commands in Linux for DNS troubleshooting. Complete guide with installation steps, examples, and tips for fixing network issues.
Related guides
How to Restrict an SSH Key to One Command
Restrict an SSH key to one command with authorized_keys options. Protect the command and check that unwanted shell and forwarding access are denied.
Linux and CommandsSelf-Hosted Video Processing With FFmpeg: A Practical Guide
Learn how to self-host video processing on a VPS using FFmpeg, with practical commands for conversion, compression, thumbnails, and automated workflows.
Linux and CommandsHow to use nohup: Commands in Linux That Survive Terminal Closes
Keep commands running after you close the terminal. nohup examples with wget, Python, rsync, and Docker on any VPS.
Linux and CommandsHow to Fix “Too Many Open Files” Error on Linux Servers
Learn how to fix the "Too Many Open Files" error on Linux servers by understanding file descriptors, adjusting limits, and diagnosing leaks effectively.
