Introduction to Server Security: Fundamentals of Linux Firewalls

**Summary:** This article introduces Linux firewalls, which act as the "gatekeepers" of servers to restrict network access and primarily protect servers from attacks. The mainstream tools are categorized into three types: ufw (for Ubuntu/Debian, simple and based on iptables), firewalld (for CentOS/RHEL, supporting dynamic rules and zone management), and iptables (low-level, suitable for advanced users). In basic operations, ufw uses `enable` to turn on and `allow` to open ports; for firewalld, `--permanent` must be added to ensure rule persistence, and `reload` is required to apply changes. Common pitfalls for beginners include forgetting to add `--permanent` (resulting in temporary rule失效), setting the default policy to "deny inbound" for enhanced security, and only allowing specific IPs to access high-risk ports (e.g., 22). Conclusion: Firewalls are a security barrier; it is essential to clarify requirements, configure rules, ensure persistence, and conduct regular checks. (注:原文中“规则忘加`--permanent`会临时失效”中的“失效”翻译为“rule invalidation”更精准,已修正。) **Final Translation:** **Summary:** This article introduces Linux firewalls, which act as the "gatekeepers" of servers to restrict network access and primarily protect servers from attacks. The mainstream tools are categorized into three types: ufw (for Ubuntu/Debian, simple and based on iptables), firewalld (for CentOS/RHEL, supporting dynamic rules and zone management), and iptables (low-level, suitable for advanced users). In basic operations, ufw uses `enable` to turn on and `allow` to open ports; for firewalld, `--permanent` must be added to ensure rule persistence, and `reload` is required to apply changes. Common pitfalls for beginners include forgetting to add `--permanent` (resulting in temporary rule invalidation), setting the default policy to "deny inbound" for enhanced security, and only allowing specific IPs to access high-risk ports (e.g., 22). Conclusion: Firewalls are a security barrier; it is essential to clarify requirements, configure rules, ensure persistence, and conduct regular checks.

Read More
A Step-by-Step Guide to Configuring Linux Firewall (iptables)

This article introduces the configuration of Linux firewall (iptables) with the core objective of protecting server security. iptables is a packet filtering tool that manages traffic through tables (primarily filter), chains (INPUT/OUTPUT/FORWARD), and rules (match conditions + actions). Before configuration, existing rules should be checked (`iptables -L -n`) and cleared (`-F`/`-X`). Key steps include: allowing traffic on the local loopback interface (lo), setting default policies (DROP for inbound, ACCEPT for outbound), opening necessary ports (e.g., SSH, 80/443 for web services), and finally saving the rules (using `service iptables save` for CentOS and installing `iptables-persistent` for Ubuntu). Security considerations: prioritize rule order, apply the principle of least privilege, avoid directly exposing port 22 to the public internet, and regularly audit rules. Common operations include viewing, deleting, and clearing rules. By following these steps, a basic firewall can be quickly configured to meet the security needs of most servers.

Read More