Linux View port usage status, shutdown port method

Source: Internet
Author: User

First you must know that the port does not exist independently, it is dependent on the process. When a process is turned on, its corresponding port is turned on and the process shuts down, and the port is closed. The next time a process is turned on again, the corresponding port is turned on again. Instead of purely understanding that a port is closed, you can disable a port.

1. You can use

Netstat-anp

To see which ports are open.
(Note: The parameter '-n ' will convert the application to port display, that is, the address of the number format, such as: nfs->2049, ftp->21, so you can open two terminals, one for each corresponding to the port number of the program)


2. You can then pass

Lsof-i: $PORT

Check the program that applies the port ($PORT refers to the corresponding port number) or you can view the file/etc/services, from which you can find the service that corresponds to the port.

3. To close a port, you can:
1) Disable the port via the Iptables tool, such as:

sudo iptables-a input-p tcp--dport $PORT-j dropsudo iptables-a output-p tcp--dport $PORT-j DROP

  

2) or turn off the corresponding application, the port will naturally shut down, such as:

Kill-9 PID (PID: Process number)

such as: Through

NETSTAT-ANP | grep ssh

have shown:

TCP 0 127.0.0.1:2121 0.0.0.0:* LISTEN 7546/ssh

The

Kill-9 7546

("~$ chkconfig" can be used to view the open state of the system service.)

Linux View port usage status, shutdown port method

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.