LoginSignup
5
5

More than 5 years have passed since last update.

CentOS 7.4でtelnetのアクセス制限できなかった話

Last updated at Posted at 2018-02-02

新規に構築した社内サーバで、telnet-serverを利用することとなったものの、/etc/hosts.allow,/etc/hosts.denyが効かず、かなり紆余曲折したので、備忘として残しておきます。

hosts.allowが効かない

環境は、以下。

centos-release
$ cat /etc/centos-release
CentOS Linux release 7.4.1708 (Core)
telnet-server
$ rpm -q telnet-server
telnet-server-0.17-64.el7.x86_64
telnet-server
$ rpm -q tcp_wrappers
tcp_wrappers-7.6-77.el7.x86_64

これまで通り アクセス制御を/etc/hosts.allowでやろうと、編集。

/etc/hosts.deny
$ cat /etc/hosts.deny
#
# hosts.deny    This file contains access rules which are used to
#               deny connections to network services that either use
#               the tcp_wrappers library or that have been
#               started through a tcp_wrappers-enabled xinetd.
#
#               The rules in this file can also be set up in
#               /etc/hosts.allow with a 'deny' option instead.
#
#               See 'man 5 hosts_options' and 'man 5 hosts_access'
#               for information on rule syntax.
#               See 'man tcpd' for information on tcp_wrappers
#
in.telnetd:ALL
/etc/hosts.allow
$ cat /etc/hosts.allow
#
# hosts.allow   This file contains access rules which are used to
#               allow or deny connections to network services that
#               either use the tcp_wrappers library or that have been
#               started through a tcp_wrappers-enabled xinetd.
#
#               See 'man 5 hosts_options' and 'man 5 hosts_access'
#               for information on rule syntax.
#               See 'man tcpd' for information on tcp_wrappers
#

よし。ちゃんとアクセス拒否されるか、確認だ。

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

はぁ??

systemdの仕様変更?

systemd のバグ修正と機能強化のアップデート

systemd におけるネイティブの tcpwrap サポートは廃止されました。tcpwrap を使用する必要がある場合は、従来の inetd デーモンの場合と同様に、tcpd デーモンを使用して socket-activated サービスを呼び出すことを検討してください。

マヂか。。。

で、どう設定すればいいの??

かなり探しました。答えはここ
上記を参考に、以下のように/usr/lib/systemd/system/telnet@.serviceを編集

変更前

[Unit]
Description=Telnet Server
After=local-fs.target

[Service]
ExecStart=-/usr/sbin/in.telnetd
StandardInput=socket

変更後

[Unit]
Description=Telnet Server
After=local-fs.target

[Service]
ExecStart=@-/usr/sbin/tcpd /usr/sbin/in.telnetd
StandardInput=socket

設定反映

# systemctl daemon-reload
# systemctl restart telnet.socket

備考

ここではtelnet-serverでしたが、libwrapをリンクしている、sshdやvsftpdでは、tcpdを使わず、そのまま利用できました。

# ldd `which sshd` |grep libwrap
        libwrap.so.0 => /lib64/libwrap.so.0 (0x00007fa95e93e000)
# ldd `which vsftpd` |grep libwrap
        libwrap.so.0 => /lib64/libwrap.so.0 (0x00007f89f1a24000)
5
5
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
5
5