1. You can see which ports are open by "~$ NETSTAT-ANP".
(Note: The parameter '-n ' will turn the application to the port display, that is, the number format of the address, such as: nfs->2049, ftp->21, so you can open two terminals, each corresponding to the program corresponding to the port number)
2. The program that applies the port can then be viewed through the "~$ Lsof-i: $PORT" ($PORT refers to the corresponding port number). Or you can view the file/etc/services, from which you can find the service corresponding to the port.
(Note: Some ports can not be found through the Netstat, more reliable method is "~$ sudo nmap-st-o localhost")
3. To close a port, you can:
Turning off the corresponding application, the port is naturally closed, such as:
"~$ kill-9 pid" (PID: Process number)
such as: Through "~$ NETSTAT-ANP | grep ssh "
Show: TCP 0 127.0.0.1:2121 0.0.0.0:* LISTEN 7546/ssh
Then: "~$ kill-9 7546"
(You can view the open state of the system service through "~$ Chkconfig")