port 有关的总结
1 . 服务器端启动的监听端口所对应的服务是固定得
2 . 客户端启动程序时,随机启动一个大于1024以上的端口
3 . 一台服务器可以同时提供多种服务
4 . 共 65535 个 port
5 . 建立可靠的连接服务需要使用 TCP 协议,也就需要三次握手
6 . 通信协议可以启动在非正规的 port,比如WWW主机可以更改端口端口的查看
1 . netstat:在本机上以自己的程序检测自己的port
# 列出正在监听的网络服务 [root@CentOS ~]# netstat -tunl # 列出已连接的网络连接状态 [root@CentOS ~]# netstat -tun # 将已经建立,或者是正在监听当中的网络服务关闭 [root@CentOS ~]# netstat -tunp [root@CentOS ~]# kill -9 2846
2 . nmap
# 使用默认参数扫描本机所启动的 port (TCP) [root@CentOS ~]# nmap localhost # 同时扫描本机的 TCP/UDP 端口 [root@CentOS ~]# nmap -sTU localhost # 通过 ICMP 数据包的检测,分析局域网内有几台主机是启动的 [root@CentOS ~]# nmap -sP 192.168.1.0/24 # 将局域网内各个主机的端口检测一遍 [root@CentOS ~]# nmap 192.168.1.0/24
端口与服务的启动/关闭及开机时状态设定
port是在执行某软件之后被软件激活的,所以要关闭某些port 时,可直接将某个程序关闭就好了
1 . 服务的启动与管理分两种 (当次有效)
(1)stand alone:直接执行该服务的可执行文件,让该执行文件直接加载到内存当中运行。目录:/etc/init.d。 重启服务:/etc/init.d/sshd restart
(2)super daemon:用一个超级服务作为总管来统一管理某些特殊的服务、目录:/etc/xinetd.d。 重启服务:/etc/inetd.d restart# 关闭111端口,需要先找出程序 [root@CentOS ~]# netstat -tnlp | grep 111 #找到程序 tcp 0 0 0.0.0.0:111 0.0.0.0:* LISTEN 1576/rpcbind tcp 0 0 :::111 :::* LISTEN 1576/rpcbind [root@CentOS ~]# which rpcbind #找到文件 /sbin/rpcbind [root@CentOS ~]# rpm -qf /sbin/rpcbind #找出软件 rpcbind-0.2.0-12.el6.x86_64 [root@CentOS ~]# rpm -qc rpcbind | grep init #找出服务 /etc/rc.d/init.d/rpcbind [root@CentOS ~]# /etc/init.d/rpcbind stop Stopping rpcbind: [ OK ] # 也可以直接用kill [root@CentOS ~]# kill -9 1576
# 尝试启动telnet [root@CentOS ~]# rpm -qa | grep telnet-server #查询是否存在服务 [root@CentOS ~]# yum isntall telnet-server #安装服务 [root@CentOS ~]# vim /etc/xinetd.d/telnet #因为是super daemon,修改配置文件 service telnet { flags = REUSE socket_type = stream wait = no user = root server = /usr/sbin/in.telnetd log_on_failure += USERID disable = no #修改“yes”为“no” } [root@CentOS ~]# /etc/init.d/xinetd restart #重启服务 [root@CentOS ~]# netstat -tnlp #查看服务是否开启
2 . 默认启动的服务 (重启有效)
runlevel启动的数据都放置在/etc/re.d/re[0-6].d , 可以使用chkconfig命令# 查阅rpcbind 这个程序是否开机就启动 [root@CentOS ~]# chkconfig --list | grep rpcbind rpcbind 0:off 1:off 2:on 3:on 4:on 5:on 6:off # 如果开机启动,将其改为开机不启动 [root@CentOS ~]# chkconfig --level 35 rpcbind off # 立刻关闭这个服务 [root@CentOS ~]# /etc/init.d/rpcbind stop
关闭网络服务端口
# 找出目前系统上正在运行的服务,并且找到相对应的启动脚本(/etc/init.d/ 内的文件名) [root@CentOS ~]# netstat -tlunp [root@CentOS ~]# rpm -qc $(rpm -qf $(which rpc.statd) ) | grep init # 编写脚本关闭不需要的端口 [root@CentOS ~]# vim closedaemon.sh for daemon in nfs nfslock rpcgssd rpciamapd rpcsvcgssd xinetd rpcbind do chkconfig $daemon off /etc/init.d/$daemon stop done
鸟哥的服务器《五》限制连接端口
最新推荐文章于 2023-11-14 17:50:27 发布