Linux ports and services

Source: Internet
Author: User

I. Relationship between ports and services
The correspondence between the port number and the corresponding service is stored in the/etc/services file. Most ports can be found in this file. Use the netstat command
The displayed service name is also found in this file. Some people say that they can disable the port by comment out the corresponding port number in this file.
I tried it but it didn't work. This method should be useless, but it was a false positive! Comment out the corresponding port number. The only function is to use netsat.
Command, the service name (such as FTP) is not displayed but the port number (such as 21 ). The principle is also very simple: netstat cannot be in/etc/services
Find the service name corresponding to the port number in the file, and it cannot be displayed. Therefore, the/etc/services file only serves as the port number and corresponding service
Ing relationship, which is irrelevant to the start and close of the port!
2. view the ports opened on the local machine
1. view the port and connection with netstat
Netstat lists the currently connected service names
Netstat-A lists the currently connected and monitored service names
Netstat-An lists the currently connected and listening port numbers (just like the above command function, but does not explain the service name corresponding to the port number)
Netstat-AP lists the connected PID (process number) Based on the above command. With this PID, you can use kill to kill the connection.
For example, if the PID of a connection is 111, kill-9 111 is used if you want to kill the connection. OK!
Netstat-Rn output route table
2. NMAP
NMAP 127.0.0.1: view the ports opened on the local machine and scan all ports
NMAP-P 1024 65535? 127.0.0.1 scan specified port range
Does NMAP-Pt 192.168.1.1-111? Scan a group of computers
3. Close and enable ports (services)
How to disable a Port:
1. Because each port has a corresponding service, you only need to close the corresponding service to close the port.
2. Use iptable to restrict the port so that the port is not accessed, but the port is not closed.
Here we will only introduce how to disable the service. We will discuss the application of iptable later.
The services automatically started in Linux are generally stored in two places:
Services in the/etc/init. d/folder:
Services in this folder can be started or closed by running the corresponding script.
For example, start sendmail service./sendmail start (TCP port 25 is enabled)
Disable sendmail service./sendmail stop (disable TCP port 25)
View the current status of the sendmail service./sendmail? Status (check whether the service is running)
Services in the/etc/xinetd. d/folder:
Services in this folder must 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", save and quit. Run/etc/rc. d/init. d/xinetd restart
To stop the auth service, open the/etc/xinetd. d/auth configuration file, change "Disable = yes", save and exit. Run/etc/rc. d/init. d/xinetd restart
4. control services automatically started upon startup
The Control Service switch method mentioned above is performed after Linux is started. If I want to control which services are started and which services are closed during Linux Startup
There are three methods to control automatic service startup:
1. Change the corresponding folder under/etc/rc. d:
If the default logon interface is a character interface, modify the RC.3 folder. If the logon interface is a graphical interface by default, modify rc.5.
In the folder, each service name is prefixed with "K" or "S". s indicates that the service runs automatically upon startup, delete it or change the prefix to "K" and it will not start next time.
2. Run the ntsysv command:
Enter the ntsysv command, and a service list will appear. You need to start "*", which is simple.
3. Run the chkconfig command:
Disable Automatic startup of a service. For example, httpd: chkconfig -- level 35 httpd? Off; 35 indicates the running level.
Enable a service to start automatically, for example, httpd: chkconfig -- level 35 httpd? On;
View the startup status of all services: chkconfig -- list
View the startup status of a service: chkconfig -- list | grep httpd

The port and service operations are here.


Reprinted from: http://www.jb51.net/LINUXjishu/10954.html

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.