
{{ $('Map tags to IDs').item.json.title }}
How to Tunnel Traffic with SSH
SSH tunneling allows you to securely forward network traffic over an SSH connection. This can be useful for accessing services securely, bypassing firewalls, or encrypting traffic over unsecured networks. This tutorial will guide you through creating an SSH tunnel to tunnel traffic effectively.
1. Understanding SSH Tunneling
SSH tunneling can be classified into three types:
- Local Port Forwarding: Forwards a port on your local machine to a remote server.
- Remote Port Forwarding: Forwards a port on the remote server to a port on your local machine.
- Dynamic Port Forwarding: Allows you to create a SOCKS proxy that can route traffic dynamically.
2. Setting Up Local Port Forwarding
To create a local tunnel, use the following command:
ssh -L local_port:remote_host:remote_port username@ssh_server
Replace the placeholders:
- local_port: The port on your local machine.
- remote_host: The target server you want to access.
- remote_port: The port used by the target server.
- username: Your SSH username.
- ssh_server: The IP address or hostname of your SSH server.
For example, to forward local port 8080 to a web server on port 80 at example.com
through an SSH server:
ssh -L 8080:example.com:80 username@ssh_server
You can now access the remote web server by going to http://localhost:8080
in your web browser.
3. Setting Up Remote Port Forwarding
To set up remote port forwarding, use:
ssh -R remote_port:localhost:local_port username@ssh_server
This allows others to access services running on your local computer through the remote server. For example:
ssh -R 9090:localhost:3000 username@ssh_server
Users can now access the application running on port 3000 of your local machine via the remote server’s port 9090.
4. Setting Up Dynamic Port Forwarding
Dynamic port forwarding uses a SOCKS proxy to route traffic dynamically. To create a SOCKS proxy using SSH:
ssh -D local_port username@ssh_server
For example:
ssh -D 8080 username@ssh_server
Configure your application to use the SOCKS proxy at localhost:8080
.
5. Conclusion
SSH tunneling is a powerful feature that enhances security and flexibility when accessing remote services. By following this tutorial, you have learned how to create local, remote, and dynamic tunnels using SSH. Continue exploring SSH features to strengthen your network security and provide secure access to applications!