# 转发脚本内容
tcpproxy.sh----------
#!/bin/sh
# TCP Proxy using IPTables
echo 1 > /proc/sys/net/ipv4/ip_forward
# Flush nat table
iptables -t nat -F
# tcpproxy LOCAL_IP LOCAL_PORT REMOTE_IP REMOTE_PORT
function tcpproxy {
iptables -t nat -A PREROUTING --dst $1 -p tcp --dport $2 -j DNAT --to-destination $3:$4
iptables -t nat -A POSTROUTING --dst $3 -p tcp --dport $4 -j SNAT --to-source $1
iptables -t nat -A OUTPUT --dst $1 -p tcp --dport $2 -j DNAT --to-destination $3:$4
}
------------
# 使用方法
tcpproxy.sh 192.168.1.1 12345 192.168.1.2 12345