πŸ‘₯ Linux/Unix: User, Group & Security Management
Estimated reading: 4 minutes 28 views

πŸ” Linux/Unix: Basic Security Tools – chattr, semanage, ufw, firewalld Explained

🧲 Introduction – Why Learn Linux Security Tools?

Securing a Linux system isn’t just about strong passwordsβ€”it’s about controlling file immutability, access policies, and firewall configurations. Whether you’re protecting log files from tampering or securing ports, tools like chattr, semanage, ufw, and firewalld provide fine-grained control over security without requiring third-party software.

🎯 In this guide, you’ll learn:

  • How to make files immutable with chattr
  • How to manage SELinux contexts with semanage
  • How to control firewall access using ufw and firewalld
  • Real-world use cases and examples

πŸ›‘οΈ 1. chattr – Make Files Immutable or Append-Only

βœ… What is chattr?

chattr (change attribute) sets file attributes on ext-based filesystems (ext2/3/4), allowing you to make files immutable (cannot be modified or deleted) or append-only.

πŸ› οΈ Syntax:

sudo chattr [+/-][attribute] filename

πŸ”Ή Common Attributes:

AttributeDescription
+iImmutable (cannot be changed/deleted)
+aAppend-only (can only add data)

πŸ§ͺ Example 1: Make a log file immutable

sudo chattr +i /var/log/syslog

🧠 Even root can’t modify or delete it until you remove the attribute:

sudo chattr -i /var/log/syslog

πŸ”’ 2. semanage – Manage SELinux Policies (RHEL-based)

βœ… What is semanage?

semanage is a policy management tool for SELinux, used to manage file contexts, ports, and booleans in a secure, persistent way.

πŸ“¦ Install:

sudo yum install policycoreutils-python-utils  # RHEL/CentOS

πŸ› οΈ Syntax:

semanage [object_type] -l/add/delete -a -t context name

πŸ§ͺ Example 1: Allow HTTP on a custom port

sudo semanage port -a -t http_port_t -p tcp 8081

βœ… Now SELinux won’t block Apache on port 8081.

πŸ§ͺ Example 2: View port rules

semanage port -l | grep http

🧠 Used in SELinux-enabled systems (RHEL, Fedora, CentOS) to prevent false positives and service denials.


πŸ”₯ 3. ufw – Uncomplicated Firewall (Debian-based)

βœ… What is ufw?

ufw is a simplified firewall frontend for iptables, ideal for Ubuntu/Debian systems. It helps you allow/deny traffic with a human-readable syntax.

πŸ“¦ Install:

sudo apt install ufw

πŸ”Ή Common ufw Commands:

CommandDescription
sudo ufw enableEnable the firewall
sudo ufw allow 22Allow SSH
sudo ufw deny 80Deny HTTP
sudo ufw allow 443/tcpAllow HTTPS TCP
sudo ufw statusShow current rules

πŸ§ͺ Example:

sudo ufw allow from 192.168.1.10 to any port 22

βœ… Allows only a specific IP to SSH into the system.


πŸ”₯ 4. firewalld – Dynamic Firewall Manager (RHEL/Fedora)

βœ… What is firewalld?

firewalld is a zone-based firewall daemon using iptables/nftables, ideal for RHEL, CentOS, Fedora, and supports dynamic changes without restarting services.

πŸ“¦ Install:

sudo yum install firewalld

Start and enable:

sudo systemctl enable --now firewalld

πŸ”Ή Common firewalld Commands:

CommandDescription
firewall-cmd --stateCheck if firewalld is running
firewall-cmd --add-port=80/tcp --permanentOpen port 80 permanently
firewall-cmd --reloadApply permanent changes
firewall-cmd --list-allShow current zone settings

πŸ§ͺ Example:

sudo firewall-cmd --zone=public --add-service=ssh --permanent
sudo firewall-cmd --reload

βœ… Adds SSH to the public zone.


🧠 Tool Comparison Table

ToolUse CasePlatformPersistent?Access Level
chattrLocking/immutability of filesAll Linuxβœ… YesRoot only
semanageSELinux policy managementRHEL/Fedoraβœ… YesRoot
ufwBasic firewall configurationUbuntu/Debianβœ… YesSudo/root
firewalldZone-based firewall managementRHEL/Fedoraβœ… YesRoot

πŸ“Œ Summary – Recap & Next Steps

Security is a layered practice. With chattr, you can prevent tampering. With semanage, SELinux security contexts are managed properly. With ufw and firewalld, you’re able to filter and control traffic effortlessly.

πŸ” Key Takeaways:

  • Use chattr +i to protect critical files from deletion.
  • Use semanage to whitelist custom ports in SELinux.
  • Use ufw or firewalld for user-friendly firewall control.
  • Always test configurations to ensure access is not unintentionally blocked.

❓ FAQs

❓ What happens if I make /etc/passwd immutable?
⚠️ System won’t be able to modify it. Avoid using chattr +i on critical system files unless absolutely needed.

❓ Can I use both ufw and firewalld together?
❌ No. They both manage iptables/nftables. Use only one firewall tool at a time.

❓ What if semanage isn’t found?
βœ… Install it via:

sudo yum install policycoreutils-python-utils

❓ Is ufw secure enough for production?
βœ… Yes, for most standard firewall configurations. For complex needs, consider iptables or nftables directly.

❓ How do I reset ufw to default settings?
βœ… Run:

sudo ufw reset

Share Now :

Leave a Reply

Your email address will not be published. Required fields are marked *

Share

πŸ”΅ Linux/Unix: Basic Security Tools (chattr, semanage, ufw, firewalld)

Or Copy Link

CONTENTS
Scroll to Top