SSH Forwarding

Forward local socket /tmp/mysqld.sock to remote socket /var/run/mysqld/mysqld.sock

ssh -L LOCAL_SOCKET:REMOTE_SOCKET [USER@]REMOTE_IP
ssh -L /tmp/mysqld.sock:/var/run/mysqld/mysqld.sock root@ip

Forward local port 0.0.0.0:5555 to remote socket /var/run/mysqld/mysqld.sock

ssh -L [LOCAL_IP:]LOCAL_PORT:REMOTE_SOCKET [USER@]REMOTE_IP
ssh -L 5555:/var/run/mysqld/mysqld.sock root@ip

Forward local 0.0.0.0:5555 to remote localhost:8080

ssh -L LOCAL_PORT:[REMOTE_IP:]REMOTE_PORT [USER@]REMOTE_IP
ssh -L 5555:localhost:8080 root@ip

Forward traffic from the remote machine port 8080 to the local machine localhost:80

ssh -R REMOTE_PORT:[LOCAL_IP:]LOCAL_PORT [USER@]REMOTE_IP
ssh -R 8080:localhost:80 root@ip

At this point, the users logged in are able to reach the local machine localhost:80 from the remote machine localhost:8080. But user from outside the remote machine cannot reach it.

To enable user from outside to access the local machine localhost:80 from the remote machine localhost:8080, you will need to edit the sshd.config.

GatewayPorts yes

Then, restart the sshd service.

systemctl restart ssh

Or you can do this:

# LOCAL MACHINE
ssh -R 8079:localhost:80 root@ip
# FOR ANYONE THAT CAN REACH THE REMOTE MACHINE
ssh -L 0.0.0.0:8080:localhost:8079 root@localhost
# ONLY FOR USERS LOGGED IN TO THE REMOTE MACHINE
ssh -L localhost:8080:localhost:8079 root@localhost


Comments

Leave a Reply

Your email address will not be published. Required fields are marked *