Bash Network Commands - curl, wget, ssh, scp, ping, netstat

Essential bash networking commands for HTTP requests (curl, wget), secure remote access (ssh, scp), connectivity testing (ping), and port inspection (netstat, ss).

Network

Detailed Explanation

Network Commands in Bash

Networking commands are essential for interacting with APIs, managing remote servers, troubleshooting connectivity, and transferring files securely.

HTTP Requests with curl

curl is the most versatile command-line HTTP client:

# GET request
curl -s https://api.example.com/users | jq .

# POST with JSON
curl -X POST https://api.example.com/users \
  -H "Content-Type: application/json" \
  -d '{"name": "Alice", "email": "alice@example.com"}'

# Upload a file
curl -F "file=@document.pdf" https://api.example.com/upload

# Download with progress
curl -O -L https://example.com/releases/v2.0/app.tar.gz

# Follow redirects and show headers
curl -LI https://example.com

# Send with authentication
curl -H "Authorization: Bearer $TOKEN" https://api.example.com/protected

# Measure response time
curl -o /dev/null -s -w "Time: %{time_total}s\n" https://example.com

File Downloads with wget

wget https://example.com/file.tar.gz           # simple download
wget -c https://example.com/large.iso           # resume interrupted
wget -O output.txt https://example.com/data     # custom filename
wget --limit-rate=1m https://example.com/big    # rate limit

Secure Shell (SSH)

ssh user@server.com                    # connect
ssh -p 2222 user@server.com            # custom port
ssh user@server "df -h && free -h"     # run remote command
ssh -L 8080:localhost:3000 user@server -N  # tunnel
ssh-keygen -t ed25519                  # generate key pair
ssh-copy-id user@server               # install public key

Secure Copy (SCP)

scp file.txt user@server:/path/           # upload
scp user@server:/path/file.txt ./         # download
scp -r directory/ user@server:/path/      # recursive

Connectivity Testing

# Ping
ping -c 4 google.com

# DNS lookup
dig example.com
nslookup example.com

# Traceroute
traceroute example.com

# Port check
nc -zv server.com 443

Port and Connection Info

# List listening ports
ss -tlnp
netstat -tlnp

# Show established connections
ss -s
netstat -an | grep ESTABLISHED | wc -l

# Check if port is in use
lsof -i :3000

Use Case

Network commands are used for API testing and integration, remote server management, automated deployments over SSH, downloading dependencies and artifacts, troubleshooting network connectivity issues, and monitoring service health. DevOps engineers and backend developers use these commands daily.

Try It — Bash Cheat Sheet

Open full tool