ssh remote port forwarding

علی ذوالفقار
1399/03/02 23:33:57 (544)
to forward remote port to local machine , use ssh port forwarding :
 ssh -R remoteport:local-address:localport user@server
 ssh -R 8080:127.0.0.1:8080 root@myserver.com
 autossh -M 0 -R remoteport:local-address:localport user@server
autossh -f -M 0 -o "ServerAliveInterval 10" -o "ServerAliveCountMax 3" -D localhost:1234 -N 
autossh -M 0 -o "ServerAliveInterval 10" -o "ServerAliveCountMax 3" -D localhost:1234 user@ip.address
user@ip.address

Gateway Port Forward must be enabled in sshd_config file :
vi /etc/sshd_config
find and change GatewayPorst to yes :
GatewayPorts yes
now save config file and restart sshd service :
systemctl restart sshd
or
service sshd restart

SAMPLE : 
forward local RDP to my server on port 13389 : 
    ssh -R 13389:127.0.0.1:3389 root@myserver.com

forward a PC(in LAN) RDP to my server on port 13389 :
    ssh -R 13389:192.168.0.5:3389 root@myserver.com

-------
autossh : 
autossh -M 0 -o "ServerAliveInterval 1" -o "ServerAliveCountMax 5" -D local-ip:1080 root@remote
autossh -M 0 -D local-ip:1080 root@remote
ssh -D localportnumber accountname@servername
ssh -D 1080 root@remote-server

------------------------------------------------------
foreign server 
--------------------
autossh -M 0 -R 222:localhost:22 root@iran-server

iran server
--------------------
autossh -M 0 -D iran-server:21 -C root@127.0.0.1 -p 222
Back