Opening Web Server Ports on CentOS
A web server on a VPS requires port configurations to allow public access to hosted websites. The specific ports that need to be opened within iptables are port 80 (HTTP) and port 443 (HTTPS). There are two methods to configure this setup:
1: Editing the /etc/sysconfig/iptables File
vi /etc/sysconfig/iptables
# Firewall configuration written by system-config-firewall
# Manual customization of this file is not recommended.
*filter
:INPUT ACCEPT [0:0]
:FORWARD ACCEPT [0:0]
:OUTPUT ACCEPT [0:0]
-A INPUT -m state –state ESTABLISHED,RELATED -j ACCEPT
-A INPUT -p icmp -j ACCEPT
-A INPUT -i lo -j ACCEPT
-A INPUT -m state –state NEW -m tcp -p tcp –dport 22 -j ACCEPT
-A INPUT -m state –state NEW -m tcp -p tcp –dport 80 -j ACCEPT
-A INPUT -m state –state NEW -m tcp -p tcp –dport 443 -j ACCEPT
-A INPUT -j REJECT –reject-with icmp-host-prohibited
-A FORWARD -j REJECT –reject-with icmp-host-prohibited
2: Using the Command Line Interface (CLI)
iptables -A INPUT -p tcp -m tcp --dport 80 -j ACCEPT iptables -A INPUT -p tcp -m tcp --dport 443 -j ACCEPT iptables -I INPUT -m state --state ESTABLISHED,RELATED -j ACCEPT
Saving and Restarting iptables
service iptables save
Next, restart the iptables service to apply the changes:
service iptables restart
Verifying the Firewall Settings
iptables -L
Chain INPUT (policy ACCEPT)
target prot opt source destination
ACCEPT all — anywhere anywhere state RELATED,ESTABLISHED
ACCEPT icmp — anywhere anywhere
ACCEPT all — anywhere anywhere
ACCEPT tcp — anywhere anywhere state NEW tcp dpt:ssh
ACCEPT tcp — anywhere anywhere state NEW tcp dpt:http
REJECT all — anywhere anywhere reject-with icmp-host-prohibited
Once verified, you can test the connection by accessing the website hosted on your server via any web browser.
Recent Articles
-
Cloudmatika / July 17, 2026
How to Install and Configure an SSL Certificate on Windows Server and IIS
-
Cloudmatika / March 30, 2026
Tier 3 Data Center for Stable Business Operations
-
Cloudmatika / March 30, 2026
Cyber Protect for the Digital Industry: Strategies for Protecting Data, Systems, and Business Operations
-
Cloudmatika / March 26, 2026
Save Costs with Containers in a Virtual Data Center
-
Cloudmatika / March 26, 2026
Zimbra Email & Collaboration for Cost Efficiencies
