Networking Basics

What You'll Learn

This guide covers essential Linux networking commands: finding your IP address, testing connectivity, transferring files over SSH, and making HTTP requests.

Finding Your Network Information

ip addr show                    # Show all network interfaces and IPs (short: ip a)
hostname -I                     # Show your IP address(es) only
ifconfig                        # Legacy command (may need: sudo apt install net-tools)

Understanding the output:

Testing Connectivity

ping

ping google.com                 # Test if you can reach Google (Ctrl+C to stop)
ping -c 4 google.com            # Send exactly 4 pings then stop

nslookup and dig

nslookup google.com             # Look up the IP address of a domain (DNS)
dig google.com                  # More detailed DNS lookup

Checking Open Ports

ss -tlnp                        # Show listening TCP ports on YOUR machine
sudo ss -tulnp                   # Show all listening ports with process names

SSH — Secure Remote Access

Connecting to a Remote Server

ssh user@192.168.1.100          # Connect via IP
ssh user@example.com            # Connect via domain name
ssh -p 2222 user@server.com     # Use a non-standard port

Setting Up SSH Keys (Passwordless Login)

# On your local machine:
ssh-keygen -t ed25519           # Generate a new key pair (press Enter for defaults)
ssh-copy-id user@server.com     # Copy your public key to the server
# Now you can SSH without typing a password!

Transferring Files with SCP

scp file.txt user@server:/home/user/       # Upload a file
scp user@server:/var/log/syslog ./         # Download a file
scp -r folder/ user@server:/home/user/     # Upload an entire folder

Making HTTP Requests with curl

curl https://example.com                # Fetch a webpage (output to terminal)
curl -O https://example.com/file.zip    # Download and save the file
curl -I https://example.com             # Show only response headers
curl -X POST -d '{"key":"val"}' http://api.example.com   # Send POST data

Downloading with wget

wget https://example.com/file.zip       # Download a file
wget -c https://example.com/big.iso     # Resume an interrupted download

Practice Exercise

ip addr show                        # Find your IP address
ping -c 4 google.com                # Test internet connectivity
nslookup github.com                 # Look up GitHub's IP
curl https://httpbin.org/ip         # See what IP the world sees you as

Troubleshooting

What's Next?

You understand networking — now automate tasks with shell scripts:

Introduction to Shell Scripting →