telnet: Unable to connect to remote host: Connection refused

环境:

CentOS release 6.10 (Final)

$ telnet 127.0.0.1
Trying 127.0.0.1...
telnet: Unable to connect to remote host: Connection refused

原因是系统上没开telnet服务,解决如下:

yum -y install xinetd telnet-server
service xinetd start
netstat -tlunp | grep 23

# 发现23端口还没被监听,说明telnet服务没开

修改配置文件():

# 修改/etc/xinetd.d/telnet
# 将disable = yes 值改为no
disable         = no

重启telnet服务

service xinetd restart

# 在本机测试, 发现可以成功
telnet 127.0.0.1
Trying 127.0.0.1...
Connected to 127.0.0.1.
...省略部分内容

如果是另一台机器访问有问题,如:

[[email protected]] $
telnet 192.168.31.42
Trying 192.168.31.42...
telnet: Unable to connect to remote host: No route to host

需要检查下防火墙23有没有开:

$ iptables -L -n
Chain INPUT (policy ACCEPT)
target     prot opt source               destination
ACCEPT     all  --  0.0.0.0/0            0.0.0.0/0           state RELATED,ESTABLISHED
ACCEPT     icmp --  0.0.0.0/0            0.0.0.0/0
ACCEPT     all  --  0.0.0.0/0            0.0.0.0/0
ACCEPT     tcp  --  0.0.0.0/0            0.0.0.0/0           state NEW tcp dpt:22
ACCEPT     tcp  --  0.0.0.0/0            0.0.0.0/0           state NEW tcp dpt:8080
...省略部分内容

开放23端口

iptables -I INPUT 6 -p tcp --dport 23 -j ACCEPT
service iptables save
iptables -L -n
Chain INPUT (policy ACCEPT)
target     prot opt source               destination
ACCEPT     all  --  0.0.0.0/0            0.0.0.0/0           state RELATED,ESTABLISHED
ACCEPT     icmp --  0.0.0.0/0            0.0.0.0/0
ACCEPT     all  --  0.0.0.0/0            0.0.0.0/0
ACCEPT     tcp  --  0.0.0.0/0            0.0.0.0/0           state NEW tcp dpt:22
ACCEPT     tcp  --  0.0.0.0/0            0.0.0.0/0           state NEW tcp dpt:8080
ACCEPT     tcp  --  0.0.0.0/0            0.0.0.0/0           tcp dpt:23
...省略部分内容

再试发现就可以了:

[[email protected]] $ telnet 192.168.31.42
Trying 192.168.31.42...
Connected to 192.168.31.42.
...省略部分内容

欢迎补充指正

你可能感兴趣的:(Linux,计算机网络)