L'ho provato in diversi modi. Attualmente sto provando con pf su freebsd 8.2
Sto cercando di inserire una soluzione nat in una rete esistente che reindirizzerà il traffico da un indirizzo IP esterno a un indirizzo IP interno su tutte le porte (nat statico), ma voglio anche tradurre l'indirizzo di origine.
Rete attuale.
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
Voglio che outsidehost sia in grado di telnet a 192.168.1.3 da telneting(sp) a 10.0.0.2
Affinché funzioni, presumo che dovrò cambiare l'origine del pacchetto poiché lascia em0 o si perderà sulla via del ritorno a em1.
Quindi il flusso va così:
- da host esterno telnet 10.0.0.2
- modifica l'indirizzo di origine in 192.168.1.4
- Reindirizza il traffico da 10.0.0.2 a 192.168.1.2
- il pacchetto parte con src 192.168.1.4 va a 192.168.1.2 quindi viene rispedito a 192.168.1.4 si traduce in qualunque fosse l'addy di origine in questo caso 10.0.0.1
Continuo a pensare che si possa fare con
binat e rdr ma non riesco a capire la sintassi.
Come posso farlo?
Risposta accettata:
Ho finito per utilizzare iptables sotto Linux per ottenere questo risultato.
Per, l'inoltro IP deve essere attivato:
echo net.ipv4.ip_forward=1 >> /etc/sysctl.conf
E imposta le seguenti regole:
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.