Commands for checking, configuring, and diagnosing network connections.
Checks connectivity with a specified host.
Option | Description |
---|---|
-c N | Send only N pings and exit |
-i N | Send pings at N-second intervals |
-s N | Set packet size to N bytes |
-t N | Set TTL (Time To Live) value to N |
-w N | Set timeout to N seconds |
Examples:
ping google.com
- Continuously ping Google's serversping -c 5 192.168.1.1
- Send 5 pings to the specified IP addressping -i 2 -c 10 example.com
- Send 10 pings at 2-second intervalsping -c 5 google.com | grep "time="
- Display only response timesping -c 10 google.com | grep "time=" | awk '{print $7}' | cut -d "=" -f 2
- Extract only the response time valuesping -c 5 google.com | tail -1 | awk '{print $4}' | cut -d '/' -f 2
- Extract the average response timefor ip in 192.168.1.{1..10}; do ping -c 1 -W 1 $ip | grep "from" && echo "$ip is up"; done
- Ping multiple IP addressesping -c 5 -q google.com | grep "packet loss" | awk '{print $6}'
- Extract packet loss percentageping -c 1 -W 1 google.com > /dev/null 2>&1 && echo "Internet is up" || echo "Internet is down"
- Check internet connectivityping -c 5 -s 1500 google.com
- Check MTU with large packet sizeping -c 5 google.com | tee ping_results.txt
- Save results to a file while displaying them
Displays or configures network interface information.
Note: The ip
command is recommended in recent Linux distributions.
Syntax/Option | Description |
---|---|
ifconfig | Display information for all active interfaces |
ifconfig -a | Display information for all interfaces (including inactive ones) |
ifconfig [interface] | Display information for a specific interface |
ifconfig [interface] up/down | Enable/disable an interface |
ifconfig [interface] [ip] netmask [mask] | Set IP address and netmask |
Examples:
ifconfig
- Display information for all active network interfacesifconfig eth0
- Display information for the eth0 interfacesudo ifconfig eth0 192.168.1.100 netmask 255.255.255.0
- Set IP address and netmask for eth0ifconfig | grep -A 1 "inet "
- Display IPv4 addresses for all interfacesifconfig | grep -o -E 'inet ([0-9]{1,3}\.){3}[0-9]{1,3}' | cut -d' ' -f2
- Extract only IP addressesifconfig | grep "ether" | awk '{print $2}'
- Extract MAC addresses for all interfacesifconfig eth0 | grep "RX packets" | awk '{print "Received: " $3 " packets, " $5 " bytes"}'
- Format received packet and byte countsifconfig eth0 | grep "TX packets" | awk '{print "Transmitted: " $3 " packets, " $5 " bytes"}'
- Format transmitted packet and byte countsfor i in $(ifconfig | grep -o '^[a-zA-Z0-9]*:' | sed 's/://'); do echo "===$i==="; ifconfig $i | grep "inet "; done
- Format IP addresses for each interfaceifconfig | grep "mtu" | awk '{print $1, "MTU:", $NF}'
- Display MTU values for each interfaceifconfig eth0 | grep "errors" | awk '{print "RX errors: " $3 ", TX errors: " $7}'
- Display receive and transmit error counts
Configures and manages IP addresses, routing, network devices, etc.
Subcommand | Description |
---|---|
ip addr | Display/configure IP addresses |
ip link | Display/configure network interfaces |
ip route | Display/configure routing table |
ip neigh | Display/configure neighbor table (ARP table) |
ip tunnel | Display/configure tunnels |
Examples:
ip addr show
- Display IP address information for all interfacesip link set eth0 up
- Enable the eth0 interfaceip route show
- Display routing tablesudo ip addr add 192.168.1.100/24 dev eth0
- Add an IP address to eth0
Displays network connections, routing tables, interface statistics, etc.
Note: The ss
command is recommended in recent Linux distributions.
Option | Description |
---|---|
-a | Display all connections (including listening sockets) |
-t | Display TCP connections only |
-u | Display UDP connections only |
-n | Display numerical addresses and ports |
-p | Display process ID and program name |
-r | Display routing table |
-i | Display network interface statistics |
Examples:
netstat -tuln
- Display listening TCP and UDP ports numericallynetstat -anp
- Display all connections with associated processesnetstat -r
- Display routing table
Displays socket statistics. Used as a replacement for netstat.
Option | Description |
---|---|
-a | Display all sockets (including listening sockets) |
-t | Display TCP sockets only |
-u | Display UDP sockets only |
-n | Display numerical addresses and ports |
-p | Display process using the socket |
-l | Display listening sockets only |
-i | Display internal TCP information |
Examples:
ss -tuln
- Display listening TCP and UDP ports numericallyss -anp
- Display all sockets with associated processesss -i
- Display internal TCP information
Downloads files using HTTP, HTTPS, FTP, and other protocols.
Option | Description |
---|---|
-O [file] | Save downloaded file with specified name |
-c | Resume downloading a partially downloaded file |
-b | Download in background |
-r | Download recursively |
-P [dir] | Save files to specified directory |
--limit-rate=[rate] | Limit download speed (e.g., 200k) |
Examples:
wget https://example.com/file.zip
- Download a filewget -O output.zip https://example.com/file.zip
- Save file with specified namewget -c https://example.com/large-file.iso
- Resume interrupted download
Transfers data using various protocols.
Option | Description |
---|---|
-o [file] | Save output to specified file |
-O | Save with same name as remote file |
-L | Follow redirects |
-I, --head | Fetch HTTP headers only |
-X [method] | Specify HTTP request method (GET, POST, PUT, DELETE, etc.) |
-d, --data [data] | Send POST data |
-H [header] | Specify HTTP header |
Examples:
curl https://example.com
- Display webpage contentcurl -o page.html https://example.com
- Save webpage to specified filecurl -I https://example.com
- Fetch HTTP headers onlycurl -X POST -d "name=value" https://example.com/api
- Send POST requestcurl -s https://example.com | grep "title" | sed 's/<[^>]*>//g'
- Extract title from webpage and remove HTML tagscurl -s https://api.github.com/users/username | jq '.name, .location'
- Fetch JSON data from GitHub API and extract specific fieldscurl -u username:password https://example.com/protected
- Access using Basic authenticationcurl -H "Authorization: Bearer token123" https://api.example.com
- Access API using Bearer tokencurl -F "file=@document.pdf" https://example.com/upload
- Upload file (multipart/form-data)curl -s -w "\nHTTP Status: %{http_code}\nTotal time: %{time_total}s\n" https://example.com -o /dev/null
- Display performance statisticscurl --limit-rate 200K https://example.com/large-file.iso -o large-file.iso
- Limit download speedfor i in {1..5}; do curl -s -o /dev/null -w "%{http_code}\n" https://example.com; done
- Send multiple requests and check HTTP status codescurl -s -L https://bit.ly/shorturl
- Follow redirects to get final destination of a short URL
Displays the route packets take to reach a destination.
Option | Description |
---|---|
-n | Display IP addresses numerically (no name resolution) |
-w [seconds] | Set timeout for responses |
-m [max_ttl] | Set maximum TTL (hop count) |
-p [port] | Specify port number to use |
Examples:
traceroute google.com
- Trace route to Google serverstraceroute -n 8.8.8.8
- Trace route without name resolutiontraceroute -m 15 example.com
- Trace route with maximum 15 hopstraceroute -T -p 443 example.com
- TCP traceroute on port 443traceroute -I example.com
- Use ICMP protocol for traceroutetraceroute -4 example.com
- Use IPv4 only for traceroutetraceroute -w 1 example.com
- Set response wait time to 1 second (faster)traceroute example.com | grep -v "\*\*\*"
- Exclude timed-out hopstraceroute example.com | awk '{print $2}'
- Extract only hop IP addresses or hostnamestraceroute -q 1 example.com | grep -v "\*" | awk '{print $2}' | xargs -n 1 whois | grep "Country"
- Display country information for IPs in routefor ip in 8.8.8.8 1.1.1.1; do echo "=== $ip ==="; traceroute -n -w 1 $ip | tail -n +2 | head -n 5; done
- Compare first 5 hops to multiple destinationstraceroute example.com 2>&1 | tee traceroute_$(date +%Y%m%d_%H%M%S).log
- Save traceroute results to timestamped log file
Queries DNS information for domain names or IP addresses.
Command/Option | Description |
---|---|
nslookup [domain] | Get IP address for domain |
nslookup -type=[record_type] [domain] | Get specific DNS record type (MX, NS, SOA, etc.) |
dig [domain] | Get detailed DNS information for domain |
dig [domain] [record_type] | Get specific DNS record type |
dig +short [domain] | Display concise results only |
Examples:
nslookup google.com
- Get Google's IP addressnslookup -type=MX example.com
- Get mail server information for domaindig google.com
- Get detailed DNS information for Googledig example.com MX
- Get mail server information for domaindig +short example.com
- Display IP addresses only