iptables:阻止传入但允许传出

时间:2018-07-14 13:06:37

标签: block iptables

我使用ubuntu服务器为家庭网络供电。服务器通过 wan0 接口直接连接到互联网。在 Intranet 网站上,它使用网桥 br0 (将lan0和wlan0连接在一起)。

我使用 iptables 来阻止来自互联网的传入请求。 工作很好,可以阻止传入请求,但是我遇到的问题是,服务器本身(不是Intranet的客户端)是无法再连接到互联网(例如ping 9.9.9.9)。

使用的iptable规则如下:

*filter
# Global policies (drop the whole input)
:INPUT DROP [0:0]
:FORWARD ACCEPT [12:948]
:OUTPUT ACCEPT [52:5479]

# Allow loopback for device local communication
--append INPUT --in-interface lo --jump ACCEPT

# Allow all input from the intranet
--append INPUT --in-interface br0 --jump ACCEPT

# Allow ssh on port 22 from the wan
--append INPUT --in-interface wan0 --protocol tcp --dport 22 --match conntrack --ctstate NEW,ESTABLISHED --jump ACCEPT

# Allow ping from the wan
--append INPUT --in-interface wan0 --protocol icmp --icmp-type echo-request --jump ACCEPT
COMMIT

*nat
# Global policies
:PREROUTING ACCEPT [362:62516]
:INPUT ACCEPT [57:12612]
:OUTPUT ACCEPT [43:4250]
:POSTROUTING ACCEPT [31:2839]

# NAT traffic to the wan
--append POSTROUTING --out-interface wan0 --jump MASQUERADE

COMMIT

有人可以帮我找到问题还是必须添加哪些规则,以便服务器请求能够再次进入互联网?

0 个答案:

没有答案