linux

Linux dropped安全策略

小樊
36
2025-10-13 12:57:22
栏目: 智能运维

Linux Dropped Security Strategy: Core Concepts and Implementation
Dropped security is a fundamental principle in Linux firewall configurations where the default action for unrecognized or unauthorized network traffic is to silently discard it (using the DROP target). This approach minimizes the attack surface by ensuring that only explicitly allowed traffic can reach the system, contrasting with the more permissive ACCEPT default policy. Below is a structured guide to implementing and managing dropped security strategies using iptables and nftables.

1. Why Use DROP as the Default Policy?

The primary advantage of DROP over REJECT is stealth: when a packet is dropped, the sender receives no response (e.g., TCP RST or ICMP unreachable), forcing attackers to wait for a timeout. This makes it harder for them to identify live hosts or scan for open ports. For example, a port scan against a server with DROP will show all ports as “filtered,” while REJECT reveals which ports are closed.

2. Basic Implementation with iptables

Set Default Policies to DROP

The first step is to configure the default policies for the INPUT, FORWARD, and OUTPUT chains. A common secure setup is:

sudo iptables -P INPUT DROP
sudo iptables -P FORWARD DROP
sudo iptables -P OUTPUT ACCEPT

Allow Essential Traffic

Even with a DROP default, you must permit critical traffic to maintain system functionality:

Log Dropped Packets (Optional but Recommended)

Logging helps troubleshoot connectivity issues and monitor potential attacks. Use the LOG target to record dropped packets, with rate limiting to prevent log flooding:

sudo iptables -A INPUT -j LOG --log-prefix "IPTables-Dropped: " --log-level 4
sudo iptables -A INPUT -j DROP

Logs are stored in /var/log/syslog (Debian/Ubuntu) or /var/log/messages (RHEL/CentOS) and can be viewed with:

sudo tail -f /var/log/syslog | grep "IPTables-Dropped"

3. Advanced Dropped Security Techniques

Rate Limiting and Flood Protection

Prevent brute-force attacks (e.g., SSH) or denial-of-service (DoS) by limiting the number of connections from a single IP address. For example, allow a maximum of 10 new SSH connections per minute from any IP:

sudo iptables -A INPUT -p tcp --dport 22 -m state --state NEW -m recent --set
sudo iptables -A INPUT -p tcp --dport 22 -m state --state NEW -m recent --update --seconds 60 --hitcount 10 -j DROP

Port Knocking

Hide open ports from scanners by requiring a specific sequence of connection attempts (e.g., ports 1000, 2000, 3000) before opening a service (e.g., SSH). Tools like knockd automate this process.

Custom Chains

Organize complex rules by creating custom chains (e.g., LOGGING) to handle dropped traffic separately. This improves readability and maintainability:

sudo iptables -N LOGGING
sudo iptables -A INPUT -j LOGGING
sudo iptables -A LOGGING -m limit --limit 2/min -j LOG --log-prefix "Input-Dropped: "
sudo iptables -A LOGGING -j DROP

4. Migrating to nftables (Modern Alternative)

nftables is the successor to iptables, offering a unified syntax and better performance. Here’s how to implement a dropped security strategy with nftables:

5. Best Practices for Dropped Security

By implementing these strategies, you can create a robust dropped security policy that protects your Linux system from unauthorized access while minimizing exposure to attacks.

0
看了该问题的人还看了