Linux serverNETWORK ADMINISTRATIONS

SSH Port Forwarding In Linux | SSH Tunneling in RHEL 8 | Local, Remote & Dynamic Port Forwarding



SSH Port Forwarding In Linux | SSH Tunneling in RHEL 8 | Local, Remote & Dynamic Port Forwarding
===
SSH Port Forwarding:
• SSH port forwarding or tunneling allows you to forward otherwise insecure TCP traffic inside a secure SSH tunnel from local to destination server.
Type of SSH Port Forwarding:
• Local Port Forwarding
• Remote Port Forwarding
• Dynamic Port Forwarding
—-
1.1.1: Create SSH tunnel for HTTP server Use SSH client on server1 (our localhost) to create a secure tunnel towards server3. The -L option specifies local forwarding, in which the TCP client is on the local machine with the SSH client.
[root@server1 ~]# ssh -f -N -L localhost:5555:server3:80 root@server3

We can also use ssh -f -N -L 5555:localhost:80 root@server3 to establish the SSH tunnel but that would confuse the beginners so we will keep it by the rules. Ideally here third field localhost is considered to be called on server3 so we can use either
Make sure the SSH process is still active:

[root@server1 ~]# ps -ef | grep ssh

1.1.2: Verify the SSH Tunnel
Next we will try to connect to our apache server on server3 using curl and curl is able to connect to server3:80 using the server1:5555

[root@server1 ~]# curl http://localhost:5555
Welcome To Nehra Classes Web Page.

More information can be collected from tcpdump which is running on server3. This shows that the curl request was served using SSH secure Tunnel even when the requested port was 80

[root@server3 ~]# tcpdump -i enp0s8 port 22

1.1.3: Close Local Forwarding Tunnel
To close the secure SSH Tunnel we must kill the SSH process which was created to forward the PORT.

[root@server1 ~]# kill -9 2384

1.2: Local Port Forwarding with three servers.
[root@server1 ~]# ssh -f -N -L localhost:5555:server3:80 root@server2

Make sure the SSH process is active which means our tunnel is created
[root@server1 ~]# ps -ef | grep ssh

1.3.1: Create SSH Tunnel with Gateway Port.
[root@server1 ~]# ssh -g -f -N -L :5555:server3:80 root@server3

Make sure the SSH process is still active for the respective command:
[root@server1 ~]# ps -ef | grep ssh

1.3.2: Verify the Local Port Forwarding.
We will use curl command from server2 this time to check if it can connect to server3 using port 5555 from the secure tunnel.
[root@server2 ~]# curl http://server1:5555
Welcome To Nehra Classes Web Page.

1.3.3: Close SSH Tunnel
Close the SSH Tunnel To close the Local forwarding port, you can go ahead and kill the SSH process which we created earlier to start the tunnel from server1.
[root@server1 ~]# kill -9 2423

2: Remote port forwarding.
[root@server3 ~]# ssh -f -N -R localhost:5555:server3:80 root@server1

Make sure the SSH process with the above command is still running
[root@server3 ~]# ps -ef | grep ssh

2.2: Verify SSH Tunnel setup
Verify SSH Tunnel Next we will use curl from server1 to connect to server3 using port 5555
[root@server1 ~]# curl http://localhost:5555
Welcome To Nehra Classes Web Page.

With tcpdump running on server3 we can check the secure SSH Tunnel was used for the curl
request from server1 to server3
[root@server3 ~]# tcpdump -i enp0s8 port 22 or 80

2.3: Close SSH Tunnel
To close the SSH Tunnel we must kill the SSH process which is running on our server3
[root@server3 ~]# ps -ef | grep 5555
[root@server3 ~]# kill -9 13638

3: Dynamic Port Forwarding.
[root@server1 ~]# ssh -f -N -D 8080 root@server3

3.2: Verify SSH Tunnel setup
[root@server1 ~]# curl –proxy socks5h://localhost:8080 http://server3:80
Welcome To Nehra Classes Web Page.
===
My i5 10 Gen Laptop With 512 GB SSD & 8 GB DDR4:
https://amzn.to/30amhRt

My DSLR Camera:
https://amzn.to/36954Ml

My Boya Microphone:
https://amzn.to/3mZavTS

My Mobile:
https://amzn.to/2HCdilL

My Router:
https://amzn.to/3mXC0x7

My Tripod With Light:
https://amzn.to/2FZeCPp

My TV Entertainment System:
https://amzn.to/345150F

My Head-Phone:
https://amzn.to/3ie4rDB

My Smart Watch:
https://amzn.to/3cRbPUt

===
Thanks for watching the video. If it helped you then, please do like & share it with others as well. Feel free to post your queries & suggestions, we will be glad to answer your queries.
If you like our hard work then do subscribe to our channel & turn on the bell notification for latest updates.
===
Join this channel to get access to perks:
https://www.youtube.com/channel/UCvk2Fst1h1a0StSnUcvGfBQ/join
===

©COPYRIGHT. ALL RIGHTS RESERVED

#NehraClasses #LinuxTraining #SSHPortForwarding

source
redhat linux

Leave a Reply

Your email address will not be published. Required fields are marked *