iptables 用法

iptables用于设置、维护和检查Linux内核中IP包过滤规则的表。

# 目标(targets)
防火墙规则指定数据包的标准和目标。
(1)ACCEPT:意味着让数据包(packets)通过
(2)DROP:意味着数据包在这一层丢掉
(3)QUEUE:意味着将包传送到用户层
(4)RETURN:意味着停止遍历此链,并在前一个调用链的下一条规则中恢复。

# 表(tables)
目前有三个独立的表,哪个表在什么时候出现依赖于内核配置和哪个模块被加载。
-t table :如果内核配置了自动加载模块,但不在该表中,则尝试加载相应的模块。
(1)filter是默认的表,包含三个内建的chains:
INPUT(对于指定到本地套接字的包)
FORWARD(对于通过盒子路由的包)
OUTPUT(对于本地产生的数据包)
(2)nat 遇到创建新连接的数据包时,请查阅此表。包含三个内建的chains:
PREROUTING(改变包当它们一进入)
OUTPUT(改变本地产生的包在routing之前)
POSTROUTING(改变包当它们出去的时候)
(3)mangle此表专门用于数据包的更改
2.4.18以后的版本,
INPUT(对于进入盒子本身的包)
FORWARD(用于改变通过盒子路由的包)
POSTROUTING(用于改变数据包在它们出去的时候)
2.4.17以及之前版本,
PREROUTING(用于改变在routing之前进入的包)
OUTPUT(用于改变本地产生的包在routing之前)
(4)raw
This table is used mainly for configuring exemptions from connection tracking in combination with the NOTRACK target. It registers at the netfilter hooks with higher priority and is thus called before ip_conntrack, or any other IP tables. It provides the following built-in chains: PREROUTING (for packets arriving via any network interface) OUTPUT (for packets generated by local processes)


iptables [-t table] -[AD] chain rule-specification [options]             // append, delete
iptables [-t table] -I chain [rulenum] rule-specification [options]  // insert
iptables [-t table] -R chain rulenum rule-specification [options]    // replace
iptables [-t table] -D chain rulenum [options]                              // Delete one or more rules from the selected chain
iptables [-t table] -[LFZ] [chain] [options]                                   // list, flush, zero
        iptables -t nat -n -L          // -n Numeric output. IP addresses and port numbers will be printed in numeric format.
        iptables -L -v                  // -v Verbose output. This option makes the list command show the interface name, the rule options (if any), and the TOS masks.
iptables [-t table] -N chain                                                         // Create a new user-defined chain by the given name.
iptables [-t table] -X [chain]                                                      // Delete the optional user-defined chain specified.
iptables [-t table] -P chain target [options]                                // Set the policy for the chain to the given target.
iptables [-t table] -E old-chain-name new-chain-name               // Rename the user specified chain to the user supplied name.

参考文献

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值