Networking Commands, Ports & Subnetting
Your fast, plain-English field guide for diagnosing connections, looking up ports, calculating IPv4 subnets, and navigating the OSI model.
Command Anatomy
Most network CLI tools follow the same three-part pattern: Tool + Flag + Target.
ping -c 4 8.8.8.8
How a Request Travels
Packet Flow: Client โ Router (Gateway) โ DNS (Name to IP) โ Destination Server.
1 Essential CLI Commands
Use these six commands to check your IP, test reachability, trace routes, verify DNS, inspect open
ports, and test HTTP responses. Press Ctrl+C anytime to stop a
running ping on Linux/macOS.
ping -c 4 8.8.8.8
Win: ping 8.8.8.8
traceroute google.com
Win: tracert google.com
ip -br addr
Win: ipconfig /all
dig +short example.com
Alt: nslookup example.com
ss -tulnp
Win: netstat -ano
-tuln) and which process
ID (-p) owns them.curl -I https://example.com
Linux / macOS / Win 10+
200 OK or 404 without downloading the page body.2 Well-Known Ports Quick Table
Ports act like apartment numbers on a server's IP address, routing traffic to the right service. TCP guarantees delivery; UDP prioritizes speed.
| Port | Protocol | Service | Plain-English Purpose |
|---|---|---|---|
20 / 21 |
TCP | FTP | File Transfer Protocol (21 = control, 20 = data). Unencrypted โ prefer SFTP (22). |
22 |
TCP | SSH / SFTP | Secure Shell for encrypted remote terminal login and file transfers. |
25 |
TCP | SMTP | Simple Mail Transfer Protocol โ sends outgoing email between mail servers. |
53 |
TCP / UDP | DNS | Domain Name System โ translates names like shekharit.com to IPs (UDP
for queries, TCP for zone transfers). |
67 / 68 |
UDP | DHCP | Automatically assigns IP addresses, subnet masks, and gateways to devices (67 = server, 68 = client). |
80 |
TCP | HTTP | Unencrypted web traffic. Usually redirected to port 443. |
443 |
TCP | HTTPS | Encrypted web traffic using TLS/SSL (also HTTP/3 uses UDP 443). |
445 |
TCP | SMB | Windows file & printer sharing. Never expose directly to the public internet. |
3389 |
TCP / UDP | RDP | Remote Desktop Protocol for graphical Windows remote control. |
3 IPv4 Subnetting & CIDR Cheat Table
CIDR notation (/24) counts how many bits of the 32-bit IPv4 address belong to the
network. Remember: Usable Hosts = Total IPs โ 2 (first is Network
ID, last is Broadcast), except /32 which is a single host route.
| CIDR | Subnet Mask | Total IPs | Usable Hosts | Typical Use |
|---|---|---|---|---|
/8 |
255.0.0.0 |
16,777,216 | 16,777,214 | Massive enterprise / Class A block |
/16 |
255.255.0.0 |
65,536 | 65,534 | Cloud VPCs (AWS / Azure / GCP) |
/24 |
255.255.255.0 |
256 | 254 | Standard home, office, or VLAN subnet |
/25 |
255.255.255.128 |
128 | 126 | Half of a /24 (department LAN) |
/26 |
255.255.255.192 |
64 | 62 | Small office or app tier subnet |
/27 |
255.255.255.224 |
32 | 30 | Database or microservice subnet |
/28 |
255.255.255.240 |
16 | 14 | Small server cluster / DMZ |
/30 |
255.255.255.252 |
4 | 2 | Point-to-point router-to-router link |
/32 |
255.255.255.255 |
1 | 1 (Host) | Single IP (firewall allowlist / loopback) |
Private IPv4 Ranges (RFC 1918)
These ranges are reserved for internal networks and are not routable on the public internet:
~16.7M IPs (Enterprise & Cloud)
~1M IPs (Docker & Mid-size)
65,536 IPs (Home & Small LAN)
4 OSI Model 7-Layer Quick Reference
The OSI model splits networking into 7 layers so you can isolate problems (for example: "Is the cable unplugged at Layer 1, or is DNS failing at Layer 7?").
All People Seem To Need Data Processing
Application โ Presentation โ Session โ Transport โ Network โ Data Link โ Physical
| Layer | Name | Data Unit (PDU) | Key Protocols & Devices | What It Does |
|---|---|---|---|---|
L7 |
Application | Data | HTTP, HTTPS, DNS, SSH, SMTP | Interfaces directly with user apps (browsers, mail clients). |
L6 |
Presentation | Data | TLS/SSL, JSON, UTF-8, JPEG | Encrypts, compresses, and formats data for the app. |
L5 |
Session | Data | RPC, NetBIOS, Auth Sessions | Opens, manages, and closes communication sessions. |
L4 |
Transport | Segment | TCP, UDP, Ports | Reliable delivery (TCP) or fast delivery (UDP) + port numbers. |
L3 |
Network | Packet | IP, ICMP, Routers | Logical addressing (IP) and routing across different networks. |
L2 |
Data Link | Frame | Ethernet, Wi-Fi, MAC, Switches | Moves frames on the local LAN using hardware MAC addresses. |
L1 |
Physical | Bits | Cables, Fiber, Hubs, NICs | Transmits raw 1s and 0s over copper, fiber, or radio waves. |
5 Danger Zone & Common Mistakes
0.0.0.0/0 on Admin Ports: Allowing
0.0.0.0/0 on port 22 (SSH), 3389 (RDP), or
3306 (MySQL) exposes your server to every bot on the internet. Restrict admin
ports to your own IP (YOUR_IP/32) or a VPN.
ufw enable Before ufw allow 22:
Enabling a firewall on a cloud VPS without allowing SSH first will immediately lock you out
of your own server. Always allow SSH before enabling the firewall.
/24 with /32: Writing
203.0.113.10/24 in a firewall rule allows all 256 IPs in that neighborhood,
not just your machine. Use /32 for a single IP address.
ping Means a Server Is Down: Many cloud
firewalls block ICMP (ping) by default. Always verify with
curl -I or dig before concluding a service is offline.