Chapter 10: Essential Networking Commands for Beginners
Introduction
While Ubuntu provides a user-friendly UI for managing networks, sometimes using basic networking commands can be faster and more efficient, especially for troubleshooting. These commands help check connectivity, analyze network traffic, and configure network settings.
In this chapter, we’ll cover essential networking commands, their usage, and how to filter output using grep to find relevant details quickly.
1️⃣ Ping – Checking Connectivity
The ping
command tests whether a device is reachable over the network by sending small data packets and measuring the response time.
Basic Usage
ping google.com
Sends packets to google.com and measures response time.
If successful, it confirms that your internet is working.
Using grep to Filter Results
ping -c 5 google.com | grep 'time='
-c 5
: Sends only 5 packets.grep 'time='
: Filters the output to show only response times.
Real-World Use Case
✅ Troubleshooting internet issues: If ping
google.com
fails but ping 192.168.0.1
(router) works, your internet connection may be down.
2️⃣ Traceroute – Finding the Path to a Destination
The traceroute
command shows the path that data takes to reach a destination.
Basic Usage
traceroute google.com
Displays all the routers (hops) that packets pass through to reach Google’s servers.
Helps identify slow or failing network nodes.
Using grep to Find a Specific Hop
traceroute google.com | grep '192.168'
- Filters only lines containing 192.168, which is common in local networks.
Real-World Use Case
✅ Diagnosing slow connections: If one hop has a high response time, it might be causing the delay.
3️⃣ Netstat – Viewing Network Connections
The netstat
command shows active network connections, listening ports, and routing tables.
Basic Usage
netstat -tuln
-t
: Shows TCP connections.-u
: Shows UDP connections.-l
: Shows listening ports.-n
: Displays numerical IPs instead of resolving hostnames.
Using grep to Find a Specific Port
netstat -tuln | grep ':22'
- Shows only port 22 (SSH) to check if the SSH service is running.
Real-World Use Case
✅ Checking if a server is listening: If you expect a service (e.g., a web server) to be running but don’t see it in netstat
, it may have crashed.
4️⃣ ipconfig/ifconfig – Viewing IP and Network Configuration
ipconfig
(Windows) and ifconfig
(Linux/macOS) show the current IP addresses and network interface details.
Basic Usage (Linux/macOS)
ifconfig
- Displays network interfaces, IP addresses, and MAC addresses.
Basic Usage (Windows)
ipconfig /all
- Shows detailed network information, including DHCP settings and DNS servers.
Using grep to Find Your IP Address
ifconfig | grep 'inet '
- Shows only lines containing
inet
, which includes IP addresses.
Real-World Use Case
✅ Finding your local IP: Use this to check your Wi-Fi or Ethernet IP when troubleshooting.
5️⃣ nslookup – Checking DNS Resolution
The nslookup
command checks which IP address a domain name resolves to.
Basic Usage
nslookup google.com
- Displays the IP address of Google’s servers.
Using grep to Show Only the IP Address
nslookup google.com | grep 'Address:'
- Filters only the IP address in the output.
Real-World Use Case
✅ Testing DNS settings: If nslookup
google.com
fails but ping 8.8.8.8
works, your DNS server may be misconfigured.
6️⃣ dig – Advanced DNS Lookup
The dig
command provides more detailed DNS information.
Basic Usage
dig google.com
- Shows DNS records, including A records, CNAMEs, and MX records.
Using grep to Show Only A Records
dig google.com | grep 'A'
- Filters output to show only A records (IPv4 addresses).
Real-World Use Case
✅ Debugging website access issues: If dig
returns an unexpected IP, the domain may be misconfigured.
7️⃣ arp – Viewing MAC Addresses on the Network
The arp
command shows MAC addresses of devices on the local network.
Basic Usage
arp -a
- Lists IP and MAC addresses of devices your computer has interacted with.
Using grep to Find a Specific Device
arp -a | grep '192.168.0.1'
- Shows the MAC address of your router.
Real-World Use Case
✅ Identifying connected devices: Useful for checking if a specific device is online in your network.
8️⃣ whois – Getting Information About a Domain
The whois
command fetches registration details for a domain.
Basic Usage
whois google.com
- Shows domain owner, registrar, and expiration date.
Using grep to Show Expiration Date
whois google.com | grep 'Expiration'
- Filters to show only the expiration date of the domain.
Real-World Use Case
✅ Checking domain ownership: Useful for website security investigations or buying expired domains.
Conclusion
These essential networking commands provide a powerful way to troubleshoot network issues, analyze connectivity, and monitor activity. Using grep
helps extract only relevant details from command outputs, making diagnostics faster and more efficient.
Key Takeaways:
✅ Ping checks connectivity. ✅ Traceroute tracks the path of network traffic. ✅ Netstat shows active connections. ✅ ifconfig/ipconfig displays network settings. ✅ nslookup/dig resolve domain names. ✅ arp lists connected devices. ✅ **whois