/etc/resolv.conf file. By verifying your network interface status and ensuring proper DNS server assignments, you can restore full connectivity for package updates and web browsing.
Understanding the Error Context
This specific error message is generated by the GNU C Library (glibc) when it attempts to resolve a hostname but receives no valid response from the configured name servers. In a standard Linux environment, this means the packet destined for your DNS provider either never left your machine, was dropped by a firewall, or returned an error code indicating the server is unreachable. Unlike a "Connection refused" error which points to a specific port blockage, a temporary failure suggests a broader breakdown in the resolution pipeline.
Kali Linux is frequently used in penetration testing scenarios where network configurations change rapidly. Users often switch between wired Ethernet, Wi-Fi, and virtual adapters for monitoring modes. These rapid transitions can leave the local resolver in an inconsistent state, particularly if the DHCP client fails to update the resolv configuration correctly after a disconnect.
Verifying Network Interface Status
The first step in troubleshooting is to confirm that your network interface is actually up and has obtained an IP address. If the interface is down, no amount of DNS tweaking will help. Open a terminal and run the following command to list all active interfaces:
ip addr show
Look for your primary interface (commonly eth0 for wired or wlan0 for wireless). Ensure it shows a state of UP and contains an IPv4 address that is not a 169.254.x.x link-local address. If you see a link-local address, your device failed to acquire a proper lease from the DHCP server. In this case, you should restart the networking service or reconnect to the Wi-Fi network. For detailed diagnostics on general connectivity issues that might precede this DNS error, refer to our guide on Troubleshooting: Cannot Connect to the Internet.
Checking /etc/resolv.conf Configuration
The file /etc/resolv.conf is the primary configuration file for DNS on most Linux distributions. Historically, users edited this file directly to set permanent DNS servers like Google's 8.8.8.8 or Cloudflare's 1.1.1.1. However, modern versions of Kali Linux use systemd-resolved or NetworkManager, which manage this file dynamically. If you manually edited it, you may have broken the symlink or overwritten critical dynamic entries.
To check the current content, run:
cat /etc/resolv.conf
If the file appears empty or contains only comments, your resolver is likely broken. You should not edit this file manually unless you are running a minimal system without a network manager. Instead, let NetworkManager handle it. If you suspect corruption, you can reset the file permissions or remove it entirely to force the system to regenerate it upon the next network restart. Note that if you are using a custom DNS setup, ensure your queries are being sent correctly by checking Troubleshooting DNS Servers Not Getting Client-Initiated Queries.
Restarting Network Services
Often, the issue is simply a stale state in the NetworkManager daemon. Restarting these services forces the system to re-read configuration files and request new DHCP leases. Execute the following commands in sequence:
sudo systemctl restart NetworkManager
sudo systemctl restart systemd-resolved
After restarting, test your connection using nslookup google.com. If this returns an IP address, the problem is resolved. If it still fails, check if the systemd-resolved service is enabled at boot. Sometimes, updates to Kali Linux can disable certain services if they are deemed unnecessary for headless installations. Use systemctl status systemd-resolved to verify its active state.
Testing with Systemd-Resolved Status
Systemd-resolved provides a powerful diagnostic tool called resolvectl. This command gives you a clear view of which DNS servers are currently being used for each interface. Run the following command to see the status:
resolvectl status
Look for your active interface under the "DNS Servers" section. If it lists -- No servers --, then DHCP has failed to provide DNS information. You can manually set DNS servers for a specific interface using NetworkManager's GUI or via the command line using nmtui. This method is safer than editing config files directly as it integrates with the system's unified network management framework. For more insights on host name lookup mechanics, see Troubleshooting Host Name Lookup and DNS Resolution on Tech Support Sites.
Clearing Cache and Resetting DNS
In rare cases, the local DNS cache may become corrupted, causing resolution failures even when the network is healthy. While systemd-resolved handles caching automatically, you can flush it to force a fresh lookup. Use the following command to clear the cache:
sudo resolvectl flush-caches
Additionally, if you have previously added static entries to /etc/hosts that conflict with external domains, remove them. A malformed entry in /etc/hosts can sometimes cause the resolver to hang or fail prematurely. After making changes, always test with ping -c 4 8.8.8.8 to ensure basic IP connectivity exists before blaming DNS again.
Frequently Asked Questions
Why does nslookup work but ping to a domain fails?
This usually indicates that DNS resolution is functioning, but there is a routing or firewall issue preventing traffic from reaching the destination IP. Verify that your default gateway is correct using ip route and ensure no local iptables rules are blocking outbound traffic on port 80 or 443.
Can I manually edit /etc/resolv.conf to fix this permanently?
It is not recommended because NetworkManager or systemd-resolved will overwrite your changes during the next network cycle. Instead, configure your DNS settings through the NetworkManager GUI or by editing the connection profile in /etc/NetworkManager/system-connections/ to ensure persistence.
What causes the 169.254.x.x IP address in Kali Linux?
This is a link-local address assigned by the operating system when DHCP fails to respond. It means your computer cannot communicate with the router's DHCP server. Check your physical cable connections, Wi-Fi authentication credentials, or router DHCP pool limits to resolve this underlying connectivity issue.
How do I check if systemd-resolved is blocking my queries?
Use resolvectl query example.com to see exactly which server responds and how long it takes. If the query hangs or times out, the specified DNS server is unreachable. Switch to public DNS servers like 8.8.8.8 in your NetworkManager settings to bypass potentially problematic local ISP resolvers.
Does disabling IPv6 help with name resolution errors?
Sometimes, systems prefer IPv6 DNS servers that are misconfigured or unavailable, causing timeouts before falling back to IPv4. Disabling IPv6 in your NetworkManager connection properties can force the system to use IPv4 exclusively, which may resolve intermittent resolution delays on networks with poor IPv6 support.