溫馨提示×

Linux防火墻怎樣配置入侵檢測

小樊
40
2025-10-18 12:50:38
欄目: 網絡安全

在Linux系統中,配置入侵檢測通常涉及使用iptables、firewalld或更高級的工具如Snort或Suricata。以下是使用這些工具進行入侵檢測的基本步驟:

使用iptables進行基本的入侵檢測

  1. 更新iptables規則

    sudo iptables -F
    sudo iptables -X
    
  2. 設置默認策略

    sudo iptables -P INPUT DROP
    sudo iptables -P FORWARD DROP
    sudo iptables -P OUTPUT ACCEPT
    
  3. 允許必要的流量

    sudo iptables -A INPUT -i lo -j ACCEPT
    sudo iptables -A OUTPUT -o lo -j ACCEPT
    sudo iptables -A INPUT -m conntrack --ctstate ESTABLISHED,RELATED -j ACCEPT
    sudo iptables -A OUTPUT -m conntrack --ctstate ESTABLISHED,RELATED -j ACCEPT
    sudo iptables -A INPUT -p tcp --dport 22 -j ACCEPT  # SSH
    sudo iptables -A INPUT -p tcp --dport 80 -j ACCEPT  # HTTP
    sudo iptables -A INPUT -p tcp --dport 443 -j ACCEPT # HTTPS
    
  4. 添加入侵檢測規則

    sudo iptables -A INPUT -p tcp --dport 21 -j LOG --log-prefix "FTP attempt: "
    sudo iptables -A INPUT -p tcp --dport 23 -j LOG --log-prefix "Telnet attempt: "
    sudo iptables -A INPUT -p udp --dport 137:139 -j LOG --log-prefix "NetBIOS attempt: "
    sudo iptables -A INPUT -p tcp --dport 139 -j DROP
    sudo iptables -A INPUT -p tcp --dport 445 -j DROP
    
  5. 保存iptables規則

    sudo iptables-save > /etc/iptables/rules.v4
    

使用firewalld進行基本的入侵檢測

  1. 安裝firewalld

    sudo yum install firewalld
    sudo systemctl start firewalld
    sudo systemctl enable firewalld
    
  2. 設置默認區域

    sudo firewall-cmd --set-default-zone=public
    
  3. 允許必要的流量

    sudo firewall-cmd --permanent --zone=public --add-service=http
    sudo firewall-cmd --permanent --zone=public --add-service=https
    sudo firewall-cmd --permanent --zone=public --add-service=ssh
    sudo firewall-cmd --reload
    
  4. 添加入侵檢測規則

    sudo firewall-cmd --permanent --direct --add-rule ipv4 filter INPUT 0 -p tcp --dport 21 -j LOG --log-prefix "FTP attempt: "
    sudo firewall-cmd --permanent --direct --add-rule ipv4 filter INPUT 0 -p tcp --dport 23 -j LOG --log-prefix "Telnet attempt: "
    sudo firewall-cmd --permanent --direct --add-rule ipv4 filter INPUT 0 -p udp --dport 137:139 -j LOG --log-prefix "NetBIOS attempt: "
    sudo firewall-cmd --permanent --direct --add-rule ipv4 filter INPUT 0 -p tcp --dport 139 -j DROP
    sudo firewall-cmd --permanent --direct --add-rule ipv4 filter INPUT 0 -p tcp --dport 445 -j DROP
    sudo firewall-cmd --reload
    

使用Snort進行高級入侵檢測

  1. 安裝Snort

    sudo yum install snort
    
  2. 配置Snort: 編輯/etc/snort/snort.conf文件,配置規則和其他選項。

  3. 啟動Snort

    sudo systemctl start snort
    sudo systemctl enable snort
    
  4. 查看Snort日志

    sudo tail -f /var/log/snort/alert
    

使用Suricata進行高級入侵檢測

  1. 安裝Suricata

    sudo yum install suricata
    
  2. 配置Suricata: 編輯/etc/suricata/suricata.yaml文件,配置規則和其他選項。

  3. 啟動Suricata

    sudo systemctl start suricata
    sudo systemctl enable suricata
    
  4. 查看Suricata日志

    sudo tail -f /var/log/suricata/fast.log
    

通過以上步驟,你可以在Linux系統中配置基本的入侵檢測。根據具體需求,你可以選擇合適的工具并進行更詳細的配置。

0
亚洲午夜精品一区二区_中文无码日韩欧免_久久香蕉精品视频_欧美主播一区二区三区美女