接続元IPアドレスでアクセスを制限する

対応プラン FLEX (Linux 系 OS)

万一ユーザー名とパスワードが漏洩してしまうと、どこからでもSSHやFTPでサーバーに接続できてしまいます。
接続元が固定IPアドレスのネットワーク環境に限られる場合は、TCP wrapper の設定をすることで、特定のIPアドレスからの接続のみを許可するよう、サービスごとにアクセスを制限できます。
このマニュアルでは、特定のIPアドレスからのみSSH接続とFTP接続を許可する場合を例に設定方法をご案内します。

接続元IPアドレスでアクセスを制限する

  • このマニュアルでは Cent OS を使用している場合を例にご案内します。
  • Linux コマンドに関してはサポート対象外となります。
    ご不明な点や詳細についてはインターネットや書籍にてご確認ください。

  1. rootアカウントでログインします。

    [root@flex-000 ~]#

    プロンプト表示に続けて次のコマンドを入力します。

    [root@flex-000 ~]# vi /etc/hosts.allow
    • 「vi」と「/etc/hosts.allow」の間はスペースが入ります。

    入力したらキーボードの Enterキーを押します。

  2.  

  3. viエディタで[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.
    #
    ~
    ~
    ~
    ~

    キーボードの「i」キーを押し、viエディタを入力モードにし、下記の内容を追記します。

    #
    # 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.
    #
    #すべてのサービス: ローカルホストからは許可
    ALL: 127.0.0.1
    #
    #SSH接続: 特定のIPからのみ許可
    sshd: 123.456.789.123
    #
    #FTP接続: 特定のIPからのみ許可
    ftpd: 123.456.789.123
    ~
    ~
    ~
    ~
    -- INSERT --
    • 例示した 123.456.789.123 は、実在しないIPアドレスです。IPアドレスは、「.(ドット)」で区切られた 0 ~ 255 の数字4組で表記されます。
    • お客様の現在の接続元IPアドレスは「 18.221.41.214」です。
    • お客様の現在の接続元IPアドレスからすべてのサービスへの接続を許可する場合は、
      ALL: 18.221.41.214
      と記述します。

    編集が完了したら、キーボードの Escキーを押し、viエディタをコマンドモードに戻します。

  4.  

  5. 編集内容を保存するため、次のコマンドを入力します。

    ~
    ~
    :w

    入力したらキーボードの Enterキーを押します。

  6.  

  7. viエディタを終了するため、次のコマンドを入力します。

    ~
    ~
    :q

    入力したらキーボードの Enterキーを押します。

  8.  

  9. コマンドプロンプトに戻ります。
    プロンプト表示に続けて次のコマンドを入力します。

    [root@flex-000 ~]# vi /etc/hosts.allow
    [root@flex-000 ~]# vi /etc/hosts.deny
    • 「vi」と「/etc/hosts.allow」の間はスペースが入ります。

    入力したらキーボードの Enterキーを押します。

  10.  

  11. viエディタで[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!
    ~
    ~
    ~
    ~

    キーボードの「i」キーを押し、viエディタを入力モードにし、下記の内容を追記します。

    #
    # 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
    ~
    ~
    ~
    ~
    -- INSERT --

    編集が完了したら、キーボードの Escキーを押し、viエディタをコマンドモードに戻します。

  12.  

  13. 編集内容を保存するため、次のコマンドを入力します。

    ~
    ~
    :w

    入力したらキーボードの Enterキーを押します。

  14.  

  15. viエディタを終了するため、次のコマンドを入力します。

    ~
    ~
    :q

    入力したらキーボードの Enterキーを押します。