Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!


Mirror a remote port using SSH
New on LowEndTalk? Please Register and read our Community Rules.

All new Registrations are manually reviewed and approved, so a short delay after registration may occur before your account becomes active.

Mirror a remote port using SSH

dnwkdnwk Member

I was trying to connect to a remote MySQL by tunneling inside SSH.

I run this command on client side

ssh -L 3307:localhost:3306 root@remote server address

It actually ssh login to the remote server, instead of forwarding the port I need. What should be the correct command?

Comments

  • perennateperennate Member, Host Rep
    edited May 2014

    You could do ssh -L 3307:remote:3306 root@localhost but that seems kind of pointless, I think you can do better with iptables.

  • dnwkdnwk Member

    How do I forward a remote port to local with iptable? with encryption

  • perennateperennate Member, Host Rep

    dnwk said: How do I forward a remote port to local with iptable? with encryption

    Um, the command you pasted in your first post is the one you want then. It will create a port on your local server 3307 that is forwarded via SSH to localhost:3306 on the remote server. You can add -N if you don't want a shell, and then use screen or nohup to run in background.

  • chrispchrisp Member

    What you do is perfectly fine. You can also use ssh -L 3306:localhost:3306 [email protected] right away. When connected to the remote host you can use the local 3306 port of the server on your client locally like localhost:3306. I use this for a lot of tunneling stuff because it's easy and encrypted through your ssh connection.

  • dnwkdnwk Member

    @perennate said:
    Um, the command you pasted in your first post is the one you want then. It will create a port on your local server 3307 that is forwarded via SSH to localhost:3306 on the remote server. You can add -N if you don't want a shell, and then use screen or nohup to run in background..

    Yes. I am looking at a way to make it run in background

  • dnwkdnwk Member

    @perennate said:
    Um, the command you pasted in your first post is the one you want then. It will create a port on your local server 3307 that is forwarded via SSH to localhost:3306 on the remote server. You can add -N if you don't want a shell, and then use screen or nohup to run in background.

    -N doesn't work.

    It will just hang there

  • perennateperennate Member, Host Rep

    dnwk said: It will just hang there

    That is what it is supposed to do. Just do screen -S blue and then run the command in screen

  • amhoabamhoab Member

    Add -f -N to your command and you should be good. It'll connect and keep the tunnel open in the background.

Sign In or Register to comment.