telnet: connect to address 127.0.0.1: Connection refused问题,有需要的朋友可以参考下。
今天在使用telnet连接本机的Memcached服务时,遇到如下问题:
[root@iZ94imebuqwZ ~]# telnet localhost 11211 Trying ::1... telnet: connect to address ::1: Connection refused Trying 127.0.0.1... telnet: connect to address 127.0.0.1: Connection refused |
- 检查telnet是否已安装:
[root@iZ94imebuqwZ ~]# rpm -qa telnet
telnet-0.17-41.e15 【有输出说明已安装,如果没有输出则没有安装,使用yum install telnet进行安装】 - 检查telnet-server是否已安装:
[root@iZ94imebuqwZ ~]# rpm -qa telnet-server
telnet-server-0.17-41.el5 【有输出说明已安装,如果没有输出则没有安装,使用yum install telnet-server进行安装】 -
如果第2步进行了telnet-server安装操作,且已成功安装,则由于telnet服务是由xinetd守护的,所以我们需要重新启动xinetd。
[root@iZ94imebuqwZ ~]# service xinetd restart
Stopping xinetd: [ OK ]
Starting xinetd: [ OK ]
- xinetd启动成功,可以查看xinetd的运行情况。【非必须】 yum install xinetd
[root@iZ94imebuqwZ ~]# netstat -tnlp 【或使用netstat -tnl | grep 23只查看目标端口】
Active Internet connections (only servers)
Proto Recv-Q Send-Q Local Address Foreign Address State PID/Program name
tcp 0 0 0.0.0.0:11211 0.0.0.0:* LISTEN 1866/memcached
tcp 0 0 0.0.0.0:22 0.0.0.0:* LISTEN 343/sshd
tcp 0 0 0.0.0.0:23 0.0.0.0:* LISTEN 8923/xinetd
[root@iZ94imebuqwZ ~]#
[root@iZ94imebuqwZ ~]#
[root@iZ94imebuqwZ ~]# telnet localhost 23
Trying ::1...
Connected to localhost.
Escape character is '^]'.
CentOS release 5.10 (Final)
Kernel 2.6.18-371.11.1.el5 on an x86_64
login: - 如果仍然无法连接到telnet,需要修改/etc/xinetd.d/telnet文件。【非必须】
[root@iZ94imebuqwZ ~]# vim /etc/xinetd.d/telnet
# default: on
# description: The telnet server serves telnet sessions; it uses \
# unencrypted username/password pairs for authentication.
service telnet
{
flags = REUSE
socket_type = stream
wait = no
user = root
server = /usr/sbin/in.telnetd
log_on_failure += USERID
#disable = yes 【将disable=yes行前加#注释掉,或者把yes改为no】
}[oot@iZ94imebuqwZ ~]# service xinetd restart
Stopping xinetd: [ OK ]
Starting xinetd: [ OK ] -
如果仍然无法连接到telnet,请检查防火墙配置(添加telnet的23端口服务)。防火墙配置请参考Allen.W的有关防火墙配置的文章。