Port forwarding lets you send traffic from a local port on your machine to a port on a remote server. This method is useful for accessing remote services that are not directly available on your local network. By using local port forwarding, you can interact with remote services as if they were running on your local machine.
In an SSH tunnel, port forwarding binds a local port to a port on a remote server. Any data sent to the local port is securely forwarded to the remote service. This technique is often used to access remote web servers, databases, or services behind a firewall.
Configuring port forwarding helps you manage remote resources securely. It also allows you to bypass network restrictions and protect sensitive data during transmission. Following these steps will enable you to set up local port forwarding using SSH.
Steps to configure local port forwarding in SSH:
- Open a terminal on your local machine.
- Initiate an SSH connection to the remote server.
$ ssh username@remote-server.com
- Specify the local port you want to forward using the -L option.
$ ssh -L 8080:localhost:80 username@remote-server.com
- Define the remote server’s address and the port number to which the traffic will be forwarded.
$ ssh -L 8080:remote-server.com:80 username@remote-server.com
- Execute the command to establish the SSH tunnel.
$ ssh -L 8080:remote-server.com:80 username@remote-server.com
- Access the remote service by connecting to the specified local port on your machine.
$ curl http://localhost:8080
Mohd Shakir Zakaria is an experienced cloud architect with a strong development and open-source advocacy background. He boasts multiple certifications in AWS, Red Hat, VMware, ITIL, and Linux, underscoring his expertise in cloud architecture and system administration.
Comment anonymously. Login not required.