#!/bin/bash
# LAN IP ermitteln
ip=$(ip addr show eth1 | grep -vw "inet6" | grep "global" | grep -w "inet" | cut -d/ -f1 | awk '{ print $2 }')
if [[ $ip == "192.168.8"* ]];
then
iptables -t nat -A OUTPUT -p tcp -d 192.168.0.1/24 -j DNAT --to-destination 192.168.8.2
iptables -t nat -A POSTROUTING -m addrtype --src-type LOCAL --dst-type UNICAST -j MASQUERADE
elif [[ $ip == "192.168.16"* ]];
then
iptables -t nat -A OUTPUT -p tcp -d 192.168.0.1/24 -j DNAT --to-destination 192.168.16.2
iptables -t nat -A POSTROUTING -m addrtype --src-type LOCAL --dst-type UNICAST -j MASQUERADE
elif [[ $ip == "192.168.24"* ]];
then
iptables -t nat -A OUTPUT -p tcp -d 192.168.0.1/24 -j DNAT --to-destination 192.168.24.2
iptables -t nat -A POSTROUTING -m addrtype --src-type LOCAL --dst-type UNICAST -j MASQUERADE
elif [[ $ip == "192.168.32"* ]];
then
iptables -t nat -A OUTPUT -p tcp -d 192.168.0.1/24 -j DNAT --to-destination 192.168.32.2
iptables -t nat -A POSTROUTING -m addrtype --src-type LOCAL --dst-type UNICAST -j MASQUERADE
elif [[ $ip == "192.168.40"* ]];
then
iptables -t nat -A OUTPUT -p tcp -d 192.168.0.1/24 -j DNAT --to-destination 192.168.40.2
iptables -t nat -A POSTROUTING -m addrtype --src-type LOCAL --dst-type UNICAST -j MASQUERADE
fi
