本博客旨在自我学习使用,如有任何疑问请及时联系博主

今天遇到个稀奇古怪的问题:

调试emqx的时候一直econnrefused,检查服务时,突然发现在ubuntu上telnet localhost竟然不通???

则往下进行排查,首先查看端口状态

netstat -tnl

发现虽然可以执行telnet,但并没有telnet服务占用端口,即并没有启动telnet服务

解决方案

  1. 安装xinetd和telnetd

    sudo apt-get install xinetd telnetd

  2. 创建inetd.conf文件

    sudo vi /etc/inetd.conf

  3. 在inetd.conf文件中添加

    telnet stream tcp nowait telnetd /usr/sbin/tcpd /usr/sbin/in.telnetd

  4. 完善xinetd.conf文件

    sudo vi /etc/xinetd.conf

  5. 在defaults配置里面添加

instances = 60
log_type = SYSLOG authpriv
log_on_success = HOST PID
log_on_failure = HOST
cps = 25 30

  1. 创建telnet文件

    sudo vi /etc/xinetd.d/telnet

  2. 在文件中输入

# default: on
# description: The telnet server serves telnet sessions; it uses \
# unencrypted username/password pairs for authentication.
service telnet
{    
disable = no
flags = REUSE
socket_type = stream
wait = no
user = root
server = /usr/sbin/in.telnetd
log_on_failure += USERID
}

  1. 重启Ubuntu系统

    shutdown -r now

  2. 重新查看端口状态

    netstat -tnl

可以发现多了一个23端口占用,即为telnet服务正在监听23端口
  1. 重新测试telnet localhost

    Ubuntu20.04.3中telnet 127.0.0.1时Unable to connect to remote host: Connection refused-小白菜博客
    原帖:wolai