(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)
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.