/etc/hosts.allowファイルでアクセス制限設定をする

» 2000年12月06日 00時00分 公開
[木田佳克ITmedia]

この記事は会員限定です。会員登録すると全てご覧いただけます。

 Linuxサーバでアクセス制限を行いたい場合には、大きく分類すると次のような手段がある。

  1. アクセス元の条件を決める:hosts.allow、hosts.denyファイルでは、IPやドメインを指定してアクセス元を限定することができる。
  2. どのサービスを起動許可するかを決める:デーモン起動以外のinetサービスでは、inetdでサービスの起動許可を設定する。
  3. TCP、UDPごとのフィルタ設定を行う:tcp wrapperなどによって、特定のポート番号でのアクセスを制限する。一般的にファイアウォールと呼ばれるアクセス制限の手段。

 ここでは、1番の/etc/hosts.allow、/etc/hosts.denyの記述例を挙げてみよう。

  • hosts.allow:アクセス許可条件を設定するファイル
  • hosts.deny:アクセス不可条件を設定するファイル

 2つのファイル共に、基本的に次のような記述フォーマットになっている。

デーモン名:ホスト名またはIPアドレス
例:in.telnetd: 192.168.0.

 実際のファイル例を挙げてみよう。次のように各ファイルを編集することで、各サービスのアクセスを制御することが可能だ。

# vi /etc/hosts.deny
#
# hosts.deny This file describes the names of the hosts which are
# *not* allowed to use the local INET services, as decided
# by the '/usr/sbin/tcpd' server.
#
# The portmap line is redundant, but it is left to remind you that
# the new secure portmap uses hosts.deny and hosts.allow. In particular
# you should know that NFS uses portmap!
ALL : ALL
1.まずすべてのアクセスを禁止する
# vi /etc/hosts.allow
#
# hosts.allow This file describes the names of the hosts which are
# allowed to use the local INET services, as decided
# by the '/usr/sbin/tcpd' server.
#
in.telnetd: 192.168.0. zdnet-n.pub.softbank.co.jp
in.ftpd: 192.168.0. zdnet-n.pub.softbank.co.jp
in.popper: 192.168.0. zdnet-n.pub.softbank.co.jp
2.アクセス許可をするサービスとIP(ドメイン名)を指定する

※上記の設定では、telnet、ftp、POPのアクセスを許可するが「192.168.0.*」と「zdnet-n.pub.softbank.co.jp」からのアクセスのみを許可している。この設定以外のサービスは、hosts.deny設定ですべて拒否される。

Copyright © ITmedia, Inc. All Rights Reserved.

注目のテーマ