Source

woocode / sa-auto / sh / rc / iptables.sh

Full commit
#!/bin/bash

IPARRY=(
127.0.0.1
127.0.0.2
192.168.0.4
192.168.0.5
192.168.0.241
);

#192.168.0.5   9040-9049
#192.168.0.242 8020-8029

for LINE in ${IPARRY[*]}
do
    echo "set line[$LINE]"
    #HTTP
    /sbin/iptables -t nat -A OUTPUT -p tcp -d $LINE --dport 9040 -j REDIRECT --to-ports 8088
    /sbin/iptables -t nat -A PREROUTING -p tcp -d $LINE --dport 9040 -j REDIRECT --to-ports 8088

    /sbin/iptables -t nat -A OUTPUT -p tcp -d $LINE --dport 9041 -j REDIRECT --to-ports 8000
    /sbin/iptables -t nat -A PREROUTING -p tcp -d $LINE --dport 9041 -j REDIRECT --to-ports 8000

    /sbin/iptables -t nat -A OUTPUT -p tcp -d $LINE --dport 9042 -j REDIRECT --to-ports 22
    /sbin/iptables -t nat -A PREROUTING -p tcp -d $LINE --dport 9042 -j REDIRECT --to-ports 22

    /sbin/iptables -t nat -A OUTPUT -p tcp -d $LINE --dport 9043 -j REDIRECT --to-ports 8730
    /sbin/iptables -t nat -A PREROUTING -p tcp -d $LINE --dport 9043 -j REDIRECT --to-ports 8730

    /sbin/iptables -t nat -A OUTPUT -p tcp -d $LINE --dport 80 -j REDIRECT --to-ports 8088
    /sbin/iptables -t nat -A PREROUTING -p tcp -d $LINE --dport 80 -j REDIRECT --to-ports 8088

done


IPARRY=(
192.168.0.242
127.0.0.1
127.0.0.2
);


for LINE in ${IPARRY[*]}
do
    echo "set line[$LINE]"
    #HTTP
    iptables -t nat -A OUTPUT -p tcp -d $LINE --dport 8020 -j REDIRECT --to-ports 8088
    iptables -t nat -A PREROUTING -p tcp -d $LINE --dport 8020 -j REDIRECT --to-ports 8088

    iptables -t nat -A OUTPUT -p tcp -d $LINE --dport 8021 -j REDIRECT --to-ports 8000
    iptables -t nat -A PREROUTING -p tcp -d $LINE --dport 8021 -j REDIRECT --to-ports 8000

    iptables -t nat -A OUTPUT -p tcp -d $LINE --dport 8022 -j REDIRECT --to-ports 22
    iptables -t nat -A PREROUTING -p tcp -d $LINE --dport 8022 -j REDIRECT --to-ports 22

    iptables -t nat -A OUTPUT -p tcp -d $LINE --dport 8023 -j REDIRECT --to-ports 8730
    iptables -t nat -A PREROUTING -p tcp -d $LINE --dport 8023 -j REDIRECT --to-ports 8730

    iptables -t nat -A OUTPUT -p tcp -d $LINE --dport 80 -j REDIRECT --to-ports 8088
    iptables -t nat -A PREROUTING -p tcp -d $LINE --dport 80 -j REDIRECT --to-ports 8088

done

#route add -host 192.168.1.11 gw 192.168.1.2