Complete List of Common Iptables Named Ports: SSH, HTTP, HTTPS, MySQL and More


3 views

When working with iptables, you can reference network services by name instead of port numbers. These names are defined in the /etc/services file on Linux systems, which maps service names to their standard port numbers and protocols.

Here are the most frequently used service names in iptables rules:

ssh       - TCP 22
http      - TCP 80
https     - TCP 443
mysql     - TCP 3306
domain    - UDP 53 (DNS)
smtp      - TCP 25
pop3      - TCP 110
imap      - TCP 143
ftp       - TCP 21
ntp       - UDP 123

Here's how you would use these service names in actual iptables rules:

# Allow SSH access
iptables -A INPUT -p tcp --dport ssh -j ACCEPT

# Allow HTTP and HTTPS traffic
iptables -A INPUT -p tcp --dport http -j ACCEPT
iptables -A INPUT -p tcp --dport https -j ACCEPT

# Allow MySQL connections from specific network
iptables -A INPUT -p tcp -s 192.168.1.0/24 --dport mysql -j ACCEPT

To check if a service name exists in your system:

grep ssh /etc/services
getent services ssh

If you need to add a service name that's not in /etc/services:

echo "myapp 9999/tcp # Custom application port" >> /etc/services

Remember that service names are case-sensitive in iptables. Also, some services might have multiple names (e.g., 'domain' and 'dns' both refer to port 53). When in doubt, always verify the port mapping.


When configuring iptables firewall rules, Linux administrators often use service names instead of numeric port numbers for better readability. These mappings are defined in the /etc/services file, which contains the standard port assignments for common services.

Here are the most frequently used service name to port mappings:


# SSH (Secure Shell)
ssh = 22

# Web services
http = 80
https = 443

# Database
mysql = 3306
postgresql = 5432

# Mail services
smtp = 25
imap = 143
imaps = 993
pop3 = 110
pop3s = 995

# DNS
domain = 53

Here's how to use these named ports in actual iptables rules:


# Allow incoming SSH connections
iptables -A INPUT -p tcp --dport ssh -j ACCEPT

# Allow HTTP and HTTPS traffic
iptables -A INPUT -p tcp --dport http -j ACCEPT
iptables -A INPUT -p tcp --dport https -j ACCEPT

# Allow MySQL connections from specific subnet
iptables -A INPUT -p tcp -s 192.168.1.0/24 --dport mysql -j ACCEPT

To see all available service names and their corresponding ports:


cat /etc/services | less

# Or search for specific services:
grep -E 'ssh|http|https|mysql' /etc/services

If you need to add custom service names for your applications, edit /etc/services:


# Example custom service
myapp    5000/tcp    # Custom application port
myapp-ssl    5001/tcp    # SSL version

To verify that iptables correctly interprets service names:


iptables -L -n -v | grep -E '22|80|443|3306'

This will show you if the rules are properly translated to their numeric equivalents.

1. Always check /etc/services for the exact service names on your system
2. Consider using numeric ports in production for consistency
3. Document any custom service names added
4. Test rules thoroughly after implementation