Network Tools in Linux
Network tools in Linux are essential for diagnosing, managing, and troubleshooting network issues. They help in monitoring network performance, testing connectivity, checking for problems, and configuring network interfaces. Here's a comprehensive guide to some of the most common and useful network tools available in Linux.
________________________________________
1. Ping
Purpose: Check connectivity between the local system and a remote system (host).
Usage:
ping <hostname or IP>
Example:
ping google.com
Options:
• -c <count>: Send a specific number of ping requests.
• ping -c 5 google.com
________________________________________
2. Traceroute
Purpose: Trace the route packets take from your computer to a destination. It shows the path and delays for each hop along the way.
Usage:
traceroute <hostname or IP>
Example:
traceroute google.com
Install:
sudo apt install traceroute # On Ubuntu
sudo yum install traceroute # On CentOS
________________________________________
3. Netstat
Purpose: Display network connections, routing tables, interface statistics, and more.
Usage:
netstat
Common Options:
• -t: Show TCP connections.
• -u: Show UDP connections.
• -a: Show all connections.
• -l: Show listening ports.
• -p: Show PID and program name.
Example:
netstat -tuln
This will show all listening TCP and UDP ports along with the corresponding IP addresses.
________________________________________
4. ifconfig (deprecated, replaced by ip command)
Purpose: Displays or configures network interfaces.
Usage:
ifconfig
Example:
ifconfig eth0
To bring an interface up or down:
sudo ifconfig eth0 up # Bring interface up
sudo ifconfig eth0 down # Bring interface down
Note: ifconfig is deprecated in newer Linux distributions, and it's recommended to use ip command.
________________________________________
5. ip Command
Purpose: The ip command is used for network interface configuration, managing routing, and monitoring network devices.
Usage:
• To display IP address information:
• ip a
• To configure a network interface (e.g., eth0):
• sudo ip addr add 192.168.1.100/24 dev eth0
• To delete an IP address:
• sudo ip addr del 192.168.1.100/24 dev eth0
________________________________________
6. nslookup
Purpose: Query DNS (Domain Name System) to find domain names and their corresponding IP addresses.
Usage:
nslookup <hostname>
Example:
nslookup google.com
You can also specify a DNS server:
nslookup google.com 8.8.8.8
________________________________________
7. dig
Purpose: Another tool for querying DNS information, more advanced than nslookup.
Usage:
dig <hostname>
Example:
dig google.com
This will provide detailed DNS records, such as A, MX, and NS records.
________________________________________
8. iperf
Purpose: A tool for network performance testing, especially useful for measuring the bandwidth between two systems.
Usage:
1. Start the server (on one system):
2. iperf -s
3. Start the client (on another system):
4. iperf -c <server_ip>
Options:
• -u: Use UDP instead of TCP.
• -t <time>: Set test duration.
• -i <interval>: Show intermediate results every interval seconds.
________________________________________
9. netcat (nc)
Purpose: A versatile tool for reading and writing data across network connections using TCP/UDP. Often referred to as "the Swiss Army knife of networking."
Usage:
1. Listen on a specific port:
2. nc -l -p 12345
3. Connect to a remote host:
4. nc <hostname> <port>
Example:
nc google.com 80
________________________________________
10. curl
Purpose: A command-line tool used to transfer data from or to a server using various network protocols, including HTTP, FTP, and others.
Usage:
• Get a webpage:
• curl http://example.com
• Download a file:
• curl -O http://example.com/file.tar.gz
________________________________________
11. wget
Purpose: Another command-line tool for downloading files from the web.
Usage:
wget <URL>
Example:
wget https://example.com/file.zip
________________________________________
12. tcpdump
Purpose: A command-line packet analyzer tool that captures network traffic in real-time. It allows you to inspect packets sent over a network.
Usage:
sudo tcpdump -i eth0
Common Options:
• -w <file>: Write the output to a file.
• -n: Disable DNS resolution (shows IPs instead of hostnames).
• -c <count>: Capture a specific number of packets.
________________________________________
13. nmap
Purpose: A powerful tool for network discovery and security auditing. It’s often used to scan open ports on a remote system and find vulnerabilities.
Usage:
nmap <hostname or IP>
Example:
nmap 192.168.1.1
Advanced Options:
• -p <port>: Scan specific ports.
• -A: Enable OS detection, version detection, and traceroute.
• -sP: Ping scan to detect live hosts.
________________________________________
14. route
Purpose: Displays and manipulates the IP routing table.
Usage:
route
To add a route:
sudo route add -net <destination_network> netmask <netmask> gw <gateway>
________________________________________
15. ssh
Purpose: Secure Shell (SSH) allows secure remote login to another system.
Usage:
ssh <username>@<hostname>
Example:
ssh user@192.168.1.100
To copy files using SSH (via scp):
scp file.txt user@192.168.1.100:/home/user/
________________________________________
16. lsof
Purpose: List open files and network connections, useful for debugging network services.
Usage:
lsof -i
This shows all open network connections and the processes associated with them.
________________________________________
17. mtr
Purpose: A network diagnostic tool that combines the functionality of ping and traceroute, providing real-time network statistics.
Usage:
mtr <hostname>
Example:
mtr google.com
________________________________________