私はこれをいくつかの異なる方法で試しました。現在、freebsd8.2でpfを試しています
トラフィックを外部IPアドレスからすべてのポートの内部IPアドレスにリダイレクトする既存のネットワークにNATソリューションを挿入しようとしていますが(静的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に戻る途中で失われます。
したがって、フローは次のようになります。
- 外部ホストtelnet10.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に返送され、ソースaddyがこの場合は10.0.0.1であったものに変換されます。
私はこれがでできると考え続けています
binatとrdrですが、構文がわかりません。
どうすればこれを行うことができますか?
承認された回答:
私はこれを達成するために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.