Problem Statement
Describe a systematic approach to troubleshooting network connectivity issues. Include commands and diagnostic steps.
Explanation
Start with basic connectivity: ping 127.0.0.1 tests loopback interface ensuring TCP/IP stack works. Ping default gateway (ip route | grep default shows gateway) tests local network connectivity. Ping external IP like 8.8.8.8 (Google DNS) tests internet connectivity without DNS. If this works but domain names don't, the issue is DNS.
Check interface configuration: ip addr shows IP addresses and interface status (UP/DOWN), ip link shows physical layer status. Verify correct IP address, subnet mask, and interface is UP. Check route table with ip route or route -n ensuring default gateway exists. Incorrect IP configuration or missing gateway prevents communication beyond local network.
DNS troubleshooting: cat /etc/resolv.conf shows configured DNS servers. Test DNS with nslookup domain or dig domain. If resolution fails, try different DNS server: nslookup domain 8.8.8.8. Check /etc/hosts for local hostname overrides. NetworkManager or systemd-resolved might manage DNS configuration - check their status.
Port and service testing: telnet host port or nc -zv host port tests specific port connectivity. Check if service is listening with netstat -tuln or ss -tuln. Verify firewall rules with iptables -L -n or firewall-cmd --list-all. Check if remote firewall blocks connection. Use tcpdump or wireshark for packet capture: tcpdump -i eth0 port 80 captures HTTP traffic for detailed analysis.
Common issues and solutions: no IP address (DHCP problem - check dhclient or NetworkManager), wrong subnet (verify netmask), no default gateway (check routing), DNS failure (check resolv.conf and DNS server), firewall blocking (check iptables/firewalld), cable unplugged (check ip link for interface state), service not listening (check netstat and service status). Document findings and solutions for future reference.