本文共 4664 字,大约阅读时间需要 15 分钟。
譬如:
我们先安装一个ssh(Secure Shell)服务((我的ubuntu14.04 默认并没有安装)
sudo apt-get update
sudo apt-get install openssh-server (安装ssh服务端)
sudo apt-get install openssh-client (安装客户端,我就在自己的ubunu机器上调试,所以顺便再装一个客户端)
查看服务是否已经开启(netstat调试可参照我的另一篇博文:)
结果如下:
sunxiaowu@sunxiaowu:~$ sudo netstat -anp |grep ssh
tcp 0 0 0.0.0.0:22 0.0.0.0:* LISTEN 1016/sshd tcp6 0 0 :::22 :::* LISTEN 1016/sshd unix 2 [ ACC ] STREAM LISTENING 16589 1789/gnome-keyring- /run/user/1000/keyring-MxgGfh/ssh 稍微解释一下,此处tcp6是什么意思?意思是tcp既可走网络层ipv4协议,又可走ipv6,ssh服务进程pid1016,端口号22,正处于监听状态(依次调用了socket,bind,listen,正阻塞在accept),sshd中d表示守护(daemon)进程,以后详解。我们使用ssh客户端命令行登录
ssh ×××.*******.******.*******(目的主机ip地址)
输入yes
输入密码
登录成功
再次查看服务
如图所示,在我们用客户端ssh登录服务器后,显示情况如上。1016进程依旧监听(tcp和tcp6),新建了一个5697进程正处于ESTABLISHED状态,因为我是本机测试,故5689进程表示客户端进程,正处于和服务进程5697的连接状态。服务进程5697是哪里来的? 以后会在网络编程中详解
我们要学会查看unix文件来学习,有时候与其查看大量其他资料,不如直接看unix自带的一些文件说明
查看服务的端口分配
vim /etc/services
# Network services, Internet style
# # Note that it is presently the policy of IANA to assign a single well-known # port number for both TCP and UDP; hence, officially ports have two entries # even if the protocol doesn't support UDP operations. # # Updated from http://www.iana.org/assignments/port-numbers and other # sources like http://www.freebsd.org/cgi/cvsweb.cgi/src/etc/services . # New ports will be added on request if they have been officially assigned # by IANA and used in the real-world or are needed by a debian package. # If you need a huge list of used numbers please install the nmap package. tcpmux 1/tcp # TCP port service multiplexer echo 7/tcp echo 7/udp discard 9/tcp sink null discard 9/udp sink null systat 11/tcp users daytime 13/tcp daytime 13/udp netstat 15/tcp qotd 17/tcp quote msp 18/tcp # message send protocol 。。。。。。。。。。ipp 631/udp
# # UNIX specific services # exec 512/tcp biff 512/udp comsat login 513/tcp who 513/udp whod shell 514/tcp cmd # no passwords used syslog 514/udp printer 515/tcp spooler # line printer spooler talk 517/udp ntalk 518/udp route 520/udp router routed # RIP timed 525/udp timeserver tempo 526/tcp newdate courier 530/tcp rpc conference 531/tcp chat netnews 532/tcp readnews netwall 533/udp # for emergency broadcasts 。。。。。。。。。# From ``Assigned Numbers'':
# #> The Registered Ports are not controlled by the IANA and on most systems #> can be used by ordinary user processes or programs executed by ordinary #> users. # #> Ports are used in the TCP [45,106] to name the ends of logical #> connections which carry long term conversations. For the purpose of #> providing services to unknown callers, a service contact port is #> defined. This list specifies the port used by the server process as its #> contact port. While the IANA can not control uses of these ports it #> does register or list uses of these ports as a convienence to the #> community. # socks 1080/tcp # socks proxy server socks 1080/udp proofd 1093/tcp proofd 1093/udp rootd 1094/tcp rootd 1094/udp 238,1 40% 。。。。。。。。。。#=========================================================================
# The remaining port numbers are not as allocated by IANA. #========================================================================= # Kerberos (Project Athena/MIT) services # Note that these are for Kerberos v4, and are unofficial. Sites running # v4 should uncomment these and comment out the v5 entries above. # kerberos4 750/udp kerberos-iv kdc # Kerberos (server) kerberos4 750/tcp kerberos-iv kdc kerberos-master 751/udp kerberos_master # Kerberos authentication kerberos-master 751/tcp passwd-server 752/udp passwd_server # Kerberos passwd server krb-prop 754/tcp krb_prop krb5_prop hprop # Kerberos slave propagation krbupdate 760/tcp kreg # Kerberos registration swat 901/tcp # swat kpop 1109/tcp # Pop with Kerberos knetd 2053/tcp # Kerberos de-multiplexor。。。。。。。。。。
从这个配置文件可以查看服务对应的端口号
例如我要查看ssh服务对应信息
vim /etc/services
在命令行模式下,:/ssh
可以看到服务名ssh ,被分配的端口号是23