Home > Operation and Maintenance > Linux Operation and Maintenance > Three ways to close Linux system ports

Three ways to close Linux system ports

小云云
Release: 2018-03-29 17:22:49
Original
56199 people have browsed it


#How to close a port under Linux system, this article mainly shares with you, I hope it can help you.

1. Close the port by killing the process

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

2. Open the service by opening and closing the service /Close port

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

3. Restrict ports through the firewall

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!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template