This blog is NOT OFFICIAL website of Kali Linux. We just share Tutorials to learn Cybersecurity.

Easy Port Forwarding using SSH

Home
Sometime we need to run our localhost website or server over internet. To do this we need to forward our port that other device can access our website from anywhere in the world by internet. Usually we can forward our port by configuring settings in router, but if we don't have router or don't wanna use our router or not have static ip, then we have a very easy option. We can remotely forward port using SSH.

SSH port Forward
Image Copyright:  SRU Computer Science


To do this we use a free service called serveo.net and localhost.run. This requires no installation and no sign-up. Serveo is a SSH server. Whenever a user connects to this service they got a public URL that URL can be use to connect to their localhost server.

We are in our Kali Linux system. Here we have a website in php. We can use a html file also.

ls command in kali linux

Now we set this in our localhost. For this we check our local ip by using following command:

ifconfig
The screenshot of our local ip is following :

ifconfig in kali linux

Here we start a basic web server using php by using following command:

php -S 192.168.10.100:80
Here the 192.168.10.100 is our local ip and we run this server in port 80. The screenshot of the command is following:

php server localhost

Here we need to remember that we must run this server in the directory where we saved the php/html file. We have successfully started our website or web server in our local network. Let we check this by typing our local ip and port in browser. The screenshot is following :

demo localhost website

We can see in the screenshot that URL is our local ip. That means it is hosted in localhost. Now we want to access our website outside of our network that means from anywhere via internet.

We minimize the terminal window (Don't close this terminal, because it's running our server) and open another new terminal window to run SSH.

The Serveo Method


For this we apply following command:

ssh -R 80:192.168.10.100:80 serveo.net
Here 80 is our port and we are using ssh using serveo.net service.

Then we can see that our localhost is forwarding in a unique URL, as following screenshot.

serveo.net tutorial

Now we can access our localhost by using this URL. Copy this URL and paste it in the address bar of browser in any devices and see the magic.

SSH port forwarding tutorial

It's done. But wait serveo have some other features.

We can request serveo to get back our old URL. If it is free then serveo will assign it for us again.

We have a old serveo connection with lente.servo.net. We try to get it again. So we request for that subdomain by using following command:

ssh -R lente:80:192.168.10.100:80 serveo.net

getting old domain

Here we got that subdomain. Now we can access our localhost with this older URL.

If we want to forward random port then our first port fiels in command will be 0. like following command:

ssh -R 0:192.168.10.100:80 serveo.net
The screenshot of this command is following :

serveo random port

We can open our website with serveo.net:our_assigned_port from anywhere.
In the following screenshot we have opened this link in our mobile device.

port forward from mobile


Using Localhost.run Method

Well it is almost similar to serveo.net then why we adding this? Because these free services sometimes goes down during overload on the server. If one service is not working then we can try another. So we can use it by applying following command:

ssh -R 80:192.168.10.100:80 ssh.localhost.run
If it prompt for RSA fingerprint we type yes and press enter.


port forwarding using SSH localhost.run method

We got the shareable link in the last line, we can use this link to connect ssh.

That's it. Using this method we can forward port without VPN or router. This is so easy to configure it and the connection is stable unlike ngrok, ngrok is not much stable in free version.

Liked our works ? Show support by sharing and encourage us by commenting in the comment section. Follow our blog for more tutorials like this and for quick updates follow us on Twitter and Medium.
author-img
Kali Linux

Comments

17 comments
Post a Comment
  • AnonymousJanuary 30, 2020 at 1:59 PM

    Serveo not working /:

    Delete Comment
    • Kali Linux photo
      Kali LinuxJanuary 31, 2020 at 10:36 AM

      yes it is a free service and sometimes the server goes down.. use ngrok or protmap for sometime

      Delete Comment
    • AnonymousApril 26, 2020 at 3:16 PM

      sir how can we share files with this port forwarding

      Delete Comment
      • Kali Linux photo
        Kali LinuxApril 27, 2020 at 6:50 AM

        In computer networking, a port is a communication endpoint. At the software level, within an operating system, a port is a logical construct that identifies a specific process or a type of network service. So if we have used the 80 or 8080 port that is for web services. For sharing files you need to open File Transfer Protocol (FTP) that is port number 21. To know how to setup search on Google.

        Delete Comment
      • Terr photo
        TerrMay 6, 2020 at 6:54 PM

        Serveo connection refused

        Delete Comment
        • Kali Linux photo
          Kali LinuxSeptember 6, 2020 at 6:17 PM

          May it's servers are down.. Try again later or choose other port forwarding services.

          Delete Comment
        • Unknown photo
          UnknownNovember 12, 2020 at 1:26 PM

          hi! when running (ssh -R 80:localip:80 ssh.localhost.run) I get the message "Permission Denied (public key). I might be overlooking something, but need some help! thank you!

          Delete Comment
          • Kali Linux photo
            Kali LinuxNovember 12, 2020 at 4:54 PM

            Now in Kali new update we don't get root user by default so you need to use sudo on the command. Try following command:

            sudo ssh -R 80:localip:80 ssh.localhost.run

            Delete Comment
          • msk photo
            mskJanuary 30, 2021 at 2:14 PM

            hi,

            sudo ssh -R 80:localip:80 ssh.localhost.run

            after i using this command permission denied how to share link to victim. need your help.

            Delete Comment
            • Kali Linux photo
              Kali LinuxJanuary 30, 2021 at 5:20 PM

              Try with different port like 8080. Host the localhost on 8080 port and set the forwarding port also in 8080. Hope this will solve the problem. If not then you can send us screenshot on our Official Telegram group.

              Delete Comment
            • DarkUser photo
              DarkUserJune 17, 2021 at 1:29 PM

              How To Portforward forTCP ??
              portmap is not working today it gets banned

              Delete Comment
              • Kali Linux photo
                Kali LinuxJune 18, 2021 at 6:28 PM

                Thanks for commenting. There are lots of services like this LocalHost.io ngrok etc, or you can try our this new article on this topic.

                Delete Comment
              • quzziaty photo
                quzziatyNovember 9, 2021 at 4:23 PM

                i have already static ip from my network service and i want to make my webserver public with the ip thay give it to me how can i do it?

                Delete Comment
                • Kali Linux photo
                  Kali LinuxNovember 10, 2021 at 6:19 PM

                  You just need to forward the port which your web server is running. The default port is 80 for web services. You can forward your port on your router settings. Various router brands have various type of settings you need to find out your.

                  After forwarding your webserver's port on your router settings you can access your localhost website from outside of your network (on the internet basically). You need to browse your public fixed IP address.

                  Thanks

                  Delete Comment
                • AnonymousMarch 3, 2023 at 6:39 PM

                  permission denied(public key) I have tried different port but still the same problem

                  Delete Comment
                  google-playkhamsatmostaqltradent