我有一个在 debian 7 上运行的 Web 服务并监听端口 8080。我想将 80 重定向到 8080 以进行入站连接并只允许端口 80。这是我的iptables
配置:
root@localhost:~# iptables -v -L --line-numbers
Chain INPUT (policy DROP 76 packets, 6266 bytes)
num pkts bytes target prot opt in out source destination
1 90 8898 ACCEPT all -- lo any anywhere anywhere
2 0 0 ACCEPT tcp -- any any anywhere anywhere tcp dpt:http
3 4515 3113K ACCEPT all -- any any anywhere anywhere state RELATED,ESTABLISHED
Chain FORWARD (policy ACCEPT 0 packets, 0 bytes)
num pkts bytes target prot opt in out source destination
Chain OUTPUT (policy ACCEPT 4858 packets, 587K bytes)
num pkts bytes target prot opt in out source destination
Run Code Online (Sandbox Code Playgroud)
和 nat 表:
root@localhost:~# iptables -L -n -v -t nat
Chain PREROUTING (policy ACCEPT 14 packets, 2288 bytes)
pkts bytes target prot opt in out source destination
0 0 REDIRECT tcp -- * * 0.0.0.0/0 0.0.0.0/0 tcp dpt:80 redir ports 8080
0 0 REDIRECT udp -- * * 0.0.0.0/0 0.0.0.0/0 udp dpt:80 redir ports 8080
Chain INPUT (policy ACCEPT 0 packets, 0 bytes)
pkts bytes target prot opt in out source destination
Chain OUTPUT (policy ACCEPT 841 packets, 53415 bytes)
pkts bytes target prot opt in out source destination
Chain POSTROUTING (policy ACCEPT 841 packets, 53415 bytes)
pkts bytes target prot opt in out source destination
Run Code Online (Sandbox Code Playgroud)
我无法在端口 80 上从外部建立连接。可能存在哪些不足?
当用户点击端口 80 时,iptables
首先检查NAT PREROUTING
表,然后检查FILTER
表,因此根据您的情况,您需要在过滤器输入链中允许端口 8080。
参见下面的示例:
在过滤器表中:
iptables -A INPUT -i eth0 -p tcp -m tcp --dport 8080 -m state --state NEW,ESTABLISHED -j ACCEPT
Run Code Online (Sandbox Code Playgroud)
在 Nat 表中:
iptables -t nat -A PREROUTING -p tcp -m tcp --dport 80 -j REDIRECT --to-ports 8080
Run Code Online (Sandbox Code Playgroud)
上述规则已使用 Filter INPUT Policy Drop 进行了测试,并且有效。
表的顺序如下:
欲了解更多详情,请查看此页面。
归档时间: |
|
查看次数: |
9417 次 |
最近记录: |