Networking · #14 of 19

Network Basics

ip, ping, DNS

Network Fundamentals

Key Concepts


Checking Your Network

ip — Modern Network Tool

ip addr                     # Show all interfaces and IPs
ip addr show eth0           # Show specific interface
ip link                     # Show interface state (up/down)
ip route                    # Show routing table

Understanding ip addr Output

2: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500
    inet 192.168.1.100/24 brd 192.168.1.255 scope global eth0
    inet6 fe80::1/64 scope link

Legacy Commands

ifconfig                    # Old way (deprecated but common)
route -n                    # Old routing table

Testing Connectivity

ping — Check if Host is Reachable

ping google.com             # Ping continuously
ping -c 4 google.com        # Ping 4 times and stop
ping 8.8.8.8                # Ping Google's DNS directly

traceroute — Path to Destination

traceroute google.com       # Show hops to destination
tracepath google.com        # Alternative (no root needed)

mtr — Combines ping + traceroute

mtr google.com              # Interactive continuous trace

DNS Lookup

dig — Query DNS

dig google.com              # Full DNS query
dig google.com A            # Just A record (IPv4)
dig google.com +short       # Just the IP
dig @8.8.8.8 google.com     # Use specific DNS server

nslookup — Interactive DNS Tool

nslookup google.com

host — Simple Lookup

host google.com             # Forward lookup
host 8.8.8.8                # Reverse lookup

DNS Configuration

/etc/resolv.conf

cat /etc/resolv.conf
# nameserver 8.8.8.8
# nameserver 8.8.4.4

/etc/hosts

Local hostname resolution (checked before DNS):

cat /etc/hosts
# 127.0.0.1       localhost
# 192.168.1.50    myserver

Understanding Network Ports

What is a Port?

Think of it this way: If an IP address is like a building’s street address, a port is like an apartment number within that building.

Every network connection uses both: IP:PORT

Port Analogy

Imagine a hotel:

Common Ports Reference

| Port | Service | Description | Analogy | |------|---------|-------------|---------| | 20/21 | FTP | File transfer | Loading dock | | 22 | SSH | Secure remote access | Admin’s secret entrance | | 25 | SMTP | Send email | Outgoing mail slot | | 53 | DNS | Domain name resolution | Reception desk (directory) | | 80 | HTTP | Web traffic (unencrypted) | Public lobby | | 443 | HTTPS | Secure web traffic | Secure lobby with guards | | 110 | POP3 | Receive email | Mailbox pickup | | 143 | IMAP | Email (modern) | Mail sorting room | | 3306 | MySQL | Database | Vault | | 5432 | PostgreSQL | Database | Another vault | | 6379 | Redis | Cache | Quick-access safe | | 8080 | HTTP-alt | Development web | Side door developers use |

Port Ranges

Ports are numbered 0-65535 and divided into categories:

0-1023: Well-Known Ports

1024-49151: Registered Ports

49152-65535: Dynamic/Private Ports

Checking Open Ports

See what’s listening on your machine:

# Modern way (ss = socket statistics)
sudo ss -tulpn

# Legacy way (netstat)
sudo netstat -tulpn

# Output explains:
# -t = TCP connections
# -u = UDP connections
# -l = Listening ports
# -p = Process name
# -n = Numeric (don't resolve names)

Example output:

tcp   LISTEN  0  128  0.0.0.0:22    *:*    users:(("sshd",pid=1234))
tcp   LISTEN  0  128  0.0.0.0:80    *:*    users:(("nginx",pid=5678))

This shows SSH on port 22 and a web server on port 80.

Firewall and Ports

# See which ports are allowed through firewall
sudo ufw status

# Allow a specific port
sudo ufw allow 8080/tcp

# Block a port
sudo ufw deny 23/tcp

Humor: Port 80 is like the front door — everyone knows where it is and walks right in. Port 8080 is the side door developers use when port 80 is locked (because someone else’s web server is already using it).


Common Network Tools

wget — Download Files

wget https://example.com/file.tar.gz
wget -O output.html https://example.com/page

curl — Transfer Data

curl https://example.com                  # Get page content
curl -O https://example.com/file.tar.gz   # Download file
curl -I https://example.com               # Headers only
curl -X POST -d "data=value" https://api.example.com

netstat / ss — Network Connections

ss -tuln                    # Listening TCP/UDP ports
ss -tunp                    # With process info
netstat -tuln               # Old way (still common)

Network Configuration Files

| File | Purpose | |------|---------| | /etc/hostname | Machine name | | /etc/hosts | Local DNS | | /etc/resolv.conf | DNS servers | | /etc/network/interfaces | Network config (Debian) | | /etc/netplan/*.yaml | Network config (Ubuntu 18.04+) |


Try It!

Practice network commands in the terminal:

Exercises:

  1. Check your IP: ip addr
  2. Test connectivity: ping -c 3 localhost
  3. Look up DNS: dig localhost
  4. View routing: ip route

Try it in the terminal

A sandboxed shell with this lesson’s commands. Type help to see what’s available.

bash — try it