first, port and service relationships
The corresponding relationship between the port number and the corresponding service is stored in the/etc/services file, where most of the ports are found. Using the netstat command
The name of the service displayed is also found from this file. Some people say that you can disable the port number in this file by commenting out the corresponding port numbers.
I tried but did not work, this method should be no use, is misinformation! Comment out the corresponding port number, the only function is to use the Netsat
command, the service name (such as FTP) is not displayed, but the port number (for example, 21) is displayed. The principle is simple: netstat cannot be/etc/services
The service name corresponding to the port number found in the file is naturally not visible. So the/etc/services file is just the port number and the corresponding service
The mapping relationship is not related to the start and shutdown of the port!
Second, to view the port open to the machine
1. Netstat view ports and connections
Netstat lists the service names that are currently connected
NETSTAT-A lists the service names that are currently connected and listening
Netstat-an lists the port numbers that are currently connected and listening (like the command function above, but do not explain the service name of the port number)
Netstat-ap on the basis of the above command lists the connected PID (process number), with this PID, you can use Kill to kill the connection
For example: a connected pid=111, want to kick out on the use of KILL-9 111. Ok!
NETSTAT-RN Output Routing Table
Nmap 127.0.0.1 View the port that is open on this machine, scan all ports
Nmap-p 1024 65535? 127.0.0.1 Scan Specifies port range
Nmap-pt 192.168.1.1-111? Scan a range of computers
Iii. Closing and opening ports (services)
Ways to close ports:
1, because each port has the corresponding service, therefore closes the port as long as closes the corresponding service to be possible.
2, using iptable to limit the port, so that the port can not be accessed, but the port itself has not been closed.
Here only the method of shutting down the service is introduced, the application of iptable is discussed later.
Linux boot autostart services are generally stored in two places:
Services under the/etc/init.d/folder:
The services under this folder can be started or closed by running the appropriate script.
For example: Start the SendMail service./sendmail Start (TCP 25 port is turned on)
Turn off the SendMail service./sendmail Stop (TCP 25 port off)
View the current status of the SendMail service./sendmail? Status (to see if the service is running)
Services under the/etc/xinetd.d/folder:
The services under this folder need to be changed by changing the service profile and restarting the xinetd.
For example: To start the Auth service, open the/etc/xinetd.d/auth configuration file, change "Disable=no", and save the 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 the exit. Run/etc/rc.d/init.d/xinetd restart
Four, control the boot automatically start service
The above Control Service switch method is operated after starting Linux, if I want to control which service starts and which services are closed when Linux starts
There are 3 ways to automatically start the Control service:
1, change/etc/rc.d under the corresponding folder:
If you login to the default interface is the character interface, then modify the Rc.3 folder, if the login interface default is a graphical interface, then modify the rc.5.
In the folder, each service name preceded by "K" or "s", S on behalf of the service automatically run, delete it or prefix to "K" will not start the next time.
2. Use NTSYSV command:
To enter the NTSYSV command, a list of services will appear, which needs to be started by playing "*", simple.
3. Use chkconfig command:
Let a service not start automatically: for example Httpd:chkconfig--level httpd? Off; 35 refers to the run level
Get a service to start automatically: for example Httpd:chkconfig--level httpd? On;
To view the startup status of all services: Chkconfig--list
To view the startup status of a service: Chkconfig--list |grep httpd
Port and service operation here it is.