1. 程式人生 > >telnet: Unable to connect to remote host: Connection refused

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.
...省略部分內容

歡迎補充指正