Networking¶
Prerequisites¶
- Root or sudo privileges for network configuration changes
Quick Reference¶
| Action | Command |
|---|---|
| Show IP | ip addr |
| Show Routes | ip route |
| Ping | ping <host> |
| Check TCP port | nc -zv <host> <port> |
| Scan Ports | nmap <host> |
| Local Ports | ss -tlnp |
| DNS Lookup | dig <domain> |
| Hostname | hostnamectl set-hostname <name> |
Procedure: Check IP Address and Interfaces¶
When to use: Verifying network configuration, troubleshooting connectivity, or finding your IP.
Steps:
-
List all interfaces and IP addresses:
Look forip addreth0orens3. -
Show only up/running interfaces:
ip link show up -
Display routing table (gateway):
ip route
Troubleshooting:
- If an interface is
DOWN: Bring it up withip link set dev <interface> upor check virtualization settings.
Procedure: Test Connectivity with ping¶
When to use: Checking if a remote host is reachable.
Steps:
-
Ping by IP address (bypasses DNS):
ping 8.8.8.8 -
Ping by hostname (tests DNS + connectivity):
ping google.com -
Trace the path to a host:
traceroute google.com
Troubleshooting:
- "Destination Host Unreachable": Routing issue or local link down.
- "Request timed out": Remote host is down or blocking ICMP (firewall).
- "Temporary failure in name resolution": DNS issue.
Procedure: Scan Ports with nmap¶
When to use: Verifying which services are listening on a remote machine or checking firewall rules.
Steps:
-
Scan for open TCP ports (default top 1000):
nmap <target_ip> -
Scan specific ports:
nmap -p 80,443 <target_ip> -
Scan all 65535 ports (slow):
nmap -p- <target_ip> -
Check local listening ports (without nmap):
ss -tlnp
Troubleshooting:
- "Note: Host seems down": The host blocks ping. Add
-Pnto skip ping check.
Procedure: Check a TCP Port with nc¶
When to use: Quickly testing whether a specific TCP port on a host is open and accepting connections, without installing nmap.
Steps:
-
Test a single TCP port:
Example:nc -zv <host> <port>nc -zv example.com 443— a successful connection prints "Connection to ... succeeded!" -
Test a range of ports:
nc -zv <host> 80-443 -
Set a timeout (useful for filtered/firewalled ports):
nc -zv -w 3 <host> <port>
Why this does not work for UDP: UDP is connectionless — there is no handshake. When you send a UDP packet, the remote host is not required to respond. A closed UDP port may send back an ICMP "port unreachable" message, but firewalls typically block that. This means nc -u cannot distinguish between an open port (no response) and a firewalled port (no response). Use nmap -sU for UDP scanning, but be aware it is slow and unreliable for the same reasons.
Procedure: Disable IPv6¶
When to use: Troubleshooting network issues or if IPv6 is not supported/needed in your environment.
Steps:
-
Edit sysctl configuration:
nano /etc/sysctl.d/disable-ipv6.conf -
Add the following lines:
net.ipv6.conf.all.disable_ipv6 = 1 net.ipv6.conf.default.disable_ipv6 = 1 -
Apply changes immediately:
sysctl -p /etc/sysctl.d/disable-ipv6.conf
Troubleshooting:
- If IPv6 is still active on some interfaces: Restart the network service or reboot.
Procedure: Change the Hostname¶
When to use: Setting a meaningful name for the server (e.g., web01.example.com).
Steps:
-
Set the hostname:
hostnamectl set-hostname <new-hostname> -
Verify:
hostnamectl -
Update
/etc/hoststo resolve the new name locally:Update the line starting withnano /etc/hosts127.0.0.1or your static IP.
Troubleshooting:
- Shell prompt doesn't update: Log out and log back in.
Procedure: Configure /etc/hosts¶
When to use: Overriding DNS for testing or mapping names on a system without a DNS server.
Steps:
-
Edit the file:
nano /etc/hosts -
Add mappings in
IP hostname aliasformat:************ web01.example.com web01 ********* localhost -
Verify the new entry resolves correctly:
Check that the output shows the correct IP address (first line). The ping itself may time out if ICMP is blocked — that's fine, the IP in the output is what matters.ping -c 1 web01.example.com
Troubleshooting:
- Changes ignored: Check
/etc/nsswitch.conf. Thehostsline should start withfiles dns.
Related Documentation¶
- Concepts: Networking Models