#How to close a port under Linux system, this article mainly shares with you, I hope it can help you.
Each port has a daemon process, just kill the daemon process
Every Each port is occupied by a process.
The first step is to use the following command
netstat -anp |grep port
Find out the process occupying this port,
Second step, use the following command
kill -9 PID
Just kill it
Because each port has a corresponding service, so to close the port, you only need to close the corresponding service.
Services that are automatically started at boot in Linux are generally stored in two places:
Services under the /etc/init.d/ folder:
The services in this folder can be started or shut down by running the corresponding SCRIPT.
For example: start the sendmail service: ./sendmail start (opens the TCP 25 port)
Close the sendmail service: ./sendmail stop (closes the TCP 25 port)
View the current status of the sendmail service Status: ./sendmail? status (check whether the service is running)
Services under the /etc/xinetd.d/ folder:
The services under this folder need to be changed Service configuration file and restart xinetd.
For example: To start the auth service, open the /etc/xinetd.d/auth configuration file, change "disable=no", save and exit.
Run /etc/rc.d/init.d/xinetd restart
To stop the auth service, open the /etc/xinetd.d/auth configuration file and change "disable=yes ”, save and exit.
Run /etc/rc.d/init.d/xinetd restart
The method introduced below can be used under Linux commands, which is very simple .
Open the port as:
iptables -A INPUT -p $port -j ACCEPT
Just change ACCEPT to DROP, that is:
iptables -A INPUT -p $port -j DROP
where $port is the port number, the specific usage of iptables can be.
The above is the detailed content of Three ways to close Linux system ports. For more information, please follow other related articles on the PHP Chinese website!