The/* linux of the lower end of the port is maintained by the IANA (internet assigned numbers authority, an internet-assigned numerical authority), and the port number is divided into 3 segments. 1, 0~1023, (10) These ports have IANA allocations and controls, and, if possible, the same port number is assigned to the same given service as TCP, UDP, and SCTP. such as the 80 port is given Web Services 2, 1024~49151, these ports are not controlled by the IANA, but registered by the IANA and provide their use list, has been convenient for the entire group. The same port number is also assigned to TCP and UDP for the same given service. such as the 6000~6003 port is assigned to the X window server for both protocols. 3, 49152~65535, (16) dynamic port. The IANA, regardless of these ports, is what we call a temporary port. (49152 This magic number is 65536 of three-fourths). */#include <iostream>using namespace std;int main () {cout << "POW (2,n ) " << endl;for (int i=0,tmp=1;i<20;i++) {cout<<i<<" "<<tmp< <endl; tmp*=2;} return 0;} /*0 11 22 43 84 165 326 647 1288 2569 51210 102411 204812 409613 819214 1638415 3276816 6553617 13107218 26214419 524288vi /etc/services First Class http://www.linuxidc.com/linux/2007-06/4744.htm1 tcpmux tcp Port Service Multiplexing 5 rje Remote Job Entry 7 echo echo Services 9 discard NULL service for connection testing 11 systat system state for enumerating connected ports 13 daytime send a date and time to the requesting host 17 qotd send the daily Maxim 18 msp message sending protocol to the connected host 19 chargen character generation service; send endless stream of characters 20 ftp-data FTP data ports 21 ftp File Transfer Protocol (FTP) port, sometimes used by File service Protocol (FSP) 22 ssh secure shell (SSH) service 23 telnet telnet Services 25 smtp Simple Mail Transfer Protocol (SMTP) 37 time Time Protocol 39 rlp Resource Location protocol 42 nameserver Internet Name Services 43 nicname WHOIS Directory services 49 tacacs for based tcp/ip authentication and access to the terminal Access Controller access control system 50 re-mail-ck Remote Mail Check protocol 53 domain domain name services (such as BIND) 63 whois++ whois++, extended WHOIS Services 67 bootps Boot Protocol (BOOTP) service ; also used by the Dynamic Host Configuration Protocol (DHCP) service to use 68 bootpc bootstrap (BOOTP) clients, and also by Dynamic Host Configuration Protocol (DHCP) customers 69 tftp Small File Transfer Protocol (TFTP) 70 gopher&nbsP gopher Internet document Search and Retrieval 71 netrjs-1 remote Job Services 72 netrjs-2 Remote Job Services 73 netrjs-3 Remote Job Service 73 netrjs-4 Remote Job Services 79 finger Finger Services for user contact information 80 http Hypertext Transfer Protocol (HTTP) 88 kerberos Kerberos network authentication system for the World Wide Web (WWW) service 95 supdup Telnet Protocol Extensions 101 hostname SRI-NIC hostname service on the machine &NBSP;102&NBSP;ISO-TSAP ISO Development Environment (ISODE) network applications 105 csnet-ns mailbox name servers, also used by CSO name servers 107 rtelnet Remote Telnet 109 pop2 Post Office Protocol version 2 110 pop3 Post Office Protocol version 3 111 sunrpc Remote Procedure Call (RPC) protocol for Remote command execution, used by Network File system (NFS) 113 auth Authentication and identification protocol 115 sftp Secure File Transfer Protocol (SFTP) service 117 uucp-path Unix to Unix Replication Protocol (UUCP) path service &NBSP;119&NBSP;NNTP Network News Transfer Protocol (NNTP) 123 ntp Network Time Protocol (NTP) for the USENET discussion system 137 netbios-ns was samb in Red Hat Enterprise Linux NETBIOS Name Services used by a 138 netbios-dgm used by Samba in Red Hat Enterprise Linux NETBIOS Datagram Services 139 netbios-ssn net used by Samba in Red Hat Enterprise Linux bios Session Services 143 imap Internet Message Access Protocol (IMAP) 161 snmp Simple Network Management Protocol (SNMP) 162 snmptrap snmp Traps 163 cmip-man General Management Information Protocol (CMIP) 164 cmip-agent General Management Information Protocol (CMIP) 174 mailq MAILQ 177 xdmcp X Display Manager Control Protocol 178 nextstep NeXTStep Windows Server 179 bgp Boundary Network protocol 191 prospero Cliffod Neuman Prospero Services 194 irc Internet Relay Chat (IRC) 199 smux SNMP UNIX multiplexing 201 at-rtmp AppleTalk routing 202 at-nbp AppleTalk name binding 204 at-echo appletalk echo Services 206 at-zis AppleTalk block Information 209 qmtp Fast Mail Transfer Protocol (QMTP) 210 z39.50 niso z39.50 database 213 ipx Internetwork Packet Switching Protocol (IPX), by Novell Netware Common Datagram Protocol for Environment 220 imap3 Internet Message Access Protocol version 3 245 link link 347 fatserv fatmen Server 363 rsvp_tunnel RSVP tunnel 369 rpc2portmap Coda file System port mapper 370 codaauth2 Coda File System Validation Service 372 ulistproc unix listserv 389 ldap Lightweight Directory Access Protocol (LDAP) 427 svrloc Service Location Protocol (SLP) 434 mobileip-agent Removable Internet Protocol (IP) proxy 435 mobilip-mn removable Internet Protocol (IP) Manager 443 https Secure Hypertext Transfer Protocol (HTTP) 444 snpp Small Network Paging protocol 445 microsoft-ds Server Message Block (SMB) 464 through TCP/IP kpasswd kerberos Password and key change service 468 photuris Photuris session Key Management Protocol 487 saft Simple Asymmetric file Transfer (SAFT) protocol 488 gss-http Universal Security Services for HTTP (GSS) 496 pim-rp-disc Rendezvous point Discovery for Protocol Independent Multicast (PIM) services (RP-DISC) &NBsp;500 isakmp Internet Security Association and Key Management Protocol (ISAKMP) 535 iiop Internet Internal Object Request Proxy Protocol (IIOP) 538 gdomap gnustep Distributed Object Mapper (GDOMAP) 546 dhcpv6-client Dynamic Host Configuration Protocol (DHCP) version 6 customers 547 dhcpv6-server Dynamic Host Configuration Protocol (DHCP) version 6 service 554 rtsp real-time Streaming Protocol (RTSP) 563 nntps Network News Transfer Protocol (NNTPS) 565 whoami whoami 587 submission mail message submission agent (MSA) through Secure Sockets Layer 610 npmp-local Network Peripheral Management Protocol (NPMP) local / distributed queuing System (DQS) 611 npmp-gui Network Peripheral Management Protocol (NPMP) GUI / Distributed Queueing System (DQS) 612 hmmp-ind HMMP indication / DQS 631 ipp Internet Printing Protocol (IPP) 636 ldaps Lightweight Directory Access Protocol via Secure Sockets Layer (LDAPS) 674 acap application Configuration Access Protocol (ACAP) 694 ha-cluster "Kadmin" Database Management for Heartbeat Services 749 kerberos-adm Kerberos version 5 (v5) for clusters with high availability 750 kerberos-iv Kerberos version 4 (v4) Services 765 webster Network Dictionaries 767 phonebook Network Phone book 873 rsync rsync File Transfer service 992 telnets telnet via Secure Sockets Layer (Telnets) 993 imaps Internet Message Access Protocol via Secure Sockets Layer (IMAPS) 994 ircs Internet Relay Chat via Secure Sockets Layer (IRCS) 995 pop3s Post Office Protocol version 3 (POPS3) through Secure Sockets Layer linux*/
Prerequisite: First you must know that the port is not independent, it is dependent on the process. When a process is turned on, its corresponding port is turned on and the process shuts down, and the port is closed. The next time a process is turned on again, the corresponding port is turned on again. Instead of purely understanding that a port is closed, you can disable a port.
1. "~$ NETSTAT-ANP" can be used to see which ports are open.
(Note: The parameter '-n ' will convert the application to port display, that is, the address of the number format, such as: nfs->2049, ftp->21, so you can open two terminals, one for each corresponding to the port number of the program)
2. The program that applies the port can then be viewed by "~$ 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 that corresponds to the port.
(Note: Some ports cannot be found through Netstat, the more reliable method is "~$ sudo nmap-st-o localhost")
3. To close a port, you can:
1) Disable the port via the Iptables tool, such as:
"~$ sudo iptables-a input-p tcp--dport $PORT-j DROP"
"~$ sudo iptables-a output-p tcp--dport $PORT-j DROP"
2) or turn off the corresponding application, the port will naturally shut down, such as:
"~$ kill-9 pid" (PID: Process number)
such as: Through "~$ NETSTAT-ANP | grep ssh "
There is a display: TCP 0 127.0.0.1:2121 0.0.0.0:* LISTEN 7546/ssh
Then: "~$ kill-9 7546"
("~$ chkconfig" can be used to view the open state of the system service.)
Http://www.3lian.com/edu/2015/08-06/236829.html
LINUX port number and POW (2,n) Table