How to Block an IP Address with firewalld on Linux
On a host using firewalld, block one IP with a rich rule: sudo firewall-cmd --add-rich-rule='rule family=ipv4 source address=203.0.113.50 drop'. Add --permanent and reload to keep it after reboot. Prefer Fail2ban for repeated SSH noise.
Quick answer
sudo firewall-cmd --add-rich-rule='rule family=ipv4 source address=203.0.113.50 drop'
sudo firewall-cmd --permanent --add-rich-rule='rule family=ipv4 source address=203.0.113.50 drop'
sudo firewall-cmd --reloadWhy block at the host?
Sometimes one IP floods SSH or your app. You need a fast host-level drop while you also fix cloud rules. Aisha in Lagos and Dev in Aurangabad both keep the rich-rule syntax in their incident notes.
What is a rich rule?
A firewalld rule with extra match fields (source address, port, service). drop discards matching packets.
How do I block step by step?
- Confirm firewalld is running:
systemctl is-active firewalldWhat it means: Must print active. If not, do not blindly enable without knowing your network plan.
- Temporary block:
sudo firewall-cmd --add-rich-rule='rule family="ipv4" source address="203.0.113.50" drop'successWhat it means: Packets from that IPv4 address are dropped until reboot (or until removed).
- List rules:
sudo firewall-cmd --list-rich-rulesWhat it means: Shows the active rich rules so you can audit them.
- Make it permanent:
sudo firewall-cmd --permanent --add-rich-rule='rule family="ipv4" source address="203.0.113.50" drop' sudo firewall-cmd --reloadWhat it means: Saved to permanent config and applied.
- Remove later with
--remove-rich-ruleusing the same rule string.
On AWS, also consider a security-group deny via tighter allow-lists, or an NACL deny for stubborn cases (NACL guide).
Ravindra Bagale's Tip
Blocking one IP is a bandage. If you are on AWS, also restrict the security group. Cloud and host firewalls work together. Chen in Singapore blocks at both layers during an incident.
Ravindra Bagale's Tip – मराठी
एक IP block करणे पट्टी आहे. AWS वर असाल तर security group सुद्धा आवरा. Cloud आणि host firewall एकत्र काम करतात. सिंगापूरमधील चेन घटनेत दोन्ही थर वापरतो.
Ravindra Bagale's Tip – हिंदी
एक IP ब्लॉक करना पट्टी है। AWS पर हो तो security group भी कसें। Cloud और host firewall साथ काम करते हैं। सिंगापुर के चेन घटना में दोनों परतें लगाते हैं।
Quick quiz: check what you learned
Which two firewalld steps make a rich rule survive reboot?
- Add with --permanent then --reload
- Only hope the attacker goes away
- Disable SELinux on the whole host
- Open port 0 to the public internet
Show answer
A. Runtime rules die on reboot without --permanent + reload.
Best long-term protection for SSH on a public server?
- Fail2ban plus a tight security group
- Public password auth left forever
- No logging of failed SSH attempts
- FTP on port 21 left wide open
Show answer
A. Layer host firewall, cloud SG, and fail2ban.
Learn it properly
This guide is the short path. These pages go deeper, with labs:
Frequently asked questions
How do I block an IP with firewalld?
sudo firewall-cmd --add-rich-rule='rule family=ipv4 source address=IP drop'
How do I block a whole /24?
Use source address=203.0.113.0/24 in the rich rule — carefully.
firewalld vs AWS NACL?
firewalld is on the OS. NACL is in the VPC subnet. Different layers.
What about Ubuntu ufw?
Use sudo ufw deny from IP. This guide focuses on firewalld (Amazon Linux / RHEL).
Related?
Fail2ban guide and Cyber 32.3 host firewall lesson.