iptables:リダイレクトされたポートのトラフィックを許可する方法

iptables:リダイレクトされたポートのトラフィックを許可する方法

Debian 7 で実行され、ポート 8080 でリッスンする Web サービスがあります。インバウンド接続を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     

そして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 

ポート 80 で外部接続を確立できません。どの欠陥が存在する可能性がありますか?

ベストアンサー1

ユーザーがポート80に達すると、iptables最初にNAT PREROUTINGテーブルを確認してからFILTERテーブルを確認するため、フィルタ入力チェーンでポート8080を許可する必要があります。

以下の例をご覧ください。

フィルタテーブルから:

iptables -A INPUT -i eth0 -p tcp -m tcp --dport 8080 -m state --state NEW,ESTABLISHED -j ACCEPT

Natテーブルから:

iptables -t nat -A PREROUTING -p tcp -m tcp --dport 80 -j REDIRECT --to-ports 8080

上記のルールは、Filter INPUT Policy Dropとタスクを使用してテストされました。

テーブルの順序は次のとおりです。

  1. マングル事前ルーティング
  2. 自然な事前ルーティング
  3. 管理入力
  4. フィルタ入力

詳しくはご確認くださいこれページ。

おすすめ記事