|$ curl https://forge-ai.dev/api/markdown?path=docs/linux/networking
$cat docs/networking.md
updated Recently·22 min read·published

Networking

LinuxNetworkingcurlfirewallIntermediate🎯Free Tools
Introduction

Every server, container, and cloud instance relies on Linux networking. Knowing how to inspect interfaces, diagnose connectivity, and secure traffic is essential for backend engineers, DevOps, and anyone deploying production workloads.

Network Interfaces
interfaces.sh
Bash
1# Modern tool: ip
2ip addr show
3ip link show
4
5# Bring an interface up or down
6sudo ip link set eth0 up
7sudo ip link set eth0 down
8
9# Add or remove an IP address
10sudo ip addr add 192.168.1.50/24 dev eth0
11sudo ip addr del 192.168.1.50/24 dev eth0
12
13# Routing table
14ip route show
15ip route get 8.8.8.8
📝

note

The older ifconfig and route commands still work on many systems, but ip is the modern replacement and should be preferred.
Sockets & Listening Ports
sockets.sh
Bash
1# Modern replacement for netstat
2ss -tlnp # TCP listening ports with process
3ss -tunlp # TCP and UDP listening with process
4ss -s # socket statistics
5
6# Legacy netstat (still common)
7netstat -tlnp
8
9# Check if a port is open locally
10curl -v http://localhost:3000
HTTP with curl
curl.sh
Bash
1# Simple GET
2curl https://api.example.com/users
3
4# Follow redirects, show headers
5curl -L -I https://forgelearn.dev
6
7# POST JSON
8curl -X POST https://api.example.com/users \
9 -H "Content-Type: application/json" \
10 -d '{"name":"alice","role":"admin"}'
11
12# Save response to file
13curl -o output.json https://api.example.com/data
14
15# Show timing and verbose output
16curl -w "@curl-format.txt" -o /dev/null -s https://forgelearn.dev
17curl -v https://forgelearn.dev
DNS
dns.sh
Bash
1# Lookup IP for a domain
2nslookup forgelearn.dev
3host forgelearn.dev
4dig forgelearn.dev
5
6# Query a specific nameserver
7dig @8.8.8.8 forgelearn.dev
8
9# Reverse DNS
10dig -x 8.8.8.8
11
12# DNS resolution config
13cat /etc/resolv.conf
Firewall
firewall.sh
Bash
1# ufw (Uncomplicated Firewall) — Debian/Ubuntu
2sudo ufw status
3sudo ufw allow 22/tcp
4sudo ufw allow 80/tcp
5sudo ufw allow 443/tcp
6sudo ufw enable
7
8# iptables / nftables
9sudo iptables -L -v -n
10sudo iptables -A INPUT -p tcp --dport 22 -j ACCEPT

warning

Before enabling a firewall on a remote server, make sure you have allowed your SSH port (usually 22) so you do not lock yourself out.
Troubleshooting
troubleshooting.sh
Bash
1# Test connectivity
2ping 8.8.8.8
3ping forgelearn.dev
4
5# Trace route
6mtr forgelearn.dev
7traceroute forgelearn.dev
8
9# Check DNS resolution
10getent hosts forgelearn.dev
11
12# Inspect TLS certificate
13openssl s_client -connect forgelearn.dev:443 -servername forgelearn.dev </dev/null