• DNS

    How to Flush Your Linux DNS Cache in Seconds

    DNS (Domain Name System) is like the phonebook of the internet, translating human-friendly domain names into IP addresses. To make browsing faster, your Linux system stores DNS lookups locally in a DNS cache. But sometimes, that cache causes issues—like loading outdated websites, running into connection errors, or struggling with DNS changes.

    The quick fix? Flushing your DNS cache.

    In this guide, we’ll explain what the DNS cache is, why you might need to clear it, and how to flush it instantly on different Linux distributions.

    What Is the DNS Cache in Linux?

    The DNS cache is a temporary database your computer keeps to remember recent domain lookups. For example, when you visit example.com, the IP address is stored locally.

    Benefits of the cache:

    • Faster browsing (no need to resolve domains repeatedly).
    • Reduced DNS traffic.

    Problems arise when cached records become stale or corrupted, causing:

    • Websites failing to load.
    • Old IP addresses being used after a DNS update.
    • Security issues from DNS spoofing.

    Why Flush the DNS Cache?

    You may need to flush your DNS cache when:

    • A website recently changed its DNS records.
    • You encounter repeated “server not found” or connection errors.
    • You suspect DNS spoofing or security issues.
    • You’re testing DNS changes as a developer or sysadmin.

    How to Flush DNS Cache in Linux

    Different Linux systems use different DNS caching services. Here are the most common methods:

    1. systemd-resolved (Ubuntu 18.04+, Debian, Fedora, etc.)

    If your system uses systemd-resolved:

    sudo systemd-resolve --flush-caches
    

    Check the cache size:

    systemd-resolve --statistics
    

    2. nscd (Name Service Cache Daemon)

    Some older distributions use nscd:

    sudo /etc/init.d/nscd restart
    

    Or:

    sudo service nscd restart
    

    3. dnsmasq

    If your system uses dnsmasq:

    sudo /etc/init.d/dnsmasq restart
    

    Or:

    sudo systemctl restart dnsmasq
    

    4. BIND (named)

    For servers running BIND:

    sudo rndc flush
    

    Flush a specific zone:

    sudo rndc flushname example.com
    

    Quick One-Liners by System

    • Ubuntu/Debian (systemd): sudo systemd-resolve --flush-caches
    • CentOS/RHEL (nscd): sudo service nscd restart
    • Fedora (dnsmasq): sudo systemctl restart dnsmasq
    • BIND servers: sudo rndc flush

    Verifying DNS Cache Flush

    After flushing, test with:

    dig example.com
    

    or

    nslookup example.com
    

    If you see updated IPs or reduced response times, your cache was successfully cleared.

    Keeping Your DNS Healthy

    Regularly maintaining your DNS setup helps avoid many common connection issues. Along with the occasional cache flush, it’s a good idea to keep your system updated, monitor DNS performance, and double-check settings after making changes. These small habits ensure your browsing stays fast, reliable, and secure.

    Conclusion

    Flushing your Linux DNS cache is quick, easy, and can save you from hours of frustration. Whether you’re a developer testing DNS changes or a user troubleshooting connection issues, knowing these commands keeps your system clean and responsive.

    So next time a website doesn’t load correctly, remember: sometimes all it takes is a simple DNS cache flush to get things back on track.

  • Commands

    Quick Guide to Using the Host Command

    When you’re working with networks, troubleshooting websites, or learning about DNS, one of the simplest yet most useful tools at your disposal is the host command.

    It’s often overlooked compared to tools like dig or nslookup, but host is lightweight, easy to use, and gives you the answers you need without overwhelming you with technical details.

    In this guide, we’ll explain what the host command does, break down its options, and walk through real-world examples — step by step.

    What is the Host Command?

    Every time you visit a website like www.google.com, your computer needs to know the IP address of that site. Humans remember names like example.com, but computers use numbers (IP addresses). The Domain Name System (DNS) acts like a phonebook, translating names into numbers.

    The host command is a tool that lets you query DNS directly. With it, you can:

    • Find the IP address of a domain (forward lookup).
    • Find the domain name associated with an IP (reverse lookup).
    • Check for special DNS records like mail servers (MX), verification records (TXT), or nameservers (NS).
    • Use different DNS servers to test how records are seen across the internet.

    It’s simple but extremely powerful for debugging network issues, verifying domain settings, or just learning how DNS works.

    Limitations of the Host command

    Installing the Host Command

    On many Unix-like systems, host is already installed. If it isn’t:

    • Ubuntu/Debian: sudo apt-get update sudo apt-get install dnsutils
    • CentOS/Fedora/RHEL: sudo yum install bind-utils
    • macOS:
      The host command is included by default.

    Once installed, you can run:

    host -v
    

    to confirm it’s available.

    Basic Syntax

    The general structure of the command is:

    host [options] name [server]
    
    • name → the domain name (e.g., example.com) or IP address you’re looking up.
    • server → (optional) a DNS server to query, such as 8.8.8.8 (Google DNS) or 1.1.1.1 (Cloudflare).
    • options → flags to specify record type or output style.

    Practical Examples

    Let’s walk through the most common use cases.

    1. Finding the IP Address of a Domain

    If you want to know where a domain points, just type:

    host example.com
    

    Example output:

    example.com has address 93.184.216.34
    example.com has IPv6 address 2606:2800:220:1:248:1893:25c8:1946
    

    This tells you both the IPv4 and IPv6 addresses of example.com.

    2. Reverse Lookup (IP to Domain)

    If you already have an IP address but want to know what domain it belongs to:

    host 93.184.216.34
    

    Output:

    34.216.184.93.in-addr.arpa domain name pointer example.com.
    

    This process is called a reverse DNS lookup. It’s often used in email systems to verify sending servers.

    3. Checking MX Records (Mail Servers)

    MX records show which servers handle email for a domain.

    host -t MX gmail.com
    

    Output:

    gmail.com mail is handled by 10 alt1.gmail-smtp-in.l.google.com.
    gmail.com mail is handled by 20 alt2.gmail-smtp-in.l.google.com.
    

    This means that if you send an email to @gmail.com, it will be delivered to Google’s SMTP servers.

    4. Checking TXT Records (Verification and Security)

    TXT records often contain important information such as:

    • SPF: Sender Policy Framework (email anti-spam).
    • DKIM: Email signing keys.
    • Verification tokens for services like Google or Microsoft.

    Example:

    host -t TXT example.com
    

    Output:

    example.com descriptive text "v=spf1 include:_spf.example.net ~all"
    

    This SPF record shows which servers are allowed to send mail for example.com.

    5. Finding Nameservers

    Nameservers control which DNS servers are authoritative for a domain.

    host -t NS example.com
    

    Output:

    example.com name server ns1.exampledns.com.
    example.com name server ns2.exampledns.com.
    

    This tells you which servers provide the official DNS records for example.com.

    6. Forcing a Query to a Specific DNS Server

    By default, host uses your system’s DNS resolver (often your ISP’s or local network DNS). But sometimes you want to check what another provider sees — useful when DNS hasn’t fully propagated.

    host example.com 8.8.8.8
    

    This forces the query to use Google DNS.

    7. Querying IPv6 Records

    To explicitly request an IPv6 (AAAA) record:

    host -t AAAA example.com
    

    Output:

    example.com has IPv6 address 2606:2800:220:1:248:1893:25c8:1946
    

    Tips and Troubleshooting

    • Use verbose mode with -v if you want more details about the DNS lookup process. host -v example.com
    • Check multiple record types if troubleshooting a website or email issue. For example, always check A, AAAA, MX, and TXT records when setting up a mail server.
    • Compare multiple DNS servers if you think propagation is delayed. For example: host example.com 1.1.1.1 host example.com 8.8.8.8
    • NXDOMAIN error means the record does not exist. If you’re expecting it to exist, check your domain’s DNS configuration.

    Host vs. Dig vs. Nslookup

    You might wonder why we use host when dig and nslookup exist.

    • host → Quick, clean, human-readable results. Great for everyday lookups.
    • dig → Very detailed output, useful for advanced troubleshooting.
    • nslookup → Older tool, still works, but mostly replaced by dig and host.

    If you want speed and simplicity, host is the tool for you.

    Final Thoughts

    The host command is a lightweight, no-nonsense tool for DNS lookups. Whether you’re checking if a website is pointing to the right IP, verifying mail records, or troubleshooting DNS propagation, it gets the job done quickly.

    Here’s what you can do right now:

    1. Run host example.com on your terminal.
    2. Try looking up MX, TXT, and NS records for domains you own.
    3. Compare results from your system DNS vs Google’s 8.8.8.8.

    Once you start using host, you’ll find it becomes one of your go-to tools for DNS diagnostics.