게이트웨이가 아닌 네트워크에 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로 돌아가는 도중에 패킷이 손실될 것입니다.

따라서 프로세스는 다음과 같습니다.

  • 외부 호스트의 텔넷 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. 

관련 정보