## Script hecho por el Ing. Carlos Eduardo Molina C.
## Comparte la conexion de internet desde unmodem 3G
## Comentarios, escribir a cemolina@redtauros.com
## http://www.redtauros.com/

#!/bin/bash
iptables --flush            
iptables --table nat --flush
iptables --delete-chain
iptables --table nat --delete-chain
  
echo 1 > /proc/sys/net/ipv4/ip_forward

internal=eth0
external=ppp0
/sbin/iptables -A FORWARD -i ${external} -o ${internal} -m state --state RELATED,ESTABLISHED -j ACCEPT
/sbin/iptables -A FORWARD -i ${internal} -o ${external} -j ACCEPT

# Enrutamiento al puerto 8081

/sbin/iptables -A FORWARD -s 192.168.1.10/24 -i eth0 -p tcp --dport 8081 -j ACCEPT
#/sbin/iptables -A FORWARD -i ppp0 -p tcp --dport 8081 -d 192.168.1.10 -j ACCEPT
#/sbin/iptables -A FORWARD -s 0.0.0.0/0 -d 192.168.1.10 -j LOG --log-prefix \
#"Regla FORWARD:"
#/sbin/iptables -A FORWARD -s 0.0.0.0/0 -d 192.168.1.10 -j ACCEPT

iptables -t nat -A PREROUTING -i ppp0 -p tcp --destination-port 8081 -j DNAT --to-destination 192.168.1.10:8081

#/sbin/iptables -t nat -A PREROUTING -p tcp -i ppp0 \
#--destination-port 8081 -j DNAT --to 192.168.1.10:8081

/sbin/iptables -t nat -A POSTROUTING -o ${external} -j MASQUERADE

#sbin/iptables -t nat -A PREROUTING -p udp -i ppp0 \
#-destination-port 8081 -j DNAT --to-destination 192.168.1.10:8081
