Search Our Database
How to Set Up Local Port Forwarding Using Terminal
Introduction
Local port forwarding is a method of securely tunneling network traffic from your local machine to a remote server over an encrypted SSH connection. It allows you to access services, databases, or applications that are hosted on private networks or behind firewalls, without directly exposing them to the public internet.
By forwarding a local port to a port on the remote server, you can interact with these internal resources as if they were running on your own machine, enhancing both security and convenience. This technique is commonly used by developers, administrators, and security professionals to protect sensitive services during remote access.
In this guide, you will learn how to set up local port forwarding using OpenSSH on a Linux system, ensuring your connections remain private and secure.
Prerequisites
- SSH login credentials for the remote server
- Destination server IP address or hostname
- Destination server port number
Step-by-Step Guide
Step 1: Open Your Terminal
- Launch the terminal application on your local machine.
Step 2: Execute the SSH Command for Port Forwarding
- Use the following syntax to establish the port forwarding:
ssh -L local_port:destination_server_ip:remote_port ssh_server_hostname
Command Explanation
- -L: Specifies local port forwarding
- local_port: The port number on your local machine that you want to forward
- destination_server_ip: The IP address or hostname of the destination server
- remote_port: The destination port on the destination server
- ssh_server_username: The username to log into the SSH server
- ssh_server_ip: The IP address or hostname of the SSH server
Example Scenario
Suppose you want to forward traffic from your local port 2288 to the destination server 10.10.2.30 on port 22, through an SSH server at 103.209.10.10 using the username almalinux and a private key located at home/almalinux/pass.key You would run:
ssh -i /home/almalinux/pass.key -L 2288:10.10.2.30:22 almalinux@103.209.10.10
After the port forwarding is established, you can connect to the destination server through the forwarded local port:
ssh -i /home/almalinux/pass.key cloud-user@localhost -p 2288
Important Notes
- Make sure the local port you choose (e.g., 2288) is not already being used by another application.
- Ensure you have permission to connect to the SSH server and access the destination server.
Conclusion
Local port forwarding is a powerful feature of SSH that allows you to securely access remote resources without exposing them to the public network.
By following the steps outlined in this guide, you can set up a secure tunnel from your local machine to a remote destination with ease.
Always ensure that your SSH keys and login credentials are handled securely to maintain the safety and integrity of your connections.
If further assistance is needed, please communicate with our support team at support@ipserverone.com.