Disable and enable Linux ports

Source: Internet
Author: User
In Linux, there seems to be no command to directly enable or disable the port, because if you only enable the port and do not associate it with the process, enabling and disabling a port makes no sense (when a port is opened, no program processes the incoming data ). That is to say, the port in Linux is active... linux does not seem to have any command to directly enable or disable the port, because if you only enable the port and do not associate it with the process, enabling and disabling a port makes no sense (when a port is opened, no program processes the incoming data ). In other words, the port activity in Linux is closely linked to the process. if you want to disable a port, you only need to kill the corresponding process.
 
 
 
For example, to disable port 22:
 
 
 
$ Netstat-anp | grep: 22
Tcp 0 0 0.0.0.0: 22 0.0.0.0: * LISTEN 1666/sshd
 
 
#-A displays all active TCP connections and the TCP and UDP ports being monitored
 
#-N represents the address and port number in the form of numbers, and does not try to parse its name (number)
 
#-P: list the processes related to Port listening or connection (you need to pay attention to them here) (pid)
 
 
 
Knowing the process ID 1666 corresponding to port 22, as long:
 
$ Killed 1666
You can.
 
 
 
The "-p" option requires attention to a permission issue. if you execute the netstat command in the shell logged on by a common user, you can only list the processes that have the permission of this common user, if you want to see all the ports, it is best to switch to the root.
 
 
 
The following are some common netstat options:
 
 
 
$ Netstat-tn # list the connection statuses of all TCP protocols
 
 
#-T only displays the TCP-related connection and Port listening status. Note that it is different from-a (tcp)
 
 
 
$ Netstat-tuln # list the port listening statuses of all inet address classes

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.