How to view port usage status and disable ports in Linux

Source: Internet
Author: User

Http://blog.csdn.net/wudiyi815/article/details/7473097

Premise: First, you must know that a port does not exist independently and is attached to a process. If a process is enabled, the corresponding port is enabled. if the process is disabled, the port is closed. If a process is enabled again next time, the corresponding port is enabled again. Rather than simply disabling a port, you can disable it.

1. You can use "~ $ Netstat-ANP "to check which ports are opened.
(Note: adding the '-n' parameter will applyProgramSwitch to port display, that is, address in digital format, such as NFS-> 2049, ftp-> 21. Therefore, you can enable two terminals to correspond to the port number of the program one by one)
2. Then you can use "~ $ Lsof-I: $ port "to view the program that applies this port ($ port indicates the corresponding port number ). You can also view the/etc/services file to find the service corresponding to the port.
(Note: Some ports cannot be found through netstat. The more reliable method is "~ $ Sudo NMAP-St-o localhost ")
3. to disable a port, you can:
1) disable the port through iptables, for example:
"~ $ Sudo iptables-A input-p tcp -- dport $ port-J Drop"
"~ $ Sudo iptables-A output-p tcp -- dport $ port-J Drop"
2) or shut down the corresponding application, the port is closed, for example:
"~ $ Kill-9 PID "(PID: process ID)
For example "~ $ Netstat-anp | grep ssh"
Displayed: TCP 0 127.0.0.1: 2121 0.0.0.0: * Listen 7546/ssh
Then :"~ $ Kill-9 7546"

(You can use "~ $ Chkconfig "view the activation status of system services)

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.