
对于 Linux 系统管理员来说,清楚某个服务是否正确地绑定或某个端口,是至关重要的。如果你需要处理端口相关的问题,这篇文章可能会对你有用。
被动模式下,server使用port命令告诉客户端,它用那个端口,然后客户端发起对他的数据传输,所以这对于一个防火墙来说就是比较麻烦的事情,因为有可能会有new状态的数据包,但是它又是合理的请求,这个时候就用到这个related状态了,他就是一种关联,在linux中,有个叫ftp_conntrack的模块,它能识别port命令,然后对相应的端口进行放行。使用tcp232-test软件,将gprs模块的串口连接到电脑串口,例子电脑串口为com5,调试软件右边协议类型设置为tcp server ,本地ip填写电脑自身的ip地址:192.168.0.120.本地端口为刚才在路由器上映射的端口23419.点击开始。这款软件是由java编写的,所以在运行软件之前需要事先安装java环境,cmd窗口是告诉我们此时软件正在8008端口。
套接字是和 IP 地址、软件端口和协议结合起来使用的,而端口号对传输控制协议(TCP)和用户数据报协议(UDP)协议都适用,TCP 和 UDP 都可以使用 0 到 65535 之间的端口号进行通信。
以下是端口分配类别:
在 Linux 上的 /etc/services 文件可以查看到更多关于保留端口的信息。

# less /etc/services # /etc/services: # $Id: services,v 1.55 2013/04/14 ovasik Exp $ # Network services, Internet style # IANA services version: last updated 2013-04-10 # Note that it is presently the policy of IANA to assign a single well-known # port number for both TCP and UDP; hence, most entries here have two entries # even if the protocol doesn't support UDP operations. # Updated from RFC 1700, ``Assigned Numbers'' (October 1994). Not all ports # are included, only the more common ones. # The latest IANA port assignments can be gotten from # http://www.iana.org/assignments/port-numbers # The Well Known Ports are those from 0 through 1023. # The Registered Ports are those from 1024 through 49151 # The Dynamic and/or Private Ports are those from 49152 through 65535 # Each line describes one service, and is of the form: # service-name port/protocol [aliases ...] [# comment] tcpmux 1/tcp # TCP port service multiplexer tcpmux 1/udp # TCP port service multiplexer rje 5/tcp # Remote Job Entry rje 5/udp # Remote Job Entry echo 7/tcp echo 7/udp discard 9/tcp sink null discard 9/udp sink null systat 11/tcp users systat 11/udp users daytime 13/tcp daytime 13/udp qotd 17/tcp quote qotd 17/udp quote msp 18/tcp # message send protocol (historic) msp 18/udp # message send protocol (historic) chargen 19/tcp ttytst source chargen 19/udp ttytst source ftp-data 20/tcp ftp-data 20/udp # 21 is registered to ftp, but also used by fsp ftp 21/tcp ftp 21/udp fsp fspd ssh 22/tcp # The Secure Shell (SSH) Protocol ssh 22/udp # The Secure Shell (SSH) Protocol telnet 23/tcp telnet 23/udp # 24 - private mail system lmtp 24/tcp # LMTP Mail Delivery lmtp 24/udp # LMTP Mail Delivery
可以使用以下六种方法查看端口信息。查看端口占用进程
以下我们将找出 sshd 守护进程所使用的端口号。
方法 1:使用 ss 命令

ss 一般用于转储套接字统计信息。它能够输出类似于 netstat 输出的信息,但它可以比其它工具显示更多的 TCP 信息和状态信息。
它还可以显示所有类型的套接字统计信息,包括 PACKET、TCP、UDP、DCCP、RAW、Unix 域等。
# ss -tnlp | grep ssh
LISTEN 0 128 *:22 *:* users:(("sshd",pid=997,fd=3))
LISTEN 0 128 :::22 :::* users:(("sshd",pid=997,fd=4))
也可以使用端口号来检查。

# ss -tnlp | grep ":22"
LISTEN 0 128 *:22 *:* users:(("sshd",pid=997,fd=3))
LISTEN 0 128 :::22 :::* users:(("sshd",pid=997,fd=4))
方法 2:使用 netstat 命令
netstat 能够显示网络连接、路由表、接口统计信息、伪装连接以及多播成员。查看端口占用进程
默认情况下,netstat 会列出打开的套接字。如果不指定任何地址族,则会显示所有已配置地址族的活动套接字。但 netstat 已经过时了,一般会使用 ss 来替代。

# netstat -tnlp | grep ssh tcp 0 0 0.0.0.0:22 0.0.0.0:* LISTEN 997/sshd tcp6 0 0 :::22 :::* LISTEN 997/sshd
也可以使用端口号来检查。
# netstat -tnlp | grep ":22" tcp 0 0 0.0.0.0:22 0.0.0.0:* LISTEN 1208/sshd tcp6 0 0 :::22 :::* LISTEN 1208/sshd
方法 3:使用 lsof 命令
本文来自电脑杂谈,转载请注明本文网址:
http://www.pc-fly.com/a/jisuanjixue/article-96914-1.html
古舊
高营养高蛋白