Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

The relationship between LINUX port and service

2025-03-18 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >

Share

Shulou(Shulou.com)06/01 Report--

This article introduces the knowledge of "the relationship between LINUX port and service". Many people will encounter such a dilemma in the operation of actual cases, so let the editor lead you to learn how to deal with these situations. I hope you can read it carefully and be able to achieve something!

I. the relationship between ports and services

The correspondence between the port number and the corresponding service is stored in the / etc/services file, where most of the ports can be found. Use the netstat command

The service name displayed is also found in this file. Some people say that by commenting out the corresponding port number in this file, you can disable the port.

I tried, but it didn't work. This method should be useless. It's misinformation. The only purpose of commenting out the corresponding port number is to use netsat

Command, instead of displaying the service name (such as ftp), it will display the port number (such as 21). The principle is also simple: netstat cannot be found in / etc/services

The service name corresponding to the port number is found in the file, and naturally it cannot be displayed. So the / etc/services file only serves as the port number and the corresponding service

Mapping has nothing to do with the startup and shutdown of the port!

Second, check the open ports of this machine.

1. Netstat to view ports and connections

Netstat lists the names of services that are currently connected

Netstat-a lists the names of services that are currently connected and being monitored

Netstat-an lists the port numbers that are currently connected and being monitored (the same as the command function above, except that the service name corresponding to the port number is not explained)

Netstat-ap lists the PID (process number) of the connection based on the above command. With this PID, you can use KILL to kill the connection.

For example: a connected PID=111, if you want to kick it out, use KILL-9 111. Ok!

Netstat-rn output routing tabl

2 、 nmap

Nmap 127.0.0.1 View the ports open on this machine and scan all ports

Nmap-p 1024 65535? 127.0.0.1 scan designated port range

Nmap-PT 192.168.1.1-111? Scan a range of computers

Close and open the port (service)

How to close the port:

1. Because each port has a corresponding service, to shut down the port, you only need to turn off the corresponding service.

2. Restrict the port with IPTABLE, so that the port can not be accessed, but the port itself is not closed.

Only the method of shutting down the service is introduced here, and the application of IPTABLE will be discussed later.

The services that start automatically in linux are generally stored in two places:

Services under / etc/init.d/ folder:

All services in this folder can be started or shut down by running the corresponding SCRIPT.

For example: start the sendmail service. / sendmail start (TCP port 25 is open)

Shut down the sendmail service. / sendmail stop (close TCP port 25)

View the current status of the sendmail service. / sendmail? Status (check whether the service is running)

Services under / etc/xinetd.d/ folder:

The services under this folder need to be changed by changing the service configuration file and restarting xinetd.

For example: to start the auth service, open the / etc/xinetd.d/auth configuration file, change "disable=no", and save exit. Run / etc/rc.d/init.d/xinetd restart

To stop the auth service, open the / etc/xinetd.d/auth configuration file, change "disable=yes", and save exit. Run / etc/rc.d/init.d/xinetd restart

Fourth, control the service that starts automatically.

The control service switch method mentioned above operates after starting linux. If I want to control which services are started and which services are turned off when linux starts, how to do it.

There are three ways to control the automatic startup of the service:

1. Change the corresponding folder under / etc/rc.d:

If the default interface for your login is the character interface, change the rc.3 folder, and if the login interface is graphical by default, modify rc.5.

In the folder, the name of each service is preceded by "K" or "S". S means that the service starts up and runs automatically. Delete it or change its prefix to "K" and it will not start next time.

2. Use the ntsysv command:

Enter the ntsysv command and a list of services will appear. If you need to start, type "*". It's simple.

3. Use the chkconfig command:

Let a service not start automatically: for example, httpd:chkconfig-- level 35 httpd? Off; 35 refers to the run level

Let a service start automatically: for example, httpd:chkconfig-- level 35 httpd? On

Check the startup status of all services: chkconfig-- list

View the startup status of a service: chkconfig-- list | grep httpd

This is the end of the content of "the relationship between LINUX Ports and Services". Thank you for reading. If you want to know more about the industry, you can follow the website, the editor will output more high-quality practical articles for you!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Servers

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report