Hey there, future Networking Ninja! 🥷 Ready to level up your command line game? Today, we’re diving into some core tools that every Linux enthusiast should have in their toolbox. Whether you’re tracking down network issues, checking connections, digging deep into DNS data, capturing network packets, or testing web responses, these tools will make you the Sherlock Holmes of the command line.
1. net-tools
: The Networking Veteran 🌟
net-tools
is a package containing a set of classic networking commands. Although newer tools have emerged, net-tools
remains a go-to suite for many sysadmins. Let’s break down what’s inside:
Key Commands from net-tools
:
ifconfig
: Short for interface configuration,ifconfig
is a powerful command to display or configure network interfaces. Runningifconfig
shows you IP addresses, MAC addresses, and network status:
ifconfig
To bring up or down an interface:
sudo ifconfig eth0 up
sudo ifconfig eth0 down
route
: This command shows the routing table, which controls how data packets get from one machine to another. Want a quick look at your routing table?
route -n
To add or delete routes, you can use:
sudo route add default gw 192.168.1.1
sudo route del default gw 192.168.1.1
arp
: Displays the ARP (Address Resolution Protocol) table, which shows the mapping between IP addresses and MAC addresses in your network.
arp -a
⚠️ Heads Up: Many distributions are replacing these commands with ip
commands from iproute2
. But net-tools
is still available and reliable for those familiar with its syntax!
2. netstat -tulpn
: The Connection Whisperer 🔍
netstat
is the Swiss Army knife for network diagnostics. Let’s go beyond just -tulpn
and explore more options!
Breaking Down netstat -tulpn
:
-t
: Show TCP connections-u
: Show UDP connections-l
: List all listening ports-p
: Show the PID and program name (so you know exactly who’s hogging your port)-n
: Show numerical addresses instead of hostnames (quicker and more precise)
netstat -tulpn
This command will give you a breakdown of all active listening ports along with the processes using them.
Other Useful netstat
Examples:
- View the Routing Table:
netstat -nr
This displays the kernel routing table. The -r
flag shows the routes, and -n
makes sure you get numerical IP addresses instead of hostnames.
- Check Established Connections:
netstat -at
The -a
flag shows all connections, while -t
restricts it to TCP.
3. dig
: The DNS Detective 🔎
Want to go full-on detective mode and find out what’s happening with your DNS? Then dig
is your sidekick. It stands for Domain Information Groper, and it’s a powerful tool to get detailed information about DNS records.
Basic dig
Magic:
dig example.com
You’ll get a beautiful breakdown of all the juicy DNS details: the IP address, TTL, authoritative name servers, and more. It’s a great way to troubleshoot or just satisfy your curiosity.
Advanced dig
Tricks:
- Query TXT Records:
dig TXT example.com
This fetches TXT records for the domain, which often include verification information or additional data about the domain.
- Query MX Records (Mail Exchange):
dig MX example.com
This tells you where to send emails for that domain.
- Trace a DNS Path:
dig example.com +trace
This option will trace the DNS path from the root servers down to your domain.
- Get a Short, Clean Answer:
dig example.com +short
4. nc -v
: The Swiss Army Knife of Networking 🛠️
Meet nc
, aka Netcat, the Swiss Army knife of network utilities. With nc
, you can pretty much do it all: chat between computers, scan ports, transfer files, and more. The -v
option makes things more verbose, meaning it’ll give you more information about what’s happening.
Simple nc
Examples:
Check if a Port is Open:
Want to see if a web server is responding on port 80 (HTTP) or 443 (HTTPS)? Use:
nc -v www.example.com 80
Or:
nc -v www.example.com 443
Test SSH Connectivity:
nc -v example.com 22
Or:
nc -v 192.168.1.1 22
This checks if port 22 (default for SSH) is open on the target server. If it connects, you know SSH is up!
More nc
Tricks:
Port Scanning:
If you want to scan a range of ports to see what’s open:
nc -v -z 192.168.1.1 80-90
-z
: Scan mode (doesn’t send data, just checks if the port is open)80-90
: Scan ports 80 to 90 on the specified IP
5. tcpdump
: The Packet Sniffer Extraordinaire 🕵️
tcpdump
is like having a magnifying glass over your network traffic. It’s a packet sniffer, meaning it captures packets going in and out of your interfaces. This is a fantastic tool for deep troubleshooting and understanding what’s happening in your network.
Basic tcpdump
Examples:
Capture Traffic on Port 80 (HTTP):
tcpdump -i eth0 port 80
This will show all the packets going through port 80 on the eth0
interface.
Capture Traffic on Port 443 (HTTPS):
tcpdump -i eth0 port 443
Perfect for debugging secure web traffic!
More tcpdump
Tricks:
- Capture Traffic from a Specific IP:
tcpdump -i eth0 src host 192.168.1.10
This captures all packets coming from the IP 192.168.1.10
.
- Filter Packets by Port and IP:
tcpdump -i eth0 host 192.168.1.10 and port 80
This captures HTTP traffic to or from the specified IP.
6. curl
: The Web Request Wizard 🌐
curl
is your go-to command for interacting with web servers directly from the terminal. It’s perfect for downloading files, making API requests, and testing web responses.
Basic curl
Example:
curl http://example.com
This sends a simple GET request to http://example.com
and prints the HTML response.
Advanced curl
Tricks:
- Resolve a Domain to a Specific IP: Want to test a domain name resolution with a specific IP address? Use:
curl --resolv example.com:443:127.0.0.1 https://example.com/
This command forces example.com
to resolve to 127.0.0.1
(locally) when accessing port 443 (HTTPS).
- Download a File:
curl -O https://example.com/file.zip
The -O
option saves the file with its original name.
- Send a POST Request with Data:
curl -X POST -d "name=Jeremie&[email protected]" https://example.com/submit
- Follow Redirects:
curl -L https://example.com
The -L
option tells curl
to follow any HTTP redirects.
- Get HTTP Headers:
curl -I https://example.com
This retrieves only the headers of the response.
Conclusion: From Zero to Network Hero 🌐
Armed with net-tools
, netstat
, dig
, nc
, tcpdump
, and curl
, you’re well on your way to becoming a command-line networking master. Whether you’re just starting out or you’re a seasoned pro looking for a refresher, these tools are a must-know for any serious Linux user.
So, fire up that terminal and start experimenting. The network’s your playground, and you’ve got the tools to explore it like a pro!
Happy networking! 🎉