
When your Linux machine can’t connect to the internet or another network, you need a set of reliable tools and commands to diagnose and solve the problem. Thankfully, Linux comes with powerful command-line utilities that help you understand your network configuration and identify issues quickly.
Here’s a practical guide to checking and troubleshooting network connections in Linux.
1. Check IP Address and Network Interfaces
Use the ip
or ifconfig
command to view your IP addresses and active interfaces:
ip a
Or:
ifconfig
Make sure your network interface (like eth0
or wlan0
) has an IP address. If not, your machine isn’t connected to a network.
2. Check Default Gateway and Routing Table
Verify if a default route is set using:
ip route
Look for a line that begins with default
. It shows the gateway through which your traffic is routed. If there’s no default route, you may need to add one manually or restart your network service.
3. Test Network Connectivity
Start with a simple ping test:
ping 8.8.8.8
If this works, your network connection is active. To test DNS resolution, try:
ping google.com
If the IP ping works but domain name ping fails, your issue is likely DNS-related.
4. Check DNS Settings
Inspect your DNS configuration:
cat /etc/resolv.conf
This file should list nameservers. If it’s empty or incorrect, try setting a public DNS (like nameserver 8.8.8.8
) manually.
5. Use traceroute or mtr
To diagnose where packets are getting lost or delayed:
traceroute google.com
Or a more detailed tool:
mtr google.com
These show you the path your traffic takes and where it might be failing.
6. Check for Dropped Packets or Interface Errors
To see statistics on network interfaces:
ip -s link
This shows packet counts, errors, and drops. Useful for identifying physical or driver-related issues.
7. Restart Network Services
Sometimes restarting the network service fixes temporary glitches:
sudo systemctl restart NetworkManager
Or for older systems:
sudo service networking restart
8. Use nmcli
for Network Manager
If your system uses NetworkManager, nmcli
is a powerful command-line tool:
nmcli device status
To connect or disconnect a device:
nmcli device connect eth0
FAQs
Q1: How do I find my IP address in Linux?
Use ip a
or ifconfig
to list IP addresses and interfaces.
Q2: Why can I ping IPs but not domain names?
This usually indicates a DNS configuration issue. Check /etc/resolv.conf
.
Q3: What tool shows packet path or latency issues?
Use traceroute
or mtr
to analyze routing problems.
Q4: How do I restart my network in Linux?
Run sudo systemctl restart NetworkManager
or sudo service networking restart
.
Meta Description
Let me know if you’d like it adapted for a specific distro (like Ubuntu or CentOS), or turned into a downloadable PDF!
How to Check and Troubleshoot Network Connections in Linux (F.A.Q)
How do I find my IP address in Linux?
Use ip a
or ifconfig
to list IP addresses and interfaces.
Why can I ping IPs but not domain names?
This usually indicates a DNS configuration issue. Check /etc/resolv.conf
.
What tool shows packet path or latency issues?
Use traceroute
or mtr
to analyze routing problems.
How do I restart my network in Linux?
Run sudo systemctl restart NetworkManager
or sudo service networking restart
.