iptables 端口轉發
iptables -t nat -A PREROUTING -d 114.114.114.114 -p tcp -m tcp --dport 3389 -j DNAT --to-destination 10.0.1.123:3389
iptables -t nat -A POSTROUTING -d 10.0.1.123 -p tcp -m tcp --dport 3389 -j SNAT --to-source 10.0.0.254
#外網接口地址114.114.114.114 內網接口地址10.0.0.254,內部服務器10.0.1.123轉發端口3389
rinetd
編譯安裝
wget http://www.boutell.com/rinetd/http/rinetd.tar.gz
tar xzvf rinetd.tar.gz
cd rinetd
mkdir -p /usr/man/man8
make &&make install
配置文件
cat /etc/rinetd.conf
0.0.0.0 9001 192.168.1.1 3306
0.0.0.0 9002 192.168.1.2 80
#綁定的地址、綁定的端口、轉發的地址 、轉發的端口
啓動rinetd服務
rinetd -c /etc/rinetd.conf
SSH
ssh轉發命令
ssh -N -L 0.0.0.0:1521:10.0.15.131:1521 [email protected] -f
#通過ssh通道,將10.0.15.131的1521端口映射到本機的1521端口,參數-f表示在後臺運行
ssh轉發腳本
#!/bin/bash
HOST=192.168.21.103
SSH_SERVER="[email protected] -p 24242"
declare -a T
declare -a D
T[0]="-L $HOST:33900:192.168.102.90:3389"
T[1]="-L $HOST:33910:192.168.102.93:3389"
function start()
{
pidwl=$(ps -ef|grep -v grep|grep "$SSH_SERVER"|wc -l)
if [ "X$pidwl" == "X0" ]; then
nohup /usr/local/bin/sshpass -p 'password' ssh -o ServerAliveInterval=6 -2 -f -nNT ${T[*]} $SSH_SERVER &
echo "start $SSH_SERVER"
fi
echo `date +%Y%m%d%H%M%S`
}
function stop()
{
ps -ef|grep -v grep|egrep "ServerAliveInterval"|awk '{print $2}'|xargs kill -9
echo "stop Transmit"
}
case "$1" in
start)
$1
;;
stop)
$1
;;
restart)
stop
start
;;
esac
nginx (stream模塊)
nginx1.9開始支持tcp層的轉發,通過stream實現的,而socket也是基於tcp通信。Module ngx_stream_core_module
cat vhost/port_forword.conf
stream {
# 添加socket轉發的代理
upstream manager {
hash $remote_addr consistent;
# 轉發的目的地址和端口
server 10.0.10.10:3389 max_fails=3 fail_timeout=30s;
}
server {
listen 9001;
proxy_connect_timeout 1s;
proxy_timeout 3s;
proxy_pass manager;
}
}
# 通過nginx 9001端口可以訪問內網Windows跳板機。