美文网首页
465.【Unix/Linux 系统管理】iptables 防火

465.【Unix/Linux 系统管理】iptables 防火

作者: 七镜 | 来源:发表于2022-10-22 20:35 被阅读0次

    在将 iptables 作为防火墙使用之前,必须启用 IP 转发并确保各种 iptables 模块都已经载入内核。安装 iptables 的软件包通常都自带了能够满足这两项要求的启动脚本。

    Linux 防火墙通常作为一系列包含在 rc 启动脚本中的 iptables 命令来实现。单独的 iptables 命令多采用下来形式之一。

    • iptables -F chain-name
    • iptables -P chain-name target
    • iptables -A chain-name -i interface -j target

    第一种形式(-F)清除链中先前的所有规则。第二种形式(-P)设置链的默认策略(也称为目标)。我们推荐使用 DROP 作为默认的链目标。第三种形式(-A)将当前规则追加到链中。除非你使用 -t 选项指定了表,否则命令都应用于 filter 表中的链。-i 选项将规则应用于指定的 interface,-j 选项标识出 target。iptables 还能接受很多其他子句,如下所示:

    子句 含义或可能的值
    -p proto 依据协议匹配:tcp、udp、icmp
    -s source-ip 匹配主机或源 IP 地址
    -d dest-ip 匹配主机或目标 IP 地址
    --sport port# 依据源端口匹配(注意选项有两个连字符)
    --dport port# 依据目的端口匹配(注意选项有两个连字符)
    --icmp-type type 依据 ICMP 类型匹配(注意选项有两个连字符)
    ! 否定子句
    -t table 指定命令所应用的表

    相关文章

      网友评论

          本文标题:465.【Unix/Linux 系统管理】iptables 防火

          本文链接:https://www.haomeiwen.com/subject/visbzrtx.html