zoukankan      html  css  js  c++  java
  • iptables集锦--涉及nat等等

    1、-i 输入接口
    -i 代表输入接口,-i 指定了要处理来自哪个接口的数据包,这些包即将进入 INPUT,FORWARD,PREROUTE 链。

    比如 -i eth0 指定了要处理通过 eth0 进入的数据包,如果不指定 -i 参数那么将处理所有接口的数据包。

    ! -i eth0 处理所有经由 eth0 以外的接口进入的数据包
    -i eth+ 将处理所有经由 eth 开头的接口进入的数据包
    也可以使用 --in-interface

    参考:http://einverne.github.io/post/2017/01/iptables.html

    2、mangle的使用
    填坑

    3、在proxmox的nat中有指令(注意fwbrxx是指哪些接口???????)
    In some masquerade setups with firewall enabled, conntrack zones might be needed for outgoing connections. Otherwise the firewall could block outgoing connections since they will prefer the POSTROUTING of the VM bridge (and not MASQUERADE).
    post-up iptables -t raw -I PREROUTING -i fwbr+ -j CT --zone 1
    post-down iptables -t raw -D PREROUTING -i fwbr+ -j CT --zone 1

    CT 说明
    The CT target allows to set parameters for a packet or its associatedconnection. The target attaches a "template" connection tracking entry tothe packet, which is then used by the conntrack core when initializinga new ct entry. This target is thus only valid in the "raw" table.
    --notrack
    Disables connection tracking for this packet.
    --helper name
    Use the helper identified by name for the connection. This is moreflexible than loading the conntrack helper modules with preset ports.
    --ctevents event[ ,...]
    Only generate the specified conntrack events for this connection. Possibleevent types are: new, related, destroy, reply, assured, protoinfo, helper, mark (this refers tothe ctmark, not nfmark), natseqinfo, secmark (ctsecmark).
    --expevents event[ ,...]
    Only generate the specified expectation events for this connection.Possible event types are: new.
    --zone id
    Assign this packet to zone id and only have lookups done in that zone.By default, packets have zone 0.
    --timeout name
    Use the timeout policy identified by name for the connection. This isprovides more flexible timeout policy definition than global timeout valuesavailable at /proc/sys/net/netfilter/nf_conntrack_timeout.
    参考:iptables-extensions拓展模块 https://blog.csdn.net/lee244868149/article/details/46453943?utm_source=blogxgwz4

    4、iptables规则删除,有2种方法:
    1)先通过iptables -t filter -nvL --line-numbers列出某个规则的序号,然后通过序号删除iptables -t filter -D 2 这是删除2号规则

    2)iptables-save 列出规则,然后直接删除 iptables -t filter -D -p tcp -d 110.10.2.3 --dport 80 -j REDIRECT --to-ports 18006

    5、iptables规则的列出
    iptables --list (默认列出filter)比较慢,因为解析地址为域名了,如下:

    iptables -t nat -nv --list

    6、iptables的nat动作
    SNAT 为-j SNAT --to-source 或者简写为 -j SNAT --to 一般适合出接口是固定IP地址效率高,同时可以在-to-source中设定地址段(一般使用时在此处只有1个地址)
    DNAT 为-j DNAT --to-destination 或简写为 -j DNAT --to
    MASQUERADE 为-j MASQUERADE 一般结合-o 出接口使用,当然不使用-o选项也行
    REDIRECT 为-j REDIRECT --to-ports

    7、iptables 日志相关
    iptables -j LOG --log-prefix "nat log:" --log-level 0 日志默认等级应该是level 4
    可以在/var/log/message中查看到 当然也可以在rsyslog中设定将日志传输到其他的文件中。

    8、iptables调试相关
    需要经常iptables -Z(大写Z)来清空计数器,当然同时还需要有-j LOG打日志的操作

  • 相关阅读:
    Android-Universal-Image-Loader学习笔记(两)--LruDiscCache
    linux 多个源文件在编译时会产生一个目标文件
    springMVC 获取本地项目路径 及后整理上传文件的方法
    Cf 444C DZY Loves Colors(段树)
    什么是EF, 和 Entity Framework Demo简单构建一个良好的发展环境
    Mac下一个/usr/include失踪
    ArcGIS 10 破解安装(win7 64位)
    Android ProgressBar 反向进度条/进度条从右到左走
    Java的位运算符具体解释实例——与(&)、非(~)、或(|)、异或(^)
    poj 3273 Monthly Expense (二分)
  • 原文地址:https://www.cnblogs.com/weihua2020/p/13747492.html
Copyright © 2011-2022 走看看