An in-depth guide to TCP/UDP port classifications, the /etc/services protocol directory, Name Service Switch (/etc/nsswitch.conf), systemd-resolved, and DNS analysis using dig, nslookup, and host.
In modern computer networking, an IP address delivers packets to the physical host, but a Port Number determines which application daemon or background service receives that data. Meanwhile, because humans remember names (veewom.com) rather than numeric IP addresses (93.184.216.34), the Domain Name System (DNS) acts as the distributed directory service of the Internet.
This masterclass covers the three standard IANA port classifications, the standardized Linux /etc/services file, the exact internal pipeline the Linux kernel uses to resolve hostnames, and modern diagnostics using dig, nslookup, and systemd-resolved.
A port is a 16-bit unsigned integer ranging from 0 to 65535 ($2^{16} = 65,536$ total ports) allocated in transport layer headers (both TCP and UDP). An IP address paired with a port number forms a network socket (e.g., 192.168.1.100:443). Sockets allow hundreds of concurrent services (Web, SSH, Mail, Database) to communicate across a single network card without data collision.
| Port Range Category | Numeric Range | Security & Privilege Requirements | Operational Purpose |
|---|---|---|---|
| Well-Known (Privileged) Ports | 0 – 1023 |
Requires root (superuser) or CAP_NET_BIND_SERVICE capability. |
Reserved for core standardized Internet services (SSH, HTTP, DNS, SMTP, FTP). Prevents rogue unprivileged users from hijacking critical services. |
| Registered Ports | 1024 – 49151 |
Can be bound by regular unprivileged users or service daemons. | Assigned by IANA for specific vendor server applications (MySQL 3306, PostgreSQL 5432, Redis 6379, Tomcat 8080). |
| Dynamic / Ephemeral (Private) Ports | 49152 – 65535 |
Kernel allocated dynamically. | Assigned automatically by the Linux kernel to client applications (e.g., your browser connecting to a remote web server) for temporary two-way communication. |
Linux Kernel Pro-Tip: You can check or tune your Linux system's ephemeral port range by running:
cat /proc/sys/net/ipv4/ip_local_port_range(typically returns32768 60999).
Linux maintains a standardized system database file located at /etc/services that maps service protocol names to port numbers:
| Port Number | Transport Protocol | Service Name | Functional Description |
|---|---|---|---|
| 20 / 21 | TCP | FTP (Data / Control) | File Transfer Protocol for moving files (plain text credentials). |
| 22 | TCP | SSH / SFTP | Secure Shell encrypted remote terminal access and secure file copy. |
| 25 | TCP | SMTP | Simple Mail Transfer Protocol for relaying email between mail servers. |
| 53 | UDP & TCP | DNS | Domain Name System for translating hostnames to IP addresses. |
| 67 / 68 | UDP | DHCP (Server / Client) | Dynamic Host Configuration Protocol for automatic IP leasing. |
| 80 | TCP | HTTP | Hypertext Transfer Protocol for unencrypted World Wide Web browsing. |
| 110 | TCP | POP3 | Post Office Protocol v3 for retrieving stored email messages. |
| 143 | TCP | IMAP | Internet Message Access Protocol for synchronized multi-device email. |
| 443 | TCP / UDP (QUIC) | HTTPS | Hypertext Transfer Protocol Secure (HTTP over TLS/SSL encryption). |
| 2049 | TCP / UDP | NFS | Network File System for sharing Linux storage volumes over LAN. |
| 139 / 445 | TCP | SMB / NetBIOS | Samba file and printer sharing protocol for Windows-Linux interoperability. |
| 3306 | TCP | MySQL / MariaDB | Standard relational database service port. |
| 5432 | TCP | PostgreSQL | Enterprise object-relational database listener. |
| 6379 | TCP | Redis | In-memory caching and key-value datastore. |
You can search /etc/services directly from your terminal using grep:
# Look up the port for MySQL
grep -w 3306 /etc/services
# Returns: mysql 3306/tcp # MySQL
# Look up the port for SSH
grep -w "^ssh" /etc/services
# Returns: ssh 22/tcp # SSH Remote Login Protocol
When a user types curl https://veewom.com or writes code that makes an HTTP request, the Linux system invokes the standard C library function getaddrinfo(). The system resolves the domain through a strictly defined hierarchy:
/etc/nsswitch.conf):hosts line usually reads:
hosts: files dns (or files resolve dns). This instructs Linux to check local static files first before sending packets across the network./etc/hosts):/etc/hosts. If an entry exists (e.g. 192.168.1.50 testserver.local), the kernel resolves the IP immediately with zero latency and stops further queries.127.0.0.53):/etc/resolv.conf points to the loopback stub listener 127.0.0.53 managed by systemd-resolved. If the IP is cached locally in RAM, it is returned instantly.8.8.8.8 or router IP).a.root-servers.net to m.root-servers.net) to find the Top-Level Domain (TLD) authoritative servers (e.g., .com).dig is the industry standard for diagnosing DNS issues, querying nameservers directly and showing full answer payloads:
# 1. Standard DNS query for IPv4 A record
dig veewom.com
# 2. Short answer format (prints only the resolved IP address)
dig veewom.com +short
# 3. Query a specific DNS server directly (bypassing local /etc/resolv.conf)
dig @8.8.8.8 veewom.com
# 4. Query specific record types (MX for Mail, NS for Nameservers, TXT for SPF/DKIM)
dig veewom.com MX +short
dig veewom.com NS +short
dig veewom.com TXT +short
# 5. Reverse DNS lookup (Resolving an IP to a hostname / PTR record)
dig -x 8.8.8.8 +short
# Returns: dns.google.
# 6. Full hierarchical trace from root servers to authoritative nameserver
dig +trace veewom.com
# Quick one-line lookup with host
host veewom.com
# Check mail exchangers
host -t MX google.com
# Interactive query with nslookup
nslookup veewom.com
# View active DNS servers and caching statistics
resolvectl status
# Flush local DNS cache in Ubuntu / Debian
sudo resolvectl flush-caches
# Verify cache statistics
resolvectl statistics
# Display all listening TCP and UDP ports with process name
sudo ss -tulpn
# Filter specifically for web servers (Port 80/443) or SSH (22)
sudo ss -tulpn | grep -E ':22|:80|:443'
System administrators use /etc/hosts to test staging websites before switching public DNS records:
# Add a staging server override
echo "192.168.1.200 staging.mycompany.com" | sudo tee -a /etc/hosts
# Verify ping points immediately to the private IP
ping -c 2 staging.mycompany.com
# Remove the test line when finished
sudo sed -i '/staging.mycompany.com/d' /etc/hosts
8.8.8.8 or Cloudflare 1.1.1.1) does not own the records; instead, it does the legwork of querying root, TLD, and authoritative servers on behalf of client machines and caches the answers.
/etc/resolv.conf is a dynamic symlink generated automatically by network managers (such as systemd-resolved, NetworkManager, or netplan). If you edit it manually, the managing daemon overwrites your changes on connection renewal or reboot. To make persistent DNS changes, configure them inside your Netplan YAML file or NetworkManager connection profile.
EADDRINUSE (Address already in use) error, and the second process fails to start. Only one application can listen on an exact IP:Port tuple unless the processes set the special socket option SO_REUSEPORT (used by Nginx worker processes for multi-threaded kernel load balancing).
nc -zv server-ip 443 or test using Bash's built-in TCP socket device: timeout 3 bash -c '</dev/tcp/server-ip/443' && echo "Port is Open" || echo "Port is Closed".