some people think that ssh is just used for an OS shell. because they never used ssh service properly except controlling a shell.

ssh is a more complicated thing than you think. but I am not going to discuss it all(maybe some other day). today I am going to show you port forwarding.

basically, port forwarding is a process, in which, we try to open a port to access something…KNOW MORE

ssh port forwarding is also called ssh tunneling. because it seems like a tunnel to access a website with ssh. I will explain in a minute. it is basically two types- the Local Port Forwarding and the Remote Port Forwarding.

 

REMOTE PORT FORWARDING

It is a simple way to present your local service on someone else’s computer.

for an Example, we can use port 80(HTTP). suppose, we have a website and we want to show it to our friend. but the problem is that he is not in our local area network.

here we can use ssh to show our website to our friend computer.

type this command:

ssh -R 80:127.0.0.1:80 <public IP>

I used -R for remote port forwarding. always remember, in remote port forwarding, we specify the first port(after -R) to open that port in the remote server.

and after localhost IP, I have specified the local port on which I have hosted the website.

there is too much to understand. above, I have type ‘public IP’.

it is showing your friend’s public static IP. you can also change the IP with its domain.

it is required that your friend must allow remote port forwarding in the ssh configuration file.

use this command and you will know how it works

ssh -R 80:localhost:80 serveo.net

before running this command start your web services on port 80.
type this command:

service apache2 start

 

 

LOCAL PORT FORWARDING

you can say that local port forwarding is a way to access a website on your localhost. but we can access other ports within port80(HTTP)

type this command:

ssh -L 8080:www.technicalnavigator.in:80 <your hostname>

-L is to tell ssh that we want to make an ssh tunnel from the website to our localhost. in remote port forwarding, we specified the first port for remote port but in local port forwarding, we specify the first port for the local host. like, on that first port(8080), our local host will give a response.

And the second port is for the remote host. like, the service port(80) which is running by the remote host.

in the end, I have specified the hostname. the hostname can be any user on the ssh from your machine. you can use root in the place of a hostname.

it is useful when there is a firewall which is blocking some websites. then you can use it to access it on your local website.

but remembers that you just must enable the ssh service for port forwarding.

 

type this command to run ssh service:

service ssh start

 

 

Thanks For Visiting.

LEAVE A REPLY

Please enter your comment!
Please enter your name here