ComputersSoftware

How to open a port in Linux and what to check already open?

Ports in any system located in a common network hierarchy, play the role of connecting elements. Knowing which one is open or closed, an application from one node can send a message to the same application on the other. Why and how you can open the port in Linux, this article will tell.

A bit of theory

The port is expressed by a number from 0 to 65535. Many values are registered for service needs, some can be used arbitrarily. The port specifies a specific refinement of the address. For example, some resource has a web server running.

To know exactly where to turn, the computer requesting information from it must know at least IP. But if the resource has several different services, how do you know where to send the request? That's where the port comes in handy. Knowing its number, the computer, using the IP address and port, can accurately send a request to the server.

Difficulties in work

Due to the fact that many programs using ports are not always ideal in terms of security, an open port can be a potentially vulnerable place for penetration and unauthorized access. Therefore, you need to monitor the use of ports in the system or in some way to monitor their traffic.

List of most popular port values

The range of numbers from 0 to 1023 is for use by system programs and applications:

  • 21 - used by the FTP data transfer protocol;
  • 22 - SSH secure shell service;
  • 23 - Telnet;
  • 25 - the protocol for the transmission of e-mail messages;
  • 80 - transmission of HTTP traffic. Used by web servers;
  • 110 - POP3 (another mail protocol).

These values are reserved and are used by the system by default. Many of the remaining ports can be used at their discretion.

How in Linux to check open ports

To do this, there are built-in tools. They show which ports are open in Linux. The first of these is netstat.

An example of its use: sudo netstat -ntulp

The set of keys following the command itself represents additional parameters:

  • -l. Means that you need to show only those ports that are currently being listened;
  • -p. More detailed reflection of information about the application that uses the port. In particular, its name and process ID will be displayed;
  • -t. Include ports in the TCP list;
  • -u. The same, only with UDP;
  • -n. Means that IP addresses will be shown as numbers.

How to open a port in Linux

This procedure may be needed during the development of a web application that has communication with an external server. Before opening the port, you must first check whether it is already open. This will be helped by the procedure presented above.

The iptables utility is used for opening. To check if it exists at all in the system, you need to type the following command in the console: iptables --list

As a result, the output will be displayed, indicating that the utility is running and is present in the system. Now it remains to open the port in Linux. To do this, use the command:

Iptables -A INPUT -p tcp -m tcp --dport 53 -j ACCEPT

Here, key A means that you need to add a new rule to the existing chain. INPUT indicates that the open port will be incoming. The -p switch says that the protocol type is specified, in this case TCP. Dport means the port of destination, here - 53. Well, ACCEPT - allowing connections.

In fact, iptables have much more keys, which opens up wide possibilities for more fine-tuning and ways to open the port in Linux.

Similar articles

 

 

 

 

Trending Now

 

 

 

 

Newest

Copyright © 2018 en.unansea.com. Theme powered by WordPress.