• Home
  • About Me
  • Privacy Policy
  • Hire me (FullStack Stack Developer)

Bhawani Blog

Menu
  • Home
  • About Me
  • Privacy Policy
  • Hire me (FullStack Stack Developer)
Home  /  Computer Science • Computer Science Beginners • Comupter Networking  /  SSH Tunneling (Make your localhost to the public)
SSH Tunneling
19 December 2021

SSH Tunneling (Make your localhost to the public)

Written by Bhawani Shankar
Avatar photo
Computer Science, Computer Science Beginners, Comupter Networking Leave a Comment

Hello friends, today I have brought a very useful thing for you, after reading it, you will enjoy it.

Note 1: Before going further if you are not aware of Basic IP and Protocols then please read point 3 of this blog.

Note 2: And if you do not know about SSH, then take its information from Google or YouTube, then only go ahead.

Have you heard about ngrok?

If you have heard then it is good and if you have not heard then I will tell you a little.

Generally, we use ngrok for port forwarding.

With the help of ngrok, we can publicly access the services running on our localhost. Mostly everyone uses it to make our demo application or website visible to the client. But it has some limitations and its pricing is very high.

So let’s tackle the problem of its limitations and pricing.

What is port forwarding?

By port forwarding, we can communicate requests from one address and port number combination to another while the packets are traversing a network gateway, such as a router or firewall.

What is tunneling?

A tunneling protocol is a communication protocol that allows the movement of data from one network to another. This involves allowing private network communication to be sent over a public network or public network communication over a private network through a process called encapsulation.

In simple words, you can communicate your private network to a public network and public network to a private network.

Requirements

  1. A vps with public ip. and ssh running.
  2. At least one service running on vps.
  3. client cpu with ssh running.

Types Of SSH Tunneling or Port Forwarding

There are two types of ssh port forwarding.

1. Local Port Forwarding

Local port forwarding

You already know this thing that if the devices are connected to the same network then we can access their services on each other devices. And if you don’t know then see Not 1 above.

Now we can access the services of CPU 1 from the client-side because it has public IP. But the services of CPU 2, CPU 3, CPU 4 can be accessed only in the same network. We cannot access it from the client side.

So now we have to apply some tricks to access the services of CPU 2, CPU 3, CPU 4 on the client-side that we are calling here SSH Tunneling (Local Port Forwarding).

Or in another example, if you are familiar with firewall, then let me tell you that if any VPS port is not accessible from the client-side due to firewall. So you can also use this thing to access it.

to do local port forwarding follow the below code.

ssh [USER]@[SERVER] -L [PORT ON CLIENT SIDE]:localhost:[PORT ON SERVER SIDE]

Now open localhost:[PORT ON CLIENT SIDE] will open the service of the server on your device.

Pass -g argument for global access (EX: 192.168.1.35 can access this on client-side).

ssh [USER]@[SERVER] -g -L [PORT ON CLIENT SIDE]:localhost:[PORT ON SERVER SIDE]

Now open 192.168.1.**:[PORT ON CLIENT SIDE] will open the service of the server on your device.

Other arguments are following:

ssh -N -f [USER]@[SERVER] -L [PORT ON CLIENT SIDE]:localhost:[PORT ON SERVER SIDE]

Here the -f option tells the ssh command to run in the background and -N not to execute a remote command.

2. Remote Port Forwarding

Remote port forwarding

This section will be very fun for you. Because you get all the clients to check the demo app. Then you have to give public access and with the help of this, you can do this.

First open /etc/ssh/sshd_config on server/vps.

sudo nano /etc/ssh/sshd_config

Here find the GatewayPorts use the following shortcut to find in nano editor.

ctr+w 

Type GatewayPorts and hit Enter.

Now remove # from this and make it like below:

GatewayPorts yes

In case if not found GatewayPorts then write it in the bottom.

Restart the SSH service with the command:

sudo systemctl restart sshd

Now execute the following command:

ssh -R [PORT ON SERVER SIDE]:localhost:[PORT ON CLIENT SIDE] [USER]@[SERVER]

Now you can access client service from the vps with the following:

[SERVER]:[PORT ON SERVER SIDE]

3. Dynamic Port Forwarding

comming soon…..

Share On
Share on Facebook
Share on Twitter
Share on LinkedIn
Share on Whatsapp
Avatar photo
Bhawani Shankar
Connect on Facebook Connect on Twitter Connect on Linkedin

Hey i am a professional web developer and programmer. i am expert in following. 1. Python. 2. Django. 3. Php. 4. Laravel. 5. Mongodb. 6. Bootstrap. 7. Nodejs. 8. React Native. 9. Electron 10. Flutter and many more.

 Previous Article Hacking with laser light
Next Article   Should you start your own IT company? 🤔

Related Posts

  • Should you start an IT company

    Should you start your own IT company? 🤔

    August 6, 2022
  • Hack Alexa With Laser Light

    Hacking with laser light

    December 18, 2021
  • How did I get my first project on Fiverr

    How I got my first project on Fiverr?

    December 16, 2021
0 0 votes
Article Rating
Subscribe
Login
Notify of
guest

guest

0 Comments
Inline Feedbacks
View all comments

Categories

  • Computer Science (5)
    • Computer Science Beginners (3)
    • Comupter Networking (1)
  • Electron-JS (1)
  • Flutter (1)
  • Full Stack Development (1)
  • Motivation (1)
  • Nodejs (1)
  • Personal Blog (5)
  • Software (1)
    • Computer Software (1)
  • Uncategorized (5)

Recent Posts

  • Flutter Interview Questions (2024) PART – 1
  • Tips & Tricks PART – 1
  • kalyug kalyug kalyug 😈 
  • Still, I’m unhappy
  • Should you start your own IT company? 🤔

Recent Comments

  • Bholu saini on About Me
  • Bhawani Shankar on Tips & Tricks PART – 1
  • Vaishnavi singh on Tips & Tricks PART – 1
  • Bholu Saini on B.Tech a curse or boon
  • Kapil Banshiwal on Should you start your own IT company? 🤔

Calendar

June 2025
M T W T F S S
 1
2345678
9101112131415
16171819202122
23242526272829
30  
« Jan    

Archives

  • January 2024
  • September 2022
  • August 2022
  • December 2021
  • October 2021
  • March 2021
  • August 2020

Categories

  • Computer Science
  • Computer Science Beginners
  • Computer Software
  • Comupter Networking
  • Electron-JS
  • Flutter
  • Full Stack Development
  • Motivation
  • Nodejs
  • Personal Blog
  • Software
  • Uncategorized

Meta

  • Log in
  • Entries feed
  • Comments feed
  • WordPress.org
© Copyright 2020. Blog by Bhawani Shankar.
wpDiscuz