Checking Network Configuration (ip, ifconfig, ping)
1. Viewing Network Configuration
1.1 Using the ip Command (Modern Tool)
The ip
command is part of the iproute2
package, which is the default network management tool in modern Linux systems. It replaces older commands like ifconfig
.
Key Features of ip:
- Shows detailed interface information.
- Displays IP addresses, routes, and link status.
- Allows configuration of IP addresses and routes (covered in later lessons).
Examples:
1. View All Network Interfaces and Their Details:
ip addr show
2. Show Only Active Interfaces:
ip link show up
- Displays only interfaces that are enabled and active.
3. Display Routing Table:
ip route show
1.2 Using the ifconfig Command (Deprecated but Still Used)
The ifconfig
command is deprecated but may still be available on older systems. It’s simple to use and often preferred by beginners.
Examples:
1. Display Network Interfaces and IP Information:
ifconfig
- Lists IP addresses, MAC addresses, and status of all network interfaces.
2. Check a Specific Interface (e.g., eth0)
ifconfig eth0
- Displays details only for the specified interface.
Note: For modern systems, the
ip
command should be used instead of ifconfig as it’s more robust and feature-rich.
2. Testing Network Connectivity
2.1 Using the ping Command
The ping
command checks connectivity between your system and another host by sending ICMP Echo Requests.
Examples:
1. Test Connectivity to an IP Address:
ping 8.8.8.8
- Tests if Google’s DNS server (8.8.8.8) is reachable.
2. Test Connectivity to a Domain Name:
ping google.com
- Verifies DNS resolution by checking if the domain resolves to an IP address and is reachable.
3. Limit the Number of Packets Sent (e.g., 4 packets):
ping -c 4 google.com
- Sends only 4 packets and stops, instead of pinging indefinitely.
4. Adjust Packet Size and Interval:
ping -s 128 -i 0.5 google.com
- Sends packets of 128 bytes every 0.5 seconds.
3. Checking DNS Resolution
Sometimes, network connectivity may fail due to DNS issues rather than physical connectivity problems.
Examples:
1. Test DNS Resolution with ping:
ping example.com
- Confirms whether the hostname resolves to an IP address.
2. Using the host Command (Optional):
host example.com
- Displays detailed DNS information, including IP addresses.
4. Troubleshooting Tips
1. Interface Down Issue:
ip link set eth0 up
- Brings the interface up if it’s down.
2. No IP Address Assigned:
dhclient eth0
- Requests an IP address from the DHCP server.
3. Gateway Issues:
ip route add default via 192.168.1.1 dev eth0
- Manually sets the default gateway.
4. DNS Issues:
Edit /etc/resolv.conf:
nameserver 8.8.8.8
- Adds Google’s public DNS server as a resolver.
5. Quick Recap: Key Commands
Command | Purpose |
---|---|
ip addr show | Display IP address and interface details. |
ip link show up | Show only active network interfaces. |
ip route show | Display routing table. |
ifconfig | Legacy command for viewing interface information. |
ping <ip> | Test network connectivity with an IP address. |
ping <hostname> | Test DNS resolution and connectivity with a hostname. |
ping -c 4 <ip> | Send 4 packets to test connectivity. |
ping -s 128 -i 0.5 <ip> | Customize packet size and interval for ping. |
host <domain> | Check DNS information for a hostname. |
Key Takeaways
- Use
ip
for modern systems as it is feature-rich and actively maintained. - Use
ping
to verify connectivity and isolate network issues quickly. - Transition from
ifconfig
toip
where possible, asifconfig
is deprecated.