mattintosh note

どこかのエンジニアモドキの備忘録

CentOS 7 で xinetd を使った Telnet サーバの構築

LPIC/LinuC の試験範囲に inetd/xinetd が入っているが、CentOS 7 では既に telnet サーバは systemd に移行していて手作業じゃないと xinetd での検証が出来ないので方法を書いておくよ。(この辺の古い話題はいつまで試験に出るんですかね)

Console

[root@localhost ~]# yum install xinetd telnet-server

各パッケージ含まれているファイル郡。

Console

[root@localhost ~]# rpm -ql xinetd
/etc/sysconfig/xinetd
/etc/xinetd.conf
/etc/xinetd.d/chargen-dgram
/etc/xinetd.d/chargen-stream
/etc/xinetd.d/daytime-dgram
/etc/xinetd.d/daytime-stream
/etc/xinetd.d/discard-dgram
/etc/xinetd.d/discard-stream
/etc/xinetd.d/echo-dgram
/etc/xinetd.d/echo-stream
/etc/xinetd.d/tcpmux-server
/etc/xinetd.d/time-dgram
/etc/xinetd.d/time-stream
/usr/lib/systemd/system/xinetd.service
/usr/sbin/xinetd
/usr/share/doc/xinetd-2.3.15
/usr/share/doc/xinetd-2.3.15/CHANGELOG
/usr/share/doc/xinetd-2.3.15/COPYRIGHT
/usr/share/doc/xinetd-2.3.15/README
/usr/share/doc/xinetd-2.3.15/empty.conf
/usr/share/doc/xinetd-2.3.15/sample.conf
/usr/share/man/man5/xinetd.conf.5.gz
/usr/share/man/man5/xinetd.log.5.gz
/usr/share/man/man8/xinetd.8.gz

Console

[root@localhost ~]# rpm -ql telnet-server
/usr/lib/systemd/system/telnet.socket
/usr/lib/systemd/system/telnet@.service
/usr/sbin/in.telnetd
/usr/share/man/man5/issue.net.5.gz
/usr/share/man/man8/in.telnetd.8.gz
/usr/share/man/man8/telnetd.8.gz

Telnet 用のファイルも無いので /etc/xinetd.d/telnet を作成する。属性の詳細は man 5 xinetd.conf を参照。xinetd では TCPWrapper を使っていないでアクセス制御は only_fromno_access 属性で行う。

/etc/xinetd.d/telnet

service telnet
{
    disable         = no
    flags           = REUSE
    socket_type     = stream
    wait            = no
    user            = root
    server          = /usr/sbin/in.telnetd
    log_on_failure  += USERID
}

Console

[root@localhost ~]# systemctl reload xinetd

クライアントから接続出来れば完了。

Console

[root@localhost ~]# telnet localhost
Trying ::1...
Connected to localhost.
Escape character is '^]'.

Kernel 3.10.0-957.el7.x86_64 on an x86_64
localhost login:

外部からの接続を許可する場合は firewall-cmdtelnet サービスを追加しておく必要がある。実際には接続元などを制限するべきだが、レベル1の試験範囲外(のはず)なのでここでは割愛する。CentOSVirtualBox で実行している場合、NAT であればホストの適当なポートをゲストの 23 番に転送するか、ブリッジであれば IP でそのまま接続出来るはず。

Console

[root@localhost ~]# firewall-cmd --add-service=telnet

systemd では

telnet-server パッケージをインストールして telnet.socket を開始すればよいだけ。

Console

[root@localhost ~]# yum install telnet-server
[root@localhost ~]# systemctl start telnet.socket

Debian 9 では

telnetd パッケージをインストールすれば openbsd-inetd がインストールされ、/etc/inetd.conf が設定される。

/etc/inetd.conf

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