Search code examples
portiptablesnetstat

How to read netstat ports?


I did the netstat -tulpn | grep listen and had the next results:

tcp        0      0 0.0.0.0:22              0.0.0.0:*               LISTEN      14901/sshd          
tcp        0      0 127.0.0.1:25            0.0.0.0:*               LISTEN      1011/exim4          
tcp        0      0 127.0.0.1:5000          0.0.0.0:*               LISTEN      826/ang
tcp6       0      0 :::80                   :::*                    LISTEN      655/apache2         
tcp6       0      0 :::22                   :::*                    LISTEN      14901/sshd          
tcp6       0      0 ::1:25                  :::*                    LISTEN      1011/exim4          
tcp6       0      0 :::443                  :::*                    LISTEN      655/apache2         

How can you close a port? Does this configuration have any security issue?


Solution

  • The 1st part of the question - How to close the port ?

    You can stop the service listed in the last column, or kill it. Stopping the service makes sure it wont start again on its own. Killing the service means some other process like upstart might start it up again.

    The 2nd part of the question - Does this have a security issue ?

    I would say yes, unless you have some firewall and access control mechanism in place. The reason is that the ssh service is listening for connections from any source. Ideally, you would restrict this on the firewall (or in the ssh config) and only allow known sources to connect. If you want to go one step further, make ssh listen on another port than the default port (22) so that you can avoid being seen by the most basic/common scanners. I only mention ssh as an example. You will need to review this periodically for any more software/services you deploy on that machine.