大网数据广告活动
服务器运维问答

iptables NAT is Policy Accept a security hole?

· 52CE 我爱测

im hardening my vps-server and and I saw recently that all policies are open ( ACCEPT ) at Nat Table. Im searching internet and found nothing about securing nat table. Is that a security hole or not ? Here the OUTPUT: Chain PRERO…

问题原文

原帖链接 · beard black · CC BY-SA 4.0

im hardening my vps-server and and I saw recently that all policies are open (ACCEPT) at Nat Table. Im searching internet and found nothing about securing nat table. Is that a security hole or not ? Here the OUTPUT:

Chain PREROUTING (policy ACCEPT 21038 packets, 1097K bytes)
 pkts bytes target     prot opt in     out     source               destination                                                 

Chain INPUT (policy ACCEPT 9 packets, 1088 bytes)
 pkts bytes target     prot opt in     out     source               destination                                                 

Chain OUTPUT (policy ACCEPT 187 packets, 14396 bytes)
 pkts bytes target     prot opt in     out     source               destination                                                 

Chain POSTROUTING (policy ACCEPT 48 packets, 3767 bytes)
 pkts bytes target     prot opt in     out     source               destination                                                 
  523  140K MASQUERADE  all  --  *      eth0    0.0.0.0/0            0.0.0.0/0   

For every help im thanksfull

kind regards blackbeard

已采纳解答

原帖链接 · A.B · CC BY-SA 4.0

No this is perfectly fine to use an ACCEPT policy for the nat table. Using a DROP policy would be an anomaly.

A packet traverses various chains in various tables following this schematic:

Being accepted, just means the packet gets an other chance of being accepted or dropped in the next round (ie: the next chain and its rules to receive this packet). Being dropped has an instant effect: the packet disappears and no other rule is processed for this packet. So as the packet traverses the various chains in the various tables, there's plenty of places it can be dropped. One DROP anywhere will remove the packet. An additional ACCEPT (eg: if NAT is never used, there's no nat table created) will not change this result.

As the nat table is intended to do NAT and not to filter traffic (for this there's a dedicated table: filter), there's no reason to have NAT ever drop traffic. It's still technically possible to do it, but anyway you have also to consider that NAT is not handled like other tables because it is really part of conntrack: only the first packet of each new flow are seen in iptables' nat table, in order to establish NAT rules for the flow. Others won't, their handling is done directly by conntrack which follows the NAT rules (included in the relevant conntrack table that can be consulted with the conntrack command).

So in short, you should never DROP in the nat table: you should ACCEPT or RETURN to create exceptions to following rules actually doing NAT (thus leaving the packet untouched so it will continue to the next round), or use the various NAT targets available (eg: DNAT, REDIRECT, SNAT, MASQUERADE ...) to establish the NAT rules for this flow (which will also have the packet continue to the next round). Leave the DROP default policy to chains in the filter table. The mangle table can also be used to drop traffic, but it's usually not configured with a default DROP policy either for its chains. As for the little known security table I wouldn't know, it's rarely used, so rarely existing.

摘自公开归档,保留原文语言,版式经整理,外部媒体与邮箱地址已移除。

资料来源与适用范围

资料来源
Server Fault
适用范围
以原帖系统、软件版本与发布日期为准(2020-08-21)
内容语言
中文;命令、路径和错误标识保留技术原文
本地收录日期
2026-11-15
授权说明
CC BY-SA 4.0

正文与所需资源由本站本地存储。查看来源及更新记录 ↗

请按适用版本和实际日志确认原因;本站没有对每一种系统或设备逐项执行文中的操作。