webサーバーりダイレクト

redirect.sh

#!/bin/bash
if [ -z “$2" ]
then
echo -e “Usage: $0 SourceIP DestinationIP"
exit 1
fi

sed -i “s/net.ipv4.ip_forward = 0/net.ipv4.ip_forward = 1/g" /etc/sysctl.conf
echo 1 > /proc/sys/net/ipv4/ip_forward

modprobe iptable_nat
modprobe ip_conntrack_ftp
modprobe ip_nat_ftp

for PORT in 20 21 80
do
iptables -t nat -A PREROUTING -d $1 -p tcp -m tcp –dport $PORT -j DNAT –to-destination $2:$PORT
iptables -t nat -A POSTROUTING -d $2 -p tcp –dport $PORT -j SNAT –to $1
done

/etc/init.d/iptables save
iptables -nL -t nat
cat /etc/sysconfig/iptables

Source

Posted by arkgame