html
Before opening port 8080, it's good practice to verify its current status. You can use nmap or netstat:
nmap localhost -p 8080
# or
netstat -tuln | grep 8080
CentOS uses iptables as its firewall solution. The rules are organized in chains (INPUT, OUTPUT, FORWARD). For opening a port, we mainly work with the INPUT chain.
To open TCP port 8080, run these commands as root:
iptables -I INPUT -p tcp --dport 8080 -j ACCEPT
service iptables save
service iptables restart
Check if your rule was added successfully:
iptables -L -n -v | grep 8080
On CentOS 6 and earlier, use:
service iptables save
For CentOS 7+, you'll need to install iptables-services first:
yum install iptables-services
systemctl enable iptables
systemctl start iptables
iptables-save > /etc/sysconfig/iptables
If you're using firewalld instead of iptables:
firewall-cmd --zone=public --add-port=8080/tcp --permanent
firewall-cmd --reload
If the port still isn't accessible:
- Check SELinux status:
sestatus
- Verify service is listening:
ss -tulnp | grep 8080
- Test locally first:
curl http://localhost:8080
When opening ports:
- Restrict source IPs if possible:
iptables -I INPUT -p tcp -s 192.168.1.0/24 --dport 8080 -j ACCEPT
- Consider rate limiting:
iptables -A INPUT -p tcp --dport 8080 -m limit --limit 25/minute --limit-burst 100 -j ACCEPT
- Monitor connections:
watch -n 1 'netstat -an | grep 8080'
Before modifying firewall settings, verify if port 8080 is already open or in use:
nmap -p 8080 localhost
ss -tulnp | grep 8080
netstat -tulnp | grep 8080
CentOS uses iptables as its default firewall. The rules are organized in chains (INPUT, OUTPUT, FORWARD) with specific policies (ACCEPT, DROP, REJECT). For web applications, we typically modify the INPUT chain.
To open port 8080 for TCP traffic:
iptables -I INPUT -p tcp --dport 8080 -j ACCEPT
service iptables save
service iptables restart
For more granular control, you can specify source IP ranges:
iptables -I INPUT -p tcp -s 192.168.1.0/24 --dport 8080 -j ACCEPT
To ensure rules persist after reboot:
service iptables save
chkconfig iptables on
Or on CentOS 7+:
yum install iptables-services
systemctl enable iptables
systemctl start iptables
For CentOS 7+ with firewalld:
firewall-cmd --zone=public --add-port=8080/tcp --permanent
firewall-cmd --reload
After applying changes, verify the new rule exists:
iptables -L -n -v | grep 8080
Test connectivity from another machine:
telnet your_server_ip 8080
nc -zv your_server_ip 8080
If connection issues persist:
- Check SELinux status:
sestatus
- Add SELinux rule if needed:
semanage port -a -t http_port_t -p tcp 8080
- Verify service is listening:
lsof -i :8080
When opening ports:
- Always restrict source IPs when possible
- Consider rate limiting:
iptables -A INPUT -p tcp --dport 8080 -m limit --limit 25/minute --limit-burst 100 -j ACCEPT
- Implement fail2ban for additional protection
- Regularly audit open ports:
nmap -sT -O localhost