Skip to content

Click on each book below to review & buy on Amazon.

As an Amazon Associate, I earn from qualifying purchases.


CompTIA Linux+ XK0-005 - 2.4 - SSH: Tunneling - Port Forwarding

SSH tunneling, specifically port forwarding, is a powerful feature that allows users to securely access services running on remote servers as if they were running on their local machines. Port forwarding establishes encrypted connections between the local and remote machines, enabling the forwarding of network traffic.

This guide will explain the concept of port forwarding, its benefits, and how to set it up using SSH.

Understanding Port Forwarding

Port forwarding enables users to access network services on a remote server through an encrypted SSH connection. It works by forwarding specific ports on the local machine to corresponding ports on the remote server. This allows users to access services hosted on the remote server as if they were running locally.

There are two types of port forwarding:

  • Local Port Forwarding: This forwards traffic from a port on the local machine to a specified port on the remote server. It is useful when you want to access a service running on the remote server from your local machine.

  • Remote Port Forwarding: This forwards traffic from a port on the remote server to a specified port on the local machine. It is useful when you want to expose a service running on your local machine to the remote server.

Setting up Port Forwarding

To set up port forwarding, follow these steps:

  • Use the ssh command to connect to the remote server, specifying the appropriate port forwarding option. The following examples demonstrate the syntax for both local and remote port forwarding:

    • Local Port Forwarding:

      ssh -L local_port:destination_host:destination_port user@remote_server
      
    • Remote Port Forwarding:

      ssh -R remote_port:destination_host:destination_port user@remote_server
      

    Replace local_port with the port number on your local machine you want to forward, destination_host with the IP address or hostname of the target server, and destination_port with the port number of the service on the target server.

  • After successfully logging in, the specified port forwarding will be established, allowing you to access the desired service on the local or remote machine.

Conclusion

Port forwarding is a powerful feature of SSH that allows users to securely access services on remote servers as if they were running locally. Whether you need to access remote services from your local machine or expose local services to remote servers, port forwarding provides a secure and convenient solution. Understanding how to set up and configure port forwarding using SSH is essential for Linux administrators and users who need to access remote services efficiently.


Support DTV Linux

Click on each book below to review & buy on Amazon. As an Amazon Associate, I earn from qualifying purchases.

NordVPN ®: Elevate your online privacy and security. Grab our Special Offer to safeguard your data on public Wi-Fi and secure your devices. I may earn a commission on purchases made through this link.