Debugging Connectivity Issues with resolvectl and ss: A Step-by-Step Guide to Identifying DNS and Routing Problems

Introduction to Debugging Connectivity Issues

I’ve seen this go wrong when dealing with connectivity issues on Linux systems: not knowing where to start. Two essential tools can save you a lot of time - resolvectl and ss. These tools help in identifying and troubleshooting DNS and routing problems. Let’s dive into a step-by-step guide on how to use them, focusing on practical examples and security considerations where relevant.

Understanding resolvectl

resolvectl is a command-line utility provided by systemd for querying and configuring the DNS resolver. It’s incredibly useful for controlling the DNS resolver, including setting DNS servers, querying the DNS cache, and configuring DNS over TLS (DoT) or DNS over HTTPS (DoH). To get started with resolvectl, you can use the following command to status the current DNS configuration:

resolvectl status

This command will display the current DNS servers, the DNS protocol in use (e.g., UDP, TCP, DoT, DoH), and other relevant settings. Don’t bother with trying to decipher all the output at once - focus on the parts that are relevant to your issue.

Using resolvectl for Troubleshooting

For troubleshooting purposes, resolvectl offers several useful features:

  • Querying the DNS Cache: You can query the DNS cache for a specific domain using:
    resolvectl query example.com
    
  • Flushing the DNS Cache: If you suspect the DNS cache is causing issues, you can flush it with:
    resolvectl flush-caches
    
  • Setting DNS Servers: Temporarily setting a different DNS server for testing can be done with:
    resolvectl dns <interface> <DNS_SERVER_IP>
    
    Replace <interface> with your network interface (e.g., eth0) and <DNS_SERVER_IP> with the IP address of the DNS server you wish to use. I usually start with a public DNS server like Google’s or Cloudflare’s to see if the issue persists.

Introduction to ss

ss is a command-line utility used to investigate sockets. It can display stats for PACKET sockets, TCP sockets, UDP sockets, DCCP sockets, RAW sockets, and Unix domain sockets. ss is particularly useful for diagnosing network connectivity issues by showing which ports are open, which processes are listening on those ports, and the current state of network connections. The real trick is to use ss in combination with other tools to get a complete picture of your network setup.

Using ss for Troubleshooting

For network troubleshooting, ss is invaluable:

  • Listing All Listening Sockets: To see all listening sockets, use:
    ss -l
    
  • Filtering by Protocol: You can filter sockets by protocol (e.g., TCP, UDP) with:
    ss -l -t  # For TCP
    ss -l -u  # For UDP
    
  • Showing Processes Using a Specific Port: If you’re trying to figure out which process is using a particular port, you can use:
    ss -p <port_number>
    
    Replace <port_number> with the port number you’re interested in. This is where people usually get burned - not realizing that a process is holding onto a port, preventing another service from starting.

Combining resolvectl and ss for Advanced Troubleshooting

When debugging connectivity issues, it’s often useful to combine the information from resolvectl and ss. For example, if you’re having trouble connecting to a specific website, you can use resolvectl to check the DNS resolution for that site and ss to see if there are any issues with the network connection. In practice, this means you’ll be switching between these tools to get a complete picture of what’s going on.

Security Considerations

When troubleshooting connectivity issues, keep security in mind. Ensure that any temporary changes you make (e.g., setting a different DNS server) do not introduce security risks. For instance, using a public DNS server without DoT or DoH could expose your DNS queries to eavesdropping. Always revert changes after troubleshooting and consider implementing secure DNS protocols for your system.

Practical Examples and Caveats

  • DNS over TLS (DoT) and DNS over HTTPS (DoH): When configuring DoT or DoH, ensure your system’s clock is accurate, as these protocols rely on correct time settings to function properly.
  • Firewall Rules: Remember that firewall rules can affect your ability to connect to certain services. Use tools like ufw or firewalld to manage your firewall settings. Don’t forget to check the firewall rules on the server side as well.
  • Network Manager Settings: If you’re using Network Manager, be aware that some settings might override manual configurations. Always check Network Manager’s settings when troubleshooting connectivity issues.

Additional Tools and Resources

For further troubleshooting and configuration, consider exploring the following resources:

Troubleshooting Notes

  • Always start with basic troubleshooting steps, such as checking the network cable, restarting the network service, or rebooting the system.
  • Use journalctl to inspect system logs for clues about connectivity issues.
  • Consider using network debugging tools like tcpdump or Wireshark for deeper analysis of network traffic.

See also