How to open a port in Linux

Secure connection of network nodes and exchange information between them directly associated with open ports. Connection and traffic transfer is made through a specific port, and if it is closed, to execute such a process will not be possible. Because of this, some users are interested in forwarding one or more rooms for the setup of interaction devices. Today we show you how to perform the task in operating systems based on Linux kernel.

Open ports in Linux

Though in many distributions by default there is a built in tool for managing networks, all such decisions are often not able to fully implement the setting of the open ports. The instructions in this article will be based on the additional application called Iptables — a solution to edit the firewall settings using superuser rights. All builds of the OS on Linux it works the same, except that different command for mounting, but we’ll talk about that below.

If you want to know which of those ports are already open on your computer, you can use the built-in or additional console tool. Detailed instructions on how to find the necessary information you will find in our other article, clicking on the following link, and we begin step-by-step analysis of open ports.

Read more: Viewing open ports in Ubuntu

Step 1: Install Iptables and viewing rules

The Iptables utility is not natively included with the operating system, which it need to install from the official repository, and then to work with the rules and try to change them. Installation does not take much time and is accomplished through the standard console.

  • Open the menu and run “Terminal”. To do this, it is also possible, using standard hotkey Ctrl + Alt + T.
  • Distributions based on Debian or Ubuntu, write sudo apt install iptables to start the installation and Assembly based on Fedora sudo yum install iptables. After entering press Enter.
  • Activate root by writing the password of your account. Please note that the symbols while you type are not displayed, this is done for security.
  • Wait for it to complete installations and can make sure activity, after reviewing a standard list of rules, using sudo iptables-L.
  • As you can see, in the distribution, now there is a team of iptables, responsible for the management of the eponymous utility. Again, what does this tool from superuser rights, so the string must contain the prefix sudo, and then the other values and arguments.

    Step 2: Permit data exchange

    No ports are not working properly, if it prohibits the exchange of information with their own firewall rules. In addition, the lack of necessary regulations in the future may cause various errors when forwarding, so we strongly suggest you to do the following:

  • Make sure that the configuration file does not have any rules. Best to immediately write the command to remove them, but it looks like this: sudo iptables-F.
  • Now add a rule to the input data on the local computer by inserting the line sudo iptables -A INPUT-i lo -j ACCEPT.
  • About the same command — sudo iptables -A OUTPUT-o lo -j ACCEPT — responsible for a new rule to send the information.
  • It remains only to ensure the normal interaction between the above-mentioned rules so the server can send back the packages. For this it is necessary to prohibit new connections and old ones to allow. Made it through sudo iptables -A INPUT -m state --state ESTABLISHED,RELATED-j ACCEPT.
  • The above-mentioned parameters you have provided the correct sending and receiving data, which will allow you to communicate with the server or another computer. You only have to open ports, through which will be implemented by the interaction.

    Step 3: Open the necessary ports

    You are already acquainted with the principle on which adds new rules to the Iptables configuration. There are several arguments that allow certain ports to be open. Let us explain this procedure on the example of popular port numbers 22 and 80.

  • Start the console and type the following two commands:

    sudo iptables -A INPUT -p tcp --dport 22 -j ACCEPT
    sudo iptables -A INPUT -p tcp --dport 80 -j ACCEPT

  • Now check the list of rules to ensure that the ports have been successfully propolene. Is used for this familiar command sudo iptables-L.
  • Give it a readable form and bring all the details you can use the optional argument, then the string will be like this: sudo iptables-nvL.
  • Change policy on a standard using sudo iptables-P INPUT DROP and I can get to work between nodes.
  • In the case when the administrator of the computer has made its own rules in the tool, organized relief packages at the approach to the point, for example, using sudo iptables -A INPUT -j DROP, you need to use another command sudo iptables: -I INPUT -p tcp --dport 1924-j ACCEPTwhere 1924 — the port number. It adds the necessary port in the beginning of the chain, and then the packets are discarded.

    Then you can prescribe the same line of sudo iptables-L and make sure that everything is configured correctly.

    Now you know how propisyvayutsya ports on Linux operating systems, for example, additional utility Iptables. We recommend to follow the emerging lines in the console when typing commands, it will help to detect any errors and eliminate them quickly.


    (Visited 36 times, 1 visits today)