# forwarder: forward all incoming connections to other host


# cat forwarder
#!/bin/bash

action="$1"
source="$2"
listener="$3"
target="$4"

in='iptables --table nat'

case $action in
start)
        echo 1 > /proc/sys/net/ipv4/ip_forward
        $in --append PREROUTING \
                --source $source --destination $listener \
                --jump DNAT --to-destination $target
        $in --append POSTROUTING \
                --source $source --destination $target \
                --jump SNAT --to-source $listener
        ;;
stop)
        $in --delete PREROUTING \
                --source $source --destination $listener \
                --jump DNAT --to-destination $target
        $in --delete POSTROUTING \
                --source $source --destination $target \
                --jump SNAT --to-source $listener
        ;;
status)
        $in --numeric --list --line-numbers
        ;;
clean)
        $in --flush
esac
# ./forwarder start 192.168.1.1 192.168.1.2 8.8.8.8

No comments: