• iptables防火墙配置


    • 更改 Firewall 为 iptables
    rpm -q firewalld
    rpm -e --nodeps firewalld
    yum -y install iptables-services
    systemctl start iptables
    systemctl enable iptables
    
    • 备份原有规则
    # 复制文件
    [ -f /etc/sysconfig/iptables ]&& /usr/bin/cp /etc/sysconfig/iptables{,.bak-`date +%Y%m%d%H%M%S`}
    # 命令导出
    iptables-save > /tmp/iptables.bak-`date +%Y%m%d%H%M%S`
    
    • 删除已有规则
    iptables --delete-chain
    iptables --flush
    
    • 禁止进,禁止出,允许回环网卡
    iptables -P INPUT DROP   
    iptables -P FORWARD DROP 
    iptables -P OUTPUT DROP
    iptables -A INPUT -i lo -j ACCEPT
    iptables -A OUTPUT -o lo -j ACCEPT
    
    • 允许已建立的或相关连接的通行,即允许我发出去的数据包入站
    iptables -A INPUT -p tcp -m state --state ESTABLISHED,RELATED -j ACCEPT
    iptables -A INPUT -p udp -m state --state ESTABLISHED,RELATED -j ACCEPT
    iptables -A OUTPUT -p tcp -m state --state ESTABLISHED,RELATED -j ACCEPT
    iptables -A OUTPUT -p udp -m state --state ESTABLISHED,RELATED -j ACCEPT
    
    • 限制80端口单个IP的最大连接数为10
    iptables -I INPUT -p tcp --dport 80 -m connlimit --connlimit-above 10 -j DROP
    
    • 允许80(HTTP)/873(RSYNC)/443(HTTPS)/20,21(FTP)/25(SMTP)端口的连接
    iptables -A INPUT -p tcp -m tcp --dport 80 -j ACCEPT
    iptables -A INPUT -p tcp -m tcp --dport 873 -j ACCEPT
    iptables -A INPUT -p tcp -m tcp --dport 443 -j ACCEPT
    iptables -A INPUT -p tcp -m tcp --dport 20 -j ACCEPT
    iptables -A INPUT -p tcp -m tcp --dport 21 -j ACCEPT
    iptables -A INPUT -p tcp -m tcp --dport 25 -j ACCEPT
    
    • 允许SSH端口的连接,脚本自动侦测目前的SSH端口,否则默认为22端口
    if grep "^Port" /etc/ssh/sshd_config>/dev/null;then
    	sshdport=`grep "^Port" /etc/ssh/sshd_config | sed "s/Ports//g" `
    else
    	sshdport=22
    fi
    iptables -t filter -A INPUT -p tcp -m tcp --dport $sshdport -j ACCEPT
    
    • 允许ping和被ping
    iptables -t filter -A INPUT 1 -p icmp --icmp-type 8 -m limit --limit 4/minute --limit-burst 6 -j ACCEPT
    iptables -t filter -A OUTPUT -p icmp -m icmp --icmp-type 8 -j ACCEPT
    
    • 允许机器可以进行DNS查询
    iptables -t filter -A OUTPUT -p udp -m udp -j ACCEPT
    

    站内链接


    作者:Outsrkem
    出处:https://www.cnblogs.com/outsrkem/
    本文版权归作者和博客园共有,欢迎转载,但未经作者同意必须保留此段声明,且在文章页面明显位置给出原文连接,否则保留追究法律责任的权利。

  • 相关阅读:
    C#异常断电后重新启动项目出现配置未初始化错误
    TFS: 解决The build agent error
    删除TFS中的项目
    将现有项目添加到TFS中
    Typora开启行内公式
    Markdown上下标内容多于一项
    小甲鱼python基础教程飞机大战源码及素材
    Git 将本地库添加到远程仓库
    C# float与UInt16互转
    C++的重载流输出运算符
  • 原文地址:https://www.cnblogs.com/outsrkem/p/11175533.html
Copyright © 2020-2023  润新知