tenho aqui um firewall que redireciona as conexões para uma maquina da rede interna, coloquei todas as regras de DNAT, mas não funciona, so funciona se mascarar o ip da maquina
segue o script abaixo:
#!/bin/sh
# Variáveis
# -------------------------------------------------------
iptables=/usr/local/sbin/iptables
IF_EXTERNA=eth1
IF_INTERNA=eth0
IF_MCV=eth2
# Ativa módulos
# -------------------------------------------------------
/sbin/modprobe iptable_nat
/sbin/modprobe ip_conntrack
/sbin/modprobe ip_conntrack_ftp
/sbin/modprobe ip_nat_ftp
/sbin/modprobe ipt_LOG
/sbin/modprobe ipt_REJECT
/sbin/modprobe ipt_MASQUERADE
# Ativa roteamento no kernel
# -------------------------------------------------------
echo "1" > /proc/sys/net/ipv4/ip_forward
# Proteção contra IP spoofing
# -------------------------------------------------------
echo "1" > /proc/sys/net/ipv4/conf/all/rp_filter
# Zera regras
# -------------------------------------------------------
$iptables -F
$iptables -X
$iptables -F -t nat
$iptables -X -t nat
$iptables -F -t mangle
$iptables -X -t mangle
# Determina a política padrão
# -------------------------------------------------------
$iptables -P INPUT DROP
$iptables -P OUTPUT DROP
$iptables -P FORWARD DROP
#################################################
# Tabela FILTER
#################################################
# Dropa pacotes TCP indesejáveis
# -------------------------------------------------------
$iptables -A FORWARD -p tcp ! --syn -m state --state NEW -j LOG --log-level 6 --log-prefix "FIREWALL: NEW sem syn: "
$iptables -A FORWARD -p tcp ! --syn -m state --state NEW -j DROP
# Dropa pacotes mal formados
# -------------------------------------------------------
$iptables -A INPUT -i $IF_EXTERNA -m unclean -j LOG --log-level 6 --log-prefix "FIREWALL: pacote mal formado: "
$iptables -A INPUT -i $IF_EXTERNA -m unclean -j DROP
# Aceita os pacotes que realmente devem entrar
# -------------------------------------------------------
$iptables -A INPUT -i ! $IF_EXTERNA -j ACCEPT
$iptables -A INPUT -m state --state ESTABLISHED,RELATED -j ACCEPT
$iptables -A OUTPUT -m state --state ESTABLISHED,RELATED,NEW -j ACCEPT
$iptables -A FORWARD -m state --state ESTABLISHED,RELATED,NEW -j ACCEPT
# Proteção contra tronjans
# -------------------------------------------------------
$iptables -N TROJAN
$iptables -A TROJAN -m limit --limit 15/m -j LOG --log-level 6 --log-prefix "FIREWALL: trojan: "
$iptables -A TROJAN -j DROP
$iptables -A INPUT -p TCP -i $IF_EXTERNA --dport 666 -j TROJAN
$iptables -A INPUT -p TCP -i $IF_EXTERNA --dport 666 -j TROJAN
$iptables -A INPUT -p TCP -i $IF_EXTERNA --dport 4000 -j TROJAN
$iptables -A INPUT -p TCP -i $IF_EXTERNA --dport 6000 -j TROJAN
$iptables -A INPUT -p TCP -i $IF_EXTERNA --dport 6006 -j TROJAN
$iptables -A INPUT -p TCP -i $IF_EXTERNA --dport 16660 -j TROJAN
# Proteção contra worms
# -------------------------------------------------------
$iptables -A FORWARD -p tcp --dport 135 -i $IF_INTERNA -j REJECT
$iptables -A FORWARD -p tcp --dport 135 -i $IF_MCV -j REJECT
# Proteção contra syn-flood
# -------------------------------------------------------
$iptables -A FORWARD -p tcp --syn -m limit --limit 2/s -j ACCEPT
# Proteção contra ping da morte
# -------------------------------------------------------
$iptables -A FORWARD -p icmp --icmp-type echo-request -m limit --limit 1/s -j ACCEPT
# Proteção contra port scanners
# -------------------------------------------------------
$iptables -N SCANNER
$iptables -A SCANNER -m limit --limit 15/m -j LOG --log-level 6 --log-prefix "FIREWALL: port scanner: "
$iptables -A SCANNER -j DROP
$iptables -A INPUT -p tcp --tcp-flags ALL FIN,URG,PSH -i $IF_EXTERNA -j SCANNER
$iptables -A INPUT -p tcp --tcp-flags ALL NONE -i $IF_EXTERNA -j SCANNER
$iptables -A INPUT -p tcp --tcp-flags ALL ALL -i $IF_EXTERNA -j SCANNER
$iptables -A INPUT -p tcp --tcp-flags ALL FIN,SYN -i $IF_EXTERNA -j SCANNER
$iptables -A INPUT -p tcp --tcp-flags ALL SYN,RST,ACK,FIN,URG -i $IF_EXTERNA -j SCANNER
$iptables -A INPUT -p tcp --tcp-flags SYN,RST SYN,RST -i $IF_EXTERNA -j SCANNER
$iptables -A INPUT -p tcp --tcp-flags SYN,FIN SYN,FIN -i $IF_EXTERNA -j SCANNER
$iptables -A INPUT -p icmp -d 200.x.x.x -j DROP
# Libera acesso externo a determinadas portas
# -------------------------------------------------------
$iptables -A INPUT -p tcp --dport 9900 -i $IF_EXTERNA -j ACCEPT
$iptables -A INPUT -p tcp --dport 9900 -i $IF_INTERNA -j ACCEPT
$iptables -A INPUT -p tcp --dport 9900 -i $IF_MCV -j ACCEPT
$iptables -A INPUT -p tcp --dport 80 -i $IF_INTERNA -j ACCEPT
$iptables -A INPUT -p tcp --dport 80 -i $IF_EXTERNA -j ACCEPT
$iptables -A INPUT -p tcp --dport 80 -i $IF_MCV -j ACCEPT
$iptables -A INPUT -p tcp --dport 9023 -i $IF_EXTERNA -j ACCEPT
$iptables -A INPUT -p tcp --dport 9023 -i $IF_INTERNA -j ACCEPT
$iptables -A INPUT -p tcp --dport 9023 -i $IF_MCV -j ACCEPT
$iptables -A INPUT -p tcp --dport 53 -i $IF_INTERNA -j ACCEPT
$iptables -A INPUT -p tcp --dport 53 -i $IF_EXTERNA -j ACCEPT
$iptables -A INPUT -p tcp --dport 53 -i $IF_MCV -j ACCEPT
$iptables -A INPUT -p tcp --dport 3497 -i $IF_INTERNA -j ACCEPT
$iptables -A INPUT -p tcp --dport 3497 -i $IF_EXTERNA -j ACCEPT
$iptables -A INPUT -p tcp --dport 3497 -i $IF_MCV -j ACCEPT
$iptables -A INPUT -p tcp --dport 443 -i $IF_INTERNA -j ACCEPT
$iptables -A INPUT -p tcp --dport 443 -i $IF_EXTERNA -j ACCEPT
$iptables -A INPUT -p tcp --dport 443 -i $IF_MCV -j ACCEPT
$iptables -A INPUT -p tcp --dport 25 -i $IF_MCV -j ACCEPT
$iptables -A OUTPUT -p tcp --sport 25 -o $IF_MCV -j ACCEPT
$iptables -A INPUT -p tcp --dport 110 -i $IF_MCV -j ACCEPT
$iptables -A OUTPUT -p tcp --sport 110 -o $IF_MCV -j ACCEPT
$iptables -A INPUT -p tcp --dport 9999 -i $IF_MCV -j ACCEPT
$iptables -A OUTPUT -p tcp --sport 9999 -o $IF_MCV -j ACCEPT
$iptables -A INPUT -p tcp --dport 9999 -i $IF_EXTERNA -j ACCEPT
$iptables -A OUTPUT -p tcp --sport 9999 -o $IF_INTERNA -j ACCEPT
$iptables -A INPUT -p tcp --dport 9999 -i $IF_MCV -j ACCEPT
$iptables -A OUTPUT -p tcp --sport 9999 -o $IF_MCV -j ACCEPT
#################################################
# Tabela NAT
#################################################
# Ativa mascaramento de saída
# -------------------------------------------------------
$iptables -A FORWARD -s 15.100.0.2 -j ACCEPT
$iptables -A FORWARD -d 15.100.0.2 -j ACCEPT
$iptables -t nat -A POSTROUTING -s 15.100.0.2 -j SNAT --to 201.x.x.x
#$iptables -t nat -A POSTROUTING -d 15.100.0.2 -j MASQUERADE (O REDIRECIONAMENTO SO FUNCIONA COM ESSA REGRA)
$iptables -A FORWARD -s 10.85.8.160 -j ACCEPT
$iptables -A FORWARD -d 10.85.8.160 -j ACCEPT
$iptables -A POSTROUTING -t nat -s 10.85.8.160 -j MASQUERADE
$iptables -A POSTROUTING -t nat -d 10.85.8.160 -j MASQUERADE
# Redireciona portas para outros servidores
# -------------------------------------------------------
$iptables -t nat -A PREROUTING -p tcp -d 201.x.x.x --dport 80 -j DNAT --to-destination 15.100.0.2:80
$iptables -t nat -A PREROUTING -p udp -d 201.x.x.x --dport 80 -j DNAT --to-destination 15.100.0.2:80
#$iptables -t nat -A PREROUTING -p tcp -d 10.85.8.7 --dport 80 -j DNAT --to-destination 15.100.0.2:80
#$iptables -t nat -A PREROUTING -p udp -d 10.85.8.7 --dport 80 -j DNAT --to-destination 15.100.0.2:80
$iptables -t nat -A PREROUTING -p tcp -d 201.x.x.x --dport 443 -j DNAT --to-destination 15.100.0.2:443
$iptables -t nat -A PREROUTING -p udp -d 201.x.x.x --dport 443 -j DNAT --to-destination 15.100.0.2:443
$iptables -t nat -A PREROUTING -p tcp -d 10.85.8.7 --dport 443 -j DNAT --to-destination 15.100.0.2:443
$iptables -t nat -A PREROUTING -p udp -d 10.85.8.7 --dport 443 -j DNAT --to-destination 15.100.0.2:443
$iptables -t nat -A PREROUTING -p tcp -d 201.x.x.x --dport 9999 -j DNAT --to-destination 15.100.0.2:9999
$iptables -t nat -A PREROUTING -p udp -d 201.x.x.x --dport 9999 -j DNAT --to-destination 15.100.0.2:9999
$iptables -t nat -A PREROUTING -p tcp -d 10.85.8.7 --dport 9999 -j DNAT --to-destination 15.100.0.2:9999
$iptables -t nat -A PREROUTING -p udp -d 10.85.8.7 --dport 9999 -j DNAT --to-destination 15.100.0.2:9999
$iptables -t nat -A PREROUTING -p tcp -d 201.x.x.x --dport 9023 -j DNAT --to-destination 15.100.0.2:21
$iptables -t nat -A PREROUTING -p udp -d 201.x.x.x --dport 9023 -j DNAT --to-destination 15.100.0.2:21
$iptables -t nat -A PREROUTING -p tcp -d 10.85.8.7 --dport 9023 -j DNAT --to-destination 15.100.0.2:21
$iptables -t nat -A PREROUTING -p udp -d 10.85.8.7 --dport 9023 -j DNAT --to-destination 15.100.0.2:21
$iptables -t nat -A PREROUTING -p tcp -d 10.85.8.7 --dport 5800 -j DNAT --to-destination 15.100.0.2:5800
$iptables -t nat -A PREROUTING -p udp -d 10.85.8.7 --dport 5800 -j DNAT --to-destination 15.100.0.2:5800
$iptables -t nat -A PREROUTING -p tcp -d 10.85.8.7 --dport 5900 -j DNAT --to-destination 15.100.0.2:5900
$iptables -t nat -A PREROUTING -p udp -d 10.85.8.7 --dport 5900 -j DNAT --to-destination 15.100.0.2:5900
$iptables -t nat -A PREROUTING -p tcp -d 10.85.8.7 --dport 3497 -j DNAT --to-destination 15.100.0.2:3497
$iptables -t nat -A PREROUTING -p udp -d 10.85.8.7 --dport 3497 -j DNAT --to-destination 15.100.0.2:3497
$iptables -t nat -A PREROUTING -p tcp -s 10.85.8.57 -d 10.85.8.7 --dport 1501 -j DNAT --to-destination 15.100.0.2:1501
$iptables -t nat -A PREROUTING -p udp -s 10.85.8.57 -d 10.85.8.7 --dport 1501 -j DNAT --to-destination 15.100.0.2:1501
$iptables -t nat -A PREROUTING -p tcp -s 10.85.8.94 -d 10.85.8.7 --dport 1501 -j DNAT --to-destination 15.100.0.2:1501
$iptables -t nat -A PREROUTING -p udp -s 10.85.8.94 -d 10.85.8.7 --dport 1501 -j DNAT --to-destination 15.100.0.2:1501
O PROBLEMA ESTA POR QUE TENHO UM SOFTWARE QUE PRECISA MOSTRAR O IP DE QUEM ESTA ACESSANDO, E QUANDO ESTA MASCARADO SO MOSTRA O IP DO FIREWALL, PEÇO A AJUDA DE VOÇES.