#!/bin/bash

# Setup for forwarding

ip2fwd=10.1.70.11 	# The IP of the local machine we want to forward
ssh_in=222		# The input port to forward to the local machine  
ssh_out=22		# The standard service port
samba_in=4445		
samba_out=445

sudo iptables --append FORWARD --in-interface eth1 -j ACCEPT
sudo iptables --table nat --append POSTROUTING --out-interface eth0 -j MASQUERADE
sudo iptables -A FORWARD -i eth1 -o eth0 -j ACCEPT
sudo iptables -A PREROUTING -t nat -i eth0 -p tcp --dport $ssh_in -j DNAT --to $ip2fwd:$ssh_out
sudo iptables -A FORWARD -p tcp -d $ip2fwd --dport $ssh_out -j ACCEPT
sudo iptables -A PREROUTING -t nat -i eth0 -p tcp --dport $samba_in -j DNAT --to $ip2fwd:$samba_out
sudo iptables -A FORWARD -p tcp -d $ip2fwd --dport $samba_out -j ACCEPT
sudo sysctl -w net.ipv4.ip_forward=1
