DEV Community

Baraa Mohamed
Baraa Mohamed

Posted on β€’ Edited on

3

SSH Tunnel: Forwarding Traffic between hosts

In cloud environments, you might encounter scenarios where you need to forward traffic securely between hosts. SSH tunneling, also known as port forwarding, is a technique that allows you to create a secure communication tunnel between two hosts over specific ports.

What is SSH Tunneling?

SSH tunneling enables secure access to remote services that are not directly accessible. For instance, you can access a private service on a cloud server through a public host. This approach helps maintain security by keeping sensitive services private.


Example: Accessing Jenkins Dashboard on AWS

Suppose you have Jenkins running on an EC2 instance in AWS, and you want to access its dashboard on port 8080. Using SSH tunneling, you can securely forward traffic from your local machine to the Jenkins instance.

Pre-requisites:

  1. Ensure the Jenkins EC2 instance allows TCP traffic on port 8080 and HTTP traffic in its security group.
  2. Have the access key for the Jenkins EC2 instance.

Command to Create the Tunnel:

ssh -i <access-key> -L <your-host-port>:<Jenkins-ip>:<Jenkins-port> <public-Jenkins-instance>
Enter fullscreen mode Exit fullscreen mode

Example:

ssh -i "myKey.pem" -L 4040:localhost:8080 ubuntu@ec2
Enter fullscreen mode Exit fullscreen mode

Explanation of Flags:

  • i: Includes the access key file required for authentication.
  • L: Specifies the local port (4040), remote host (localhost or the private IP of Jenkins), and remote port (8080) for the tunnel.
  • localhost: Refers to the Jenkins instance. SSH forwards traffic to port 8080 on the Jenkins EC2 instance.

Accessing Jenkins Locally

After running the command, open your browser and navigate to http://localhost:4040. You should see the Jenkins dashboard, as traffic on port 4040 of your machine is securely forwarded to port 8080 on the EC2 instance.


Conclusion

By leveraging SSH tunneling, you can securely access remote services like Jenkins dashboards without exposing them to the public internet. This technique is versatile and applicable to many cloud-based workflows.

🀍 I'd love to connect with you on LinkedInβ€”let's grow our network and share ideas! here

Image of AssemblyAI tool

Challenge Submission: SpeechCraft - AI-Powered Speech Analysis for Better Communication

SpeechCraft is an advanced real-time speech analytics platform that transforms spoken words into actionable insights. Using cutting-edge AI technology from AssemblyAI, it provides instant transcription while analyzing multiple dimensions of speech performance.

Read full post

Top comments (0)

Image of Timescale

Timescale – the developer's data platform for modern apps, built on PostgreSQL

Timescale Cloud is PostgreSQL optimized for speed, scale, and performance. Over 3 million IoT, AI, crypto, and dev tool apps are powered by Timescale. Try it free today! No credit card required.

Try free

πŸ‘‹ Kindness is contagious

Discover a treasure trove of wisdom within this insightful piece, highly respected in the nurturing DEV Community enviroment. Developers, whether novice or expert, are encouraged to participate and add to our shared knowledge basin.

A simple "thank you" can illuminate someone's day. Express your appreciation in the comments section!

On DEV, sharing ideas smoothens our journey and strengthens our community ties. Learn something useful? Offering a quick thanks to the author is deeply appreciated.

Okay