(Zz) how to check the port usage status and disable the port in Linux

Source: Internet
Author: User
1. you can use ~ $ Netstat-anp to check which ports are opened. (Note: adding parameter-n will convert the application to Port display, that is, address in digital format, such as: nfs-2049, ftp-21, so you can enable two terminals, 1 corresponds to the port number corresponding to the program) 2. then you can use ~ $ Lsof-I: $ PORT "~ $ Netstat-anp "to check which ports are opened.
(Note: adding the '-n' parameter will convert the application into a port display, that is, a digital address, such as nfs-> 2049, ftp-> 21, therefore, you can enable two terminals to correspond one by one to the corresponding port number of the program)
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 "~ $ Sudonmap-sT-Olocalhost ")
3. to close a port, you can:
1) pass IptablesTool to disable this port, such:
"~ $ Sudoiptables-AINPUT-ptcp -- dport $ PORT-jDROP"
"~ $ Sudoiptables-AOUTPUT-ptcp -- dport $ PORT-jDROP"
2) or shut down the corresponding application, the port is closed, for example:
"~ $ Kill-9PID "(PID: Process ID)
For example "~ $ Netstat-anp | grepssh"
Display: tcp0127.0.0.1: 21210.0.0.0: * LISTEN7546/ssh
Then :"~ $ Kill-97546"

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

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.