ゲートウェイではなくネットワークにnatソリューションを挿入する

ゲートウェイではなくネットワークにnatソリューションを挿入する

私はいくつかの異なるアプローチを試しました。私は現在freebsd 8.2でpfを使用しようとしています。

すべてのポート(静的NAT)で、外部IPアドレスからのトラフィックを内部IPアドレスにリダイレクトする既存のネットワークにnatソリューションを挿入しようとしていますが、ソースアドレスも変換したいと思います。

現在のネットワーク。

hosta
192.168.1.2/24 

gw
192.168.1.1/24

outsidehost
10.0.0.1/24 

natbox
em0 192.168.1.3/24 (used to manage the box)
em1 10.0.0.2/24 (outside address same lan as outsidehost)
em0_alias0 192.168.1.4/24 (inside address same lan as hosta)
route 192.168.1.0/24 192.168.1.1
route 0.0.0.0 0.0.0.0 10.0.0.1

外部ホストが10.0.0.2のtelneting(sp)を介して192.168.1.3にtelnetできることを願っています。

これを行うには、パケットがem0を離れるときにパケットの送信元を変更する必要があるとします。そうしないと、em1に戻る途中でパケットが失われます。

したがって、プロセスは次のようになります。

  • 外部ホストのTelnet 10.0.0.2
  • ソースアドレスを192.168.1.4に変更してください。
  • 10.0.0.2から192.168.1.2へのトラフィックリダイレクト
  • パケットは src 192.168.1.4 から出発して 192.168.1.2 に移動し、192.168.1.4 に戻ります。この場合、ソース追加値は10.0.0.1に戻ります。

私はいつもそれが可能だと思いました。

binatとrdrですが、構文を把握できません。

これをどのように実行できますか?

ベストアンサー1

私はこれを行うためにLinuxでiptablesを使用しました。

これを行うには、IP転送を有効にする必要があります。

echo net.ipv4.ip_forward=1 >> /etc/sysctl.conf

そして、次のルールを設定してください。

iptables -F -t nat
# flush the NAT Table.
iptables -t nat -P INPUT DROP
# set the input chain on the NAT table to DROP by default. 
# This way any traffic not allowed by defining a source address gets dropped.
# If you don't provide a -s address below it will allow all hosts from anywhere
# to reach the inside address via the outside ip. 

iptables -t nat -A PREROUTING -s 10.0.0.1 -d 10.0.0.2 \
         -j DNAT --destination-address 192.168.1.3 
# define the source and destination of the traffic allowed through.
# Change the dest address to our inside host. 

iptable -t nat -A INPUT -s 192.168.0.0/24 -J ALLOW
# Drop all traffic on sourcing from inside subnet. 
# This won't apply to traffic that matches the rule above
# as the source address will change in the next rule. 

iptables -t nat -A POSTROUTING -d 192.168.1.3 \
         -j SNAT --source-address 192.168.1.4
# here is the insert magic. Change the source address of any traffic destined
# for our inside host to our vip or owned inside address.
# This way the traffic is routed back to us at the FW. 

おすすめ記事