Master Linux Firewall: firewalld and iptables Commands Explained
This guide walks you through using Linux's two main firewall tools—firewalld for CentOS 7+ and iptables for older versions—covering installation, service control, rule management, port handling, and useful commands with clear examples and screenshots.
firewalld (CentOS 7+)
Start the firewall service systemctl start firewalld Stop the firewall service systemctl stop firewalld Check firewall status systemctl status firewalld Enable firewall at boot systemctl enable firewalld Disable firewall at boot systemctl disable firewalld Reload firewall rules firewall-cmd --reload Open a port (requires reload to take effect)
firewall-cmd --zone=public --add-port=8080/tcp --permanentList opened ports firewall-cmd --list-ports Close a port
firewall-cmd --zone=public --remove-port=8080/tcp --permanentiptables (CentOS < 7)
Installation
Install iptables package yum install iptables Install iptables services
yum install iptables-servicesService Control
Start iptables systemctl start iptables.service Stop iptables systemctl stop iptables.service Check iptables status systemctl status iptables.service Enable iptables at boot systemctl enable iptables.service Disable iptables at boot
systemctl disable iptables.serviceRule Management
View filter table chains (e.g., INPUT) iptables -L -n View NAT table chains iptables -t nat -L -n Flush all rules
iptables -F iptables -X iptables -ZAdd rule to open port 8080 on INPUT chain iptables -I INPUT -p tcp --dport 8080 -j ACCEPT List rule line numbers for INPUT chain iptables -L INPUT --line-numbers -n Delete rule by line number (e.g., close port 8080)
iptables -D INPUT 1Signed-in readers can open the original source through BestHub's protected redirect.
This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactand we will review it promptly.
macrozheng
Dedicated to Java tech sharing and dissecting top open-source projects. Topics include Spring Boot, Spring Cloud, Docker, Kubernetes and more. Author’s GitHub project “mall” has 50K+ stars.
How this landed with the community
Was this worth your time?
0 Comments
Thoughtful readers leave field notes, pushback, and hard-won operational detail here.
