🔍 Commands: dig and nslookup (DNS Lookup Tools)
Both dig (Domain Information Groper) and nslookup (Name Service Lookup) are used to query DNS (Domain Name System) servers to translate human-readable names (like google.com) into IP addresses.
1. dig vs. nslookup: The Key Differences
| Feature | nslookup |
dig |
|---|---|---|
| Philosophy | Simple, interactive, legacy tool. | Advanced, flexible, "The Pro Standard." |
| Output | Concise and clean. | Detailed (includes header, flags, and timing). |
| Scripting | Not ideal (behavior varies by OS). | Excellent (standardized output for parsing). |
| Modernity | Deprecated (though still widely used). | Actively maintained and more accurate. |
2. The dig Command (The Professional Choice)
dig is the primary tool used by network administrators. It provides the full response from the DNS server without any filtering.
A. Basic Lookup
dig google.com
Look at the "ANSWER SECTION" for the IP address.
B. Querying Specific Record Types
If you are setting up your "Ahmed Codes" domain and need to verify your mail or alias records:
- MX Records (Mail):
dig google.com MX - TXT Records (Verification):
dig google.com TXT - CNAME (Aliases):
dig google.com CNAME
C. Using a Specific DNS Server
If you want to bypass your Algerian ISP's DNS and test against Google's DNS directly:
dig @8.8.8.8 ahmedcodes.com
D. The Concise View (+short)
If you just want the IP address and nothing else (great for scripts):
dig google.com +short
3. The nslookup Command (The Quick Check)
nslookup is best for a quick, interactive check when you don't need technical details like TTL (Time to Live) or flags.
A. Basic Lookup
nslookup google.com
B. Interactive Mode
Just type nslookup and hit Enter. You can then change servers and query multiple domains in a row:
> server 1.1.1.1
> set type=mx
> google.com
4. Practical Examples for Your Workflow
A. Reverse DNS Lookup
If you see a strange IP in your Linux logs and want to know what domain it belongs to:
- dig:
dig -x 8.8.8.8 - nslookup:
nslookup 8.8.8.8
5. Pro-Tips
- The "Trace" Flag (
+trace): This is one ofdig's coolest features. It shows the entire path of a DNS query from the root servers down to the specific domain server.dig google.com +trace - Arch Linux Context: If
digisn't found on your system, it is part of thebindpackage. Install it with:sudo pacman -S bind. - Tutorial Tip: When writing your technical tutorials, use
dig +shortin your code examples—it makes the output much cleaner for readers to follow.
6. Summary Reference
| Goal | Command |
|---|---|
| Simple lookup | dig [domain] |
| Just the IP | dig [domain] +short |
| Trace DNS path | dig [domain] +trace |
| Reverse Lookup | dig -x [IP] |
| Query specific server | dig @[server] [domain] |