Linux ports and sockets

port

Linux port is a logical concept, content transport layer protocol, which is defined by the TCP / IP protocol, an 0-65535 16-bit integer between a 2-byte.

Port number (port) used to identify a process, a process which tells the operating system to the current data to be processed, IP address and port number can identify a particular process to a host on a network; a process that can be bound multiple port numbers, but a port number can not be bound multiple processes, a port number can only be occupied by one process.

The transport layer protocol (TCP and UDP) data segment has two port numbers, are called source port number and destination port number is describing "who made the data to be sent to anyone."

Port number range is divided

  • 0--1023: "fixed" port, refer to the identification and publication of some commonly used software or TCP / IP protocol, in general, it will not be used by other programs.
  • 1024--65535: The operating system dynamically assigned port numbers, port number of the client program is assigned by the operating system from this range.

Linux in common "fixed" port and the corresponding protocol

protocol The port number
FTP 21
TELNET 23
TFTP 69
SNMP 161
SSH 22
HTTP 80
SMTP 25
DNS 53
HTTPS 443

The following command can be used to view the "fixed" port

cat /etc/services

netstat
netstat is an important tool used to view network status.
Syntax : netstat [options]
Function : View network status
common options :

  • n alias rejection display can show all converted to a digital number
  • l Only lists service status in Listen (listen) of
  • p display program name to establish relevant links
  • t (tcp) only show tcp related options
  • u (udp) shows only relevant options udp
  • a (all) to display all the options, not displayed by default LISTEN related options

pidof
view the server's process id.
Syntax : pidof [process name]
Function : The process name, process id view

Sockets

Sockets (Sockets), which is the process network process ID, and the general process different ID, network ID process is composed of the port (Port) used by the IP address of the computer running this process, and this process, in the same on the computer, a port can only be assigned to a process, so that you can establish a process on a computer network.

The composition of the socket

Here Insert Picture Description
You can use netstat-all command to view the current sockets and ports on your system network application process.

Linux socket includes INET BSD socket and the socket in two parts.

BSD socket interface is based Linux socket, the socket can be regarded as a special pipe, BSD sockets typically include the following types:

  • The Steam (data stream): The socket provides a sequence of data flow in both directions, these data streams to ensure no data is lost during transmission, without damaging or duplicate, data streams from the sockets Internet (INET) address family the TCP protocols supported.
  • Datagram (datagrams): This socket is also provided a data transfer in both directions, but unlike data stream socket, they do not provide guaranteed message arrived. It does not arrive even if these packets arrive to ensure a certain order (or loss, duplication). This type of socket supported by the UDP protocol Internet address family.
  • Raw (raw socket): This socket allows processes direct access to the underlying protocol. For example, to open a Raw Socket Ethernet devices to use the original IP for transmission.
  • Reliable Delivered Message (reliable message delivery): the socket is a datagram socket is very similar, but can ensure reliable data transmission.
  • Sequenced Packets (datagrams order): the socket similar to the socket stream, the packet size is fixed.
  • Packet (packet): This is not a standard BSD socket type, which is a Linux-specific extensions to allow direct access to the process equipment in the Packet layer.

The most commonly used in the Linux Network Programming TCP protocol is supported by the data stream socket, UDP protocol support datagram sockets and raw format of the underlying protocol IP sockets can be accessed directly.

Published 70 original articles · won praise 131 · views 20000 +

Guess you like

Origin blog.csdn.net/qq_43239560/article/details/102938976