Find the service name corresponding to the port number in linux
Search for the corresponding service name 1) grep-w port number/etc/services 2) grep "\ B port number \ B"/etc/services. Port 2049 is used as an example, run grep-w 2049/etc/services or grep "\ b2049 \ B"/etc/services to find the corresponding service named nfsgrep-w 2049/etc/services nfs 2049/ tcp nfsd shilp # Network File Systemnfs 2049/udp nfsd shilp # Network File Systemnfs 2049/sctp nfsd shilp # Network File System # grep "\ b2049 \ B"/etc/services nfs 2049/ tcp nfsd shilp # Network File Systemnfs 2049/udp nfsd shilp # Network File Systemnfs 2049/sctp nfsd shilp # Network File System where-w indicates that only columns with full-word matching are displayed, that is, exact match; "\ B" indicates matching a word boundary, that is, the position between the word and the space. For example, "er \ B" matches "er" in "never ", but it does not match "er" in "verb" (if it matches "er" in "verb", "\ B" can be used for non-word boundary matching ). Find the corresponding port number based on the service name. 1) grep-w service name/etc/services2) grep "\ B service name \ B"/etc/services. The nfs service is used as an example, run grep-w nfs/etc/services or grep "\ bnfs \ B"/etc/services to find the corresponding port number 2049 # grep-w nfs/etc/services nfs 2049/tcp nfsd shilp # Network File Systemnfs 2049/udp nfsd shilp # Network File Systemnfs 2049/sctp nfsd shilp # Network File System # grep "\ bnfs \ B"/etc/services nfs 2049/tcp nfsd shilp # Network File Systemnfs 2049 /Udp nfsd shilp # Network File Systemnfs 2049/sctp nfsd shilp # Network File System where-w indicates that only the columns that match the full word are displayed, that is, exact match; "\ B" indicates matching a word boundary, that is, the position between the word and the space. \ Bnfs \ B exactly matches nfs.