質問をすることでしか得られない、回答やアドバイスがある。

15分調べてもわからないことは、質問しよう!

新規登録して質問してみよう
ただいま回答率
85.50%
CentOS

CentOSは、主にRed Hat Enterprise Linux(RHEL)をベースにした、フリーのソフトウェアオペレーティングシステムです。

Q&A

解決済

1回答

1257閲覧

AWSで、SELinuxをPermissive、firewalldをstopにしても外部から接続できない

d24d30033e5c469

総合スコア12

CentOS

CentOSは、主にRed Hat Enterprise Linux(RHEL)をベースにした、フリーのソフトウェアオペレーティングシステムです。

0グッド

1クリップ

投稿2017/11/07 03:49

編集2017/11/07 03:53

###前提・実現したいこと
CentOS 7.1で、ネットワークの外部から9999番ポートにアクセスしたいです。
開放する理由は、9999番ポートでApacheを使用するためです。

細かく言うとこのApacheの上でNagiosを動かしたい感じです。Nagiosを動かすためのApacheです。
また、80番ポートではnginxで別サーバが立ち上がっています。

今の状態

・80番(HTTP)や22番(SSH)では問題なくつながっている。
・100日ほど前はこんなめんどくさいことをやらなくても9999番ポートに普通につながっていた。

CentOSのバージョンは以下

sh

1[ec2-user@ip-10-0-3-98 ~]$ cat /etc/centos-release 2CentOS Linux release 7.1.1503 (Core)

firewalldは停止しています。

sh

1[ec2-user@ip-10-0-3-98 ~]$ sudo systemctl status firewalld 2● firewalld.service - firewalld - dynamic firewall daemon 3 Loaded: loaded (/usr/lib/systemd/system/firewalld.service; disabled; vendor preset: enabled) 4 Active: inactive (dead) 5 Docs: man:firewalld(1) 6 711月 07 11:16:59 ip-10-0-3-98 systemd[1]: Starting firewalld - dynamic firewall daemon... 811月 07 11:17:00 ip-10-0-3-98 systemd[1]: Started firewalld - dynamic firewall daemon. 911月 07 11:17:01 ip-10-0-3-98 firewalld[1991]: WARNING: ICMP type 'beyond-scope' is not supported by the kernel for ipv6. 1011月 07 11:17:01 ip-10-0-3-98 firewalld[1991]: WARNING: beyond-scope: INVALID_ICMPTYPE: No supported ICMP type., ignoring for run-time. 1111月 07 11:17:01 ip-10-0-3-98 firewalld[1991]: WARNING: ICMP type 'failed-policy' is not supported by the kernel for ipv6. 1211月 07 11:17:01 ip-10-0-3-98 firewalld[1991]: WARNING: failed-policy: INVALID_ICMPTYPE: No supported ICMP type., ignoring for...-time. 1311月 07 11:17:01 ip-10-0-3-98 firewalld[1991]: WARNING: ICMP type 'reject-route' is not supported by the kernel for ipv6. 1411月 07 11:17:01 ip-10-0-3-98 firewalld[1991]: WARNING: reject-route: INVALID_ICMPTYPE: No supported ICMP type., ignoring for run-time. 1511月 07 11:19:05 ip-10-0-3-98 systemd[1]: Stopping firewalld - dynamic firewall daemon... 1611月 07 11:19:06 ip-10-0-3-98 systemd[1]: Stopped firewalld - dynamic firewall daemon. 17Hint: Some lines were ellipsized, use -l to show in full.

SELinuxはPermissiveです

sh

1[ec2-user@ip-10-0-3-98 ~]$ sestatus 2SELinux status: enabled 3SELinuxfs mount: /sys/fs/selinux 4SELinux root directory: /etc/selinux 5Loaded policy name: targeted 6Current mode: permissive 7Mode from config file: enforcing 8Policy MLS status: enabled 9Policy deny_unknown status: allowed 10Max kernel policy version: 28

あまり意味がないと思いますが、iptablesのlistは以下のとおりです

sh

1[ec2-user@ip-10-0-3-98 ~]$ sudo iptables --list 2Chain INPUT (policy ACCEPT) 3target prot opt source destination 4ACCEPT tcp -- anywhere anywhere tcp dpt:webcache 5ACCEPT tcp -- anywhere anywhere tcp dpt:distinct 6 7Chain FORWARD (policy ACCEPT) 8target prot opt source destination 9 10Chain OUTPUT (policy ACCEPT) 11target prot opt source destination

EC2のセキュリティグループはもちろん次の通りの設定です。
イメージ説明

###試したこと

####サーバから

sh

1[ec2-user@ip-10-0-3-98 ~]$ curl --head http://localhost:9999 2HTTP/1.1 403 Forbidden 3Date: Tue, 07 Nov 2017 03:36:50 GMT 4Server: Apache/2.4.6 (CentOS) OpenSSL/1.0.1e-fips PHP/5.4.16 5Last-Modified: Thu, 16 Oct 2014 13:20:58 GMT 6ETag: "1321-5058a1e728280" 7Accept-Ranges: bytes 8Content-Length: 4897 9Content-Type: text/html; charset=UTF-8 10

では問題なくレスポンスが返ります。ステータスコードが403なのは問題ないです。

nmapでは以下が返却されます。

sh

1[ec2-user@ip-10-0-3-98 ~]$ nmap localhost 2 3Starting Nmap 6.40 ( http://nmap.org ) at 2017-11-07 12:31 JST 4Nmap scan report for localhost (127.0.0.1) 5Host is up (0.0010s latency). 6Other addresses for localhost (not scanned): 127.0.0.1 7Not shown: 990 closed ports 8PORT STATE SERVICE 922/tcp open ssh 1025/tcp open smtp 1180/tcp open http 12443/tcp open https 133306/tcp open mysql 145555/tcp open freeciv 158000/tcp open http-alt 168080/tcp open http-proxy 179200/tcp open wap-wsp 189999/tcp open abyss

ちゃんと開いてます。

クライアントから

sh

1~ nmap 【グローバルIPアドレス】 2 3Starting Nmap 7.60 ( https://nmap.org ) at 2017-11-07 12:32 JST 4Nmap scan report for ec2-【グローバルIPアドレス】.ap-northeast-1.compute.amazonaws.com (【グローバルIPアドレス】) 5Host is up (0.044s latency). 6Not shown: 993 filtered ports 7PORT STATE SERVICE 821/tcp open ftp 922/tcp open ssh 1080/tcp open http 1181/tcp open hosts2-ns 12443/tcp open https 138000/tcp open http-alt 148080/tcp open http-proxy 15 16Nmap done: 1 IP address (1 host up) scanned in 8.16 seconds

なぞに9999番が閉じられていました。

sh

1curl http://【グローバルIPアドレス】:9999 2curl: (7) Failed to connect to 【グローバルIPアドレス】 port 9999: Operation timed out

つながらない。

###補足情報
ちなみに8080番もつながらないです。
こっちはnmapで開放できてるのになぜなのかわかりませんが、直面している問題に直接関係ないので、解決できればいいなぐらいです。

そして謎にこっちはGateway Timeoutです

sh

1[ec2-user@ip-10-0-3-98 ~]$ curl http://localhost:8080 2???? It works!!

sh

1~ curl http://【グローバルIPアドレス】:8080 2<HTML>[504] Gateway Timeout</HTML>

その他

何か他に設定の見直し等あればツッコミ入れていただきたいです。

追記

/etc/hosts.denyは以下のように特に設定されていません。

sh

1[ec2-user@ip-10-0-3-98 ~]$ cat /etc/hosts.deny 2# 3# hosts.deny This file contains access rules which are used to 4# deny connections to network services that either use 5# the tcp_wrappers library or that have been 6# started through a tcp_wrappers-enabled xinetd. 7# 8# The rules in this file can also be set up in 9# /etc/hosts.allow with a 'deny' option instead. 10# 11# See 'man 5 hosts_options' and 'man 5 hosts_access' 12# for information on rule syntax. 13# See 'man tcpd' for information on tcp_wrappers 14#

気になる質問をクリップする

クリップした質問は、後からいつでもMYページで確認できます。

またクリップした質問に回答があった際、通知やメールを受け取ることができます。

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

guest

回答1

0

自己解決

VPCのネットワークACLも見ましたが、特に設定には問題ありませんでした。

イメージ説明
イメージ説明

またEC2を再起動(「再起動」コマンドではなく、一度「停止」してから「起動」した)なども試みましたが何も変化せず。

もうこれ以上調べるところなくない?と思っていたら、「ベンダのファイアウォール」という文字を見かけたので調査したところ、DeepSecurityというセキュリティ対策ソフトが入っており、それがファイアウォール機能を持っていたため、アンインストールしました。

sh

1$ sudo yum erase ds_agent

これで悲しいぐらい呆気なく動きました。
100日前に動いていたのは、100日前にDeepSecurityを導入したからだと思います。どうしてこんなになるまでほうっておいたんだ。

お騒がせしました(´・ω・;)

投稿2017/11/07 05:43

編集2017/11/07 05:45
d24d30033e5c469

総合スコア12

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

あなたの回答

tips

太字

斜体

打ち消し線

見出し

引用テキストの挿入

コードの挿入

リンクの挿入

リストの挿入

番号リストの挿入

表の挿入

水平線の挿入

プレビュー

15分調べてもわからないことは
teratailで質問しよう!

ただいまの回答率
85.50%

質問をまとめることで
思考を整理して素早く解決

テンプレート機能で
簡単に質問をまとめる

質問する

関連した質問