修改telnet最大连接数

公司的一台telnet堡垒机(一台 suse主机)近期总是不稳定,别人反映出现不能登陆情况时,主机的23端口还在监听,xinetd运行也正常。在message日志里看到有telnet timeout超时的日志。netstat查看当前23端口也有不少正常的连接,wc -l 统计了下连接数在90左右 。一旦restart服务,不能连接的人又可以正常连接了。出现问题每次都restart肯定不是办法,想深挖下根因。



由于linux telnet 并不像vsftp,可以选择单独模式运行,所以除了xinted.d的下的配置,没有其他配置文件。

一、查看xinetd.conf文件

<br />
[root@baolei01 ~]# vim /etc/xinetd.conf
#
# This is the master xinetd configuration file. Settings in the
# default section will be inherited by all service configurations
# unless explicitly overridden in the service configuration. See
# xinetd.conf in the man pages for a more detailed explanation of
# these attributes.
defaults
{
# The next two items are intended to be a quick access place to
# temporarily enable or disable services.
#
#       enabled         =
#       disabled        =
# Define general logging characteristics.
        log_type        = SYSLOG daemon info
        log_on_failure  = HOST
        log_on_success  = PID HOST DURATION EXIT
# Define access restriction defaults
#
#       no_access       =
#       only_from       =
#       max_load        = 0
        cps             = 50 10
        instances       = 90
        per_source      = 300
# Address and networking defaults
#
#       bind            =
#       mdns            = yes
        v6only          = no
}
注意:cps、instances、per_source几个参数。下面是对xinted相关参数的介绍:



<br />
disable 定义是否启动{no|yes}no表示开启,yes表示关闭
socket_type {stream|dgram}表示套接字格式,stream是TCP,dgram为udp
protocol 协议类型,这些是需是/etc/protocol里可用的
wait 允许并发数,{yes|no}yes单线程,no多线程
user  运行身份
server 有哪个文件/程序启用该服务
server_args  传递的参数
only-from 白名单
no-access 黑名单
access-time 定义访问时间
log-type {SYSLOG|FILE} syslog定义日志类型,级别;file定义日志存放位置
bind 监听ip
log-on-success 记录登陆成功的信息
log-on-failure  记录登陆失败的信息
per-source    资源限制,限制每个ip同时连接请求数
instances   限制同时运行的进程 ,当服务器被请求连接的进程数达到该值时,xinetd将停止接受多出部分的连接请求 ,直到请求连接数低于设定值为止。
phier-source = UNLIMITED表示不做限制
cps = n m 定义每妙最大连接数为n,超出后等待m秒后再尝试连接
将上面提到的三个参数根据实际需要修改并重载服务生效后,问题未再重现。



<br />

二、xinetd.d下的配置

由于xinetd.conf是一个全局配置参数,所以上面的配置可以考虑配置到相应的服务配置文件中,如下为telnet的配置示例:



<br />
server telnet
{
         disable         = no            表示服务已经开启
         flags           = REUSE
         socket_type     = stream        表示套接字stream表示TCP,dgream并表示UDP
         wait            = no            no表示为多线程服务,yes表示为单线程,用于并发连接请求。
         user            = root          以root的身份运行此服务
         server          = /usr/sbin/in.telnetd  定义有哪个进程起启动此服务,并接受用户访问
         log_on_failure  += USERID        表示在默认规则上扩展显示。
         log_type        = FILE /tmp/telnet_log  定义此服务日志的存储位置
         bind            = 192.168.0.24   指定监听IP
         per_source      = 1              指定同一IP允许向此服务最多打开的连接数
         access_times    = 08:00-19:30    指定可以使用此服务的时间
         cps             = 100 2          表示每秒最多可以有100个用户连接次服务,超出着等待2s重连
         only_from       = 192.168.0.0/25 表示仅允许192.168.0.0/25网段的计算机连接次服务
}
<br />

三、xinetd服务的特点及适用性

原则上任何系统服务都可以使用xinetd,然而最适合的应该是那些常用的网络服务,同

时,这个服务的请求数目和频繁程度不会太高。像DNS和Apache就不适合采用这种方式,而像FTP、Telnet、SSH等就适合使用xinetd模
式,系统默认使用xinetd的服务可以分为如下几类。
① 标准Internet服务:telnet、ftp。
② 信息服务:finger、netstat、systat。
③ 邮件服务:imap、imaps、pop2、pop3、pops。
④ RPC服务:rquotad、rstatd、rusersd、sprayd、walld。
⑤ BSD服务:comsat、exec、login、ntalk、shell、talk。
⑥ 内部服务:chargen、daytime、echo、servers、services、time。
⑦ 安全服务:irc。
⑧ 其他服务:name、tftp、uucp。

发表回复

您的电子邮箱地址不会被公开。 必填项已用*标注