端口

什么是端口?

端口是用来唯一标识应用程序的。


每个应用程序都占了一个端口。



例如,tomcat、mysql等软件

tomcat,默认是8080;

说明:当我们访问一个网站的时候(比如,www.chunwenxue.site),实际上访问的是服务器上的部署在tomcat里面的一个web应用程序。

从端口的角度来讲,web应用程序它不是一个程序,而只是tomcat程序的一部分,这个部分提供了某些功能,如果tomcat部署了多个项目,那么每个项目都提供了一些功能,而已。

刚才提到说在浏览器里输入网址就是在访问一个网站程序(本质上是访问tomcat,更准确地说,是本地的浏览器程序和服务器的tomcat程序在互相通信),但是输入网址时并没有输入端口号啊,这是因为Internate是基于http协议的,而http协议使用的是80端口(其他的应用层协议ftp、smtp等是使用其他的端口),访问一个网址,实际上就是在访问网址:80。

基于以上所述,我们在正式的生产环境,通常都会把tomcat的端口改为80,这样用户在浏览器里输入网址的时候就不用需要输入端口号了。不然的话,如果tomcat的端口是8080,那我们访问一个网址/网站的时候,还要在后面添加上:8080,这样多麻烦啊。



mysql,默认是3306。



……



再例如,netstat命令

netstat命令

C:\Users\Administrator>netstat -an

活动连接

  协议  本地地址          外部地址        状态
  TCP    0.0.0.0:8080             0.0.0.0:0              LISTENING
  TCP    0.0.0.0:135            0.0.0.0:0              LISTENING
  TCP    0.0.0.0:443            0.0.0.0:0              LISTENING
  TCP    0.0.0.0:445            0.0.0.0:0              LISTENING
  TCP    0.0.0.0:3306           0.0.0.0:0              LISTENING
  TCP    0.0.0.0:8009           0.0.0.0:0              LISTENING
  TCP    0.0.0.0:49152          0.0.0.0:0              LISTENING
  TCP    0.0.0.0:49153          0.0.0.0:0              LISTENING
  TCP    0.0.0.0:49154          0.0.0.0:0              LISTENING
  TCP    0.0.0.0:49155          0.0.0.0:0              LISTENING
  TCP    0.0.0.0:49160          0.0.0.0:0              LISTENING
  TCP    10.72.53.105:139       0.0.0.0:0              LISTENING
  TCP    10.72.53.105:50288     209.135.140.128:443    CLOSE_WAIT
  TCP    10.72.53.105:50292     209.135.140.128:443    CLOSE_WAIT
  TCP    10.72.53.105:60911     64.233.189.188:443     ESTABLISHED
  TCP    10.72.53.105:60926     42.121.253.45:80       ESTABLISHED
  TCP    10.72.53.105:60927     42.121.253.45:443      ESTABLISHED
  TCP    10.72.53.105:61187     182.92.197.238:22      ESTABLISHED
  TCP    10.72.53.105:61358     42.121.253.45:443      TIME_WAIT
  TCP    10.72.53.105:61360     119.147.146.168:80     TIME_WAIT
  TCP    10.72.53.105:61363     114.80.189.13:80       FIN_WAIT_2
  TCP    10.72.53.105:61364     114.80.189.13:80       FIN_WAIT_2
  TCP    10.72.53.105:61366     114.80.189.13:80       FIN_WAIT_2
  TCP    10.72.53.105:61369     42.121.253.45:443      ESTABLISHED
  TCP    10.72.53.105:61375     10.72.53.105:80        TIME_WAIT
  TCP    10.72.53.105:61386     124.116.181.110:80     ESTABLISHED
  TCP    10.72.53.105:61387     124.116.181.110:80     ESTABLISHED
  TCP    10.72.53.105:61392     106.11.20.99:80        TIME_WAIT
  TCP    10.72.53.105:61393     106.11.20.99:80        TIME_WAIT
  TCP    10.72.53.105:61396     106.11.20.41:80        CLOSE_WAIT
  TCP    10.72.53.105:61397     106.11.20.41:80        CLOSE_WAIT
  TCP    10.72.53.105:61400     140.205.179.178:80     CLOSE_WAIT
  TCP    10.72.53.105:61401     180.149.155.103:80     ESTABLISHED
  TCP    10.72.53.105:61405     140.205.176.22:80      ESTABLISHED
  TCP    10.72.53.105:61407     140.205.176.22:80      ESTABLISHED
  TCP    10.72.53.105:61408     114.112.93.171:80      TIME_WAIT
  TCP    10.72.53.105:61409     114.112.93.52:80       TIME_WAIT
  TCP    10.72.53.105:61410     124.116.133.42:80      TIME_WAIT
  TCP    10.72.53.105:61412     36.110.147.39:80       TIME_WAIT
  TCP    10.72.53.105:61413     36.110.147.39:80       TIME_WAIT
  TCP    10.72.53.105:61414     36.110.147.39:80       TIME_WAIT
  TCP    10.72.53.105:61415     36.110.147.39:80       TIME_WAIT
  TCP    10.72.53.105:61416     180.149.156.142:80     TIME_WAIT
  TCP    10.72.53.105:61417     180.149.156.142:80     TIME_WAIT
  TCP    10.72.53.105:61424     124.116.181.110:80     TIME_WAIT
  TCP    10.72.53.105:61427     106.11.20.99:80        TIME_WAIT
  TCP    10.72.53.105:61428     106.11.20.99:80        LAST_ACK
  TCP    10.72.53.105:61432     140.205.176.22:80      TIME_WAIT
  TCP    10.72.53.105:61433     106.11.20.41:80        ESTABLISHED
  TCP    10.72.53.105:61434     106.11.20.41:80        ESTABLISHED
  TCP    10.72.53.105:61438     106.11.20.41:80        TIME_WAIT
  TCP    10.72.53.105:61439     106.11.20.41:80        TIME_WAIT
  TCP    10.72.53.105:61441     180.149.155.103:80     ESTABLISHED
  TCP    10.72.53.105:61442     180.149.155.102:80     TIME_WAIT
  TCP    10.72.53.105:61444     140.205.176.22:80      TIME_WAIT
  TCP    10.72.53.105:61445     140.205.176.22:80      LAST_ACK
  TCP    10.72.53.105:61446     140.205.176.22:80      CLOSING
  TCP    10.72.53.105:61447     140.205.176.22:80      TIME_WAIT
  TCP    10.72.53.105:61448     140.205.176.22:80      TIME_WAIT
  TCP    10.72.53.105:61449     140.205.176.22:80      TIME_WAIT
  TCP    127.0.0.1:8005         0.0.0.0:0              LISTENING
  TCP    127.0.0.1:50282        127.0.0.1:50283        ESTABLISHED
  TCP    127.0.0.1:50283        127.0.0.1:50282        ESTABLISHED
  TCP    127.0.0.1:55220        127.0.0.1:55221        ESTABLISHED
  TCP    127.0.0.1:55221        127.0.0.1:55220        ESTABLISHED
  TCP    127.0.0.1:55539        127.0.0.1:55538        TIME_WAIT
  TCP    127.0.0.1:61373        127.0.0.1:61374        ESTABLISHED
  TCP    127.0.0.1:61374        127.0.0.1:61373        ESTABLISHED
  TCP    [::]:80                [::]:0                 LISTENING
  TCP    [::]:135               [::]:0                 LISTENING
  TCP    [::]:443               [::]:0                 LISTENING
  TCP    [::]:445               [::]:0                 LISTENING
  TCP    [::]:8009              [::]:0                 LISTENING
  TCP    [::]:49152             [::]:0                 LISTENING
  TCP    [::]:49153             [::]:0                 LISTENING
  TCP    [::]:49154             [::]:0                 LISTENING
  TCP    [::]:49155             [::]:0                 LISTENING
  TCP    [::]:49160             [::]:0                 LISTENING
  TCP    [::1]:80               [::1]:61418            ESTABLISHED
  TCP    [::1]:80               [::1]:61419            ESTABLISHED
  TCP    [::1]:80               [::1]:61420            ESTABLISHED
  TCP    [::1]:80               [::1]:61421            ESTABLISHED
  TCP    [::1]:80               [::1]:61422            ESTABLISHED
  TCP    [::1]:80               [::1]:61423            ESTABLISHED
  TCP    [::1]:61357            [::1]:8080             TIME_WAIT
  TCP    [::1]:61359            [::1]:8080             TIME_WAIT
  TCP    [::1]:61362            [::1]:8080             TIME_WAIT
  TCP    [::1]:61418            [::1]:80               ESTABLISHED
  TCP    [::1]:61419            [::1]:80               ESTABLISHED
  TCP    [::1]:61420            [::1]:80               ESTABLISHED
  TCP    [::1]:61421            [::1]:80               ESTABLISHED
  TCP    [::1]:61422            [::1]:80               ESTABLISHED
  TCP    [::1]:61423            [::1]:80               ESTABLISHED
  TCP    [fe80::6c0e:49d8:4fe9:abe9%11]:80  [fe80::6c0e:49d8:4fe9:abe9%11]:61376
  ESTABLISHED
  TCP    [fe80::6c0e:49d8:4fe9:abe9%11]:80  [fe80::6c0e:49d8:4fe9:abe9%11]:61377
  FIN_WAIT_2
  TCP    [fe80::6c0e:49d8:4fe9:abe9%11]:80  [fe80::6c0e:49d8:4fe9:abe9%11]:61379
  FIN_WAIT_2
  TCP    [fe80::6c0e:49d8:4fe9:abe9%11]:80  [fe80::6c0e:49d8:4fe9:abe9%11]:61382
  FIN_WAIT_2
  TCP    [fe80::6c0e:49d8:4fe9:abe9%11]:80  [fe80::6c0e:49d8:4fe9:abe9%11]:61383
  FIN_WAIT_2
  TCP    [fe80::6c0e:49d8:4fe9:abe9%11]:80  [fe80::6c0e:49d8:4fe9:abe9%11]:61384
  FIN_WAIT_2
  TCP    [fe80::6c0e:49d8:4fe9:abe9%11]:80  [fe80::6c0e:49d8:4fe9:abe9%11]:61385
  FIN_WAIT_2
  TCP    [fe80::6c0e:49d8:4fe9:abe9%11]:61376  [fe80::6c0e:49d8:4fe9:abe9%11]:80
  ESTABLISHED
  TCP    [fe80::6c0e:49d8:4fe9:abe9%11]:61377  [fe80::6c0e:49d8:4fe9:abe9%11]:80
  CLOSE_WAIT
  TCP    [fe80::6c0e:49d8:4fe9:abe9%11]:61379  [fe80::6c0e:49d8:4fe9:abe9%11]:80
  CLOSE_WAIT
  TCP    [fe80::6c0e:49d8:4fe9:abe9%11]:61382  [fe80::6c0e:49d8:4fe9:abe9%11]:80
  CLOSE_WAIT
  TCP    [fe80::6c0e:49d8:4fe9:abe9%11]:61383  [fe80::6c0e:49d8:4fe9:abe9%11]:80
  CLOSE_WAIT
  TCP    [fe80::6c0e:49d8:4fe9:abe9%11]:61384  [fe80::6c0e:49d8:4fe9:abe9%11]:80
  CLOSE_WAIT
  TCP    [fe80::6c0e:49d8:4fe9:abe9%11]:61385  [fe80::6c0e:49d8:4fe9:abe9%11]:80
  CLOSE_WAIT
  UDP    0.0.0.0:500            *:*
  UDP    0.0.0.0:4500           *:*
  UDP    0.0.0.0:5355           *:*
  UDP    0.0.0.0:50941          *:*
  UDP    10.72.53.105:137       *:*
  UDP    10.72.53.105:138       *:*
  UDP    10.72.53.105:1900      *:*
  UDP    10.72.53.105:64536     *:*
  UDP    127.0.0.1:1900         *:*
  UDP    127.0.0.1:64537        *:*
  UDP    [::]:500               *:*
  UDP    [::]:4500              *:*
  UDP    [::]:5355              *:*
  UDP    [::1]:1900             *:*
  UDP    [::1]:64535            *:*
  UDP    [fe80::6c0e:49d8:4fe9:abe9%11]:1900  *:*
  UDP    [fe80::6c0e:49d8:4fe9:abe9%11]:64534  *:*



说明:netstus命令,是用于查看哪些端口正在被哪些程序占用。


其中8080端口是被tomcat占用。


netstus命令,刚才说了,是用于查看哪些端口正在被哪些程序占用/使用。注意这句话里的2个字,正在,正在的意思是,这个程序正在运行,对于tomcat而言,我们顺便了解一下这行数据里的3个字段(本地地址、远程地址、协议),

1)本地地址是:0:0:0:0:8080,是服务器端tomcat程序的端口。

2)远程地址是:浏览器的端口。

3)协议:TCP协议(http协议是基于TCP协议的)。


参考:

http://segmentfault.com/q/1010000000209105

http://segmentfault.com/q/1010000000209105



再再例如,套接字编程/网络编程

……


评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值