How tolinux

How to check port-forwarding on Linux?

Port-forwarding lets you redirect incoming network connections to specific ports that your machine uses. It’s really handy for when you want to access your machine from an external device such as your mobile device, or for when you want to stream data from your PC to your TV.

In Linux, port forwarding is implemented using a port-family, like /dev/udp for port 22, and /dev/tcp for port 80000. If you want to know what these ports actually mean, here is a description of the Ubuntu’s public DNS port ranges:

$ telnet localhost 8100

$ telnet localhost 8100:4501

$ telnet localhost 8100:4501

$ ping localhost 8100

$ ping localhost 8100:4501

$ ssh localhost

$ ping 8100

$ ssh localhost

Both Linux-based systems and Windows use something called the DNS system. For those who don’t know, DNS is used by the internet for information purposes such as setting up port forwarding. To help you set up a more secure VPN on Linux, the native OpenVPN software, which is used in Ubuntu and other Linux-based systems, comes with a built-in VPN port (00) to let you establish connections to your VPN’s VPN server (server’s port number) via IP addresses that you can actually reach on your network. If you want to connect remotely via SSH and not by using port-forwarding, you can directly add a port-forwarding plugin to your SSH client on Windows (on Ubuntu, for instance, you can just use the nmcli command). Once you do that, you can redirect any SSH connections to a specific SSH port on your network, rather than using port-forwarding to connect with a VPN’s VPN server.

Supported ports for Linux port-forwarding.

Port Number Forwarding

At this point, the connection between your Linux system and the VPN server is established and you can start using it, so what’s the point of port-forwarding?

If you want to connect via the VPN with a remote machine, you might want to establish a port-forwarding connection via a port that is not directly accessible from your network. You can do that by opening up a command prompt on the remote machine, and typing port-forwarding on Windows. The result will display the ports the remote machine’s port is able to accept. If you don’t want to connect to that specific port, you can simply use the words “port forward port” on the Linux command line instead. On Linux, the port will be forwarded using all available ports, except the port that is used by the VPN server. So you could either connect to the VPN server via port 32, and specify the port number of the remote machine (the IP address of the remote machine) in a TCP/IP port-forwarding script, or you could simply use port forwarding to connect to the remote machine from your router.

On Windows, if you want to use port forwarding to connect to your VPN server from your PC, you first need to know the port that’s used by your VPN server. If it’s port 22 (SSH port) on your Linux system, you can simply use port forwarding to forward SSH connections to port 22 on your network. The new IP address will be assigned to your remote machine when you first connect via SSH and start using it.

How to setup port forwarding in Linux.

As previously mentioned, Linux-based systems like Ubuntu and Fedora, as well as Windows systems like Windows 10 and Server 2016, use something called DNS. There is also a network protocol named IPX, which is used on some network devices such as routers to set up port-forwarding. That’s where you’ll need to use port-forwarding to do things on the network. Here’s how to set up a port-forwarding script in Linux.

Create a port-forwarding script in Linux

If you want to create a network-based port-forwarding script for Linux, open up a text editor and start writing a port-forwarding script. The script will require the IP addresses of your VPN server (it will also use them to determine which ports are available on the remote machine, so this is a little bit more complicated), and the remote machine’s IP address. To create the remote machine’s IP address, you need to know the IP address and the port numbers of the remote machine. To do that, first write a list of IP addresses of your VPN server. You will need to know the IP addresses of your VPN server, and then you need to find and write down the port numbers of all your connected ports. You don’t need to write down all your IP addresses in one piece of text, just one of them. When you’re done writing the script, you should have something like this:

$ ip addr | grep -v fd | awk ‘/\A/(\d+)\IP[0-9]/’ { $g=\d+ /4/0/1/2/0/n. * } 1 2 3 4 5 6 7 8 $ ip addr | grep – v fd | awk ‘/\A/(\d+)\IP[0-9]/’ { $ g = \ d + / 4 / 0 / 1 / 2 / 0 / n . * }

What is the string “_npaddr”?

If you use an IP address from a private network that doesn’t use DNS, you will have to specify it manually in your script. You can use the IP address that corresponds to the VPN server.

Now for the remote machine’s IP address. If you use a machine that has a static IP address, it will not be available via DNS. If you connect to it via SSH, you’ll need to use the IP address that you see in the command prompt. To do that, you can do a string-based lookup in your Linux command line to get the remote machine’s IP address, which will display in a variable that is on a hidden or hidden variable when you run a command on the Linux command line. To do this, start up a text editor like vi, and start writing a command that will connect to the remote machine via SSH. It would look something like this:

ssh-add -t 2 | ssh -P 2

You are starting a new connection to the remote machine. A text file named ssh-add will start a script called ssh-add that will do something like this:

Let’s start adding some text to the file. Here is a list of the permissions you can give to that file.

$ chmod 0755 ~/.ssh/ubuntu1 1 $ chmod 0755 ~ / .ssh / ubuntu1

Enter “/ssh/ubuntu1” into the text box that appears in the first line of the file. Then enter the text that you created in the text file as well. Enter the text that you just typed in the input field on the command prompt. You’ll want to add all the permissions that you want the file to have. You’ll also want to adjust the permissions so that only the IP address of the VPN server can read or write to the file. Save the file and open it up in a text editor like vi.

To set up port forwarding in Linux.

Now when you connect to your VPN server via SSH, you can set up a port-forwarding file that connects to the IP address of the remote machine. You’ll need to write that down separately. To do that, you can use a text editor like vi. Once you’ve written it, you can use the file system to figure out the IP address of your remote machine, and write it down as well. You can do that by starting up a command prompt and typing:

~/ssh/bin/on-connect “/ssh/ubuntu1” 1 ~ / ssh / bin / on – connect “/ssh/ubuntu1”

Once you’ve figured out the IP address of your remote machine, you can open up a text editor like vim or nano. It’s worth noting that you’ll need to write down the IP address that the remote machine has to the port that you’re connecting to, and that will be available in the port-forwarding file. This will not be the private port-forwarding port, that is defined as the port number of the remote machine. It will be the public port that is defined as the port number of the remote machine that you connect to, which can change over time. When you write down that port number, you’ll have to switch to the port that the VPN server is running on in order to connect.

Right now, it might look like this, but if you try to run the above command on a private port, your terminal will show the error, “Epping IP address that is not a port is not available.” This is because on-connect is a string and a port-forwarding file is only supposed to use on and off. The shell is telling you that that port number that you are trying to use doesn’t exist. Don’t worry about it though. Just change the input variable to look like this:

bind /tty+23 1 bind / TYP + 23

This time you can easily see the correct port number, and you’ll also see an IP address that is on the public network. You can now start connecting to it by typing the IP address into your command prompt.

Now that you know how to do it on a private port, you can use it on the public port as well.

To do that, you’ll need to use the file command to start that file up. You can do that with vi, it’s just a case of pointing to the directory you saved your SSH port-forwarding file. To do that, you’ll use the following command:

$ vi ~/.ssh/ssh-portforwarding ~ /.ssh/ubuntu1 1 $ vi ~ / .ssh / ssh – portforwarding ~ / .ssh / ubuntu1

Once you’ve started up the file, you’ll see that it has two commands in it. The first command is “pport” and the second is “ttt”. The first command is an algorithm that we can use to set up our port-forwarding port, but we’ll leave it for now. The second command sets up the port to a specific port number. By setting a port number like that, it allows you to SSH to your remote machine on the public port, and if you change that port number, you’ll also change the port-forwarding port. Once you set up the port-forwarding port, it will be added to the port-forwarding file, which is defined as the port number that is not on the private IP address.

Once you have set up that port, you’ll need to write that down as well, so that you can use it in the future. You can do that by running the following command in a terminal:

$ vi /.ssh/debian1 1 $ vi / .ssh / debian1

This will generate a file in your home directory called debian1. Since it’s a different port, you’ll need to write that down in order to connect to it in the future.

Right now, you might not be able to connect to your remote machine. That’s because your SSH port is configured to the private IP address that your remote machine has. So, in order to connect, you’ll need to tell your port-forwarding port that it’s on the public IP. You can do that by writing down the port number that you’re using in the file, and also write down your IP address. Doing this will allow you to connect to your remote machine on the public IP.

Once you’ve written down that IP address, you’ll need to do the exact same thing again. You’ll need to tell your SSH port that it’s on the public IP.

On top of the methods that we’ve used in this tutorial, there are other ports that you can use for port forwarding. The most common is port 80, which you’ll need to understand if you’re not using ssh-fd. If you are, you don’t have to understand the whole concept of port forwarding at all.


  • port-forwarding, How to check port-forwarding on Linux?, TechRX

    My name is Biplab Das. I’m the leader of TechRX and Founder of and Professionally I'm a full-time IT support engineer whose childhood obsession with science fiction never quite faded. A quarter-century later, the technology that I coveted as a kid is woven into the fabric of everyday life. People say smartphones are boring these days, but I think everyone is beginning to take this wonderful technology marvel for granted.

Related Articles

Leave a Reply

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

Back to top button