ひとり勉強ログ

ITエンジニアの勉強したことメモ

Apacheの設定vo.3~firewalld~

CentOS7以降はFirewalldによって、HTTPでの外部からのアクセスが拒否されている。

アクセス可能となるよう、firewalldの設定を行う。

firewalldの現状の状態を確認

[bash] [root@localhost ~]# firewall-cmd --list-all dmz (active) target: default icmp-block-inversion: no interfaces: enp0s3 sources: services: ssh ports: 25565/tcp protocols: masquerade: no forward-ports: sourceports: icmp-blocks: rich rules:

「services」のところに「http」がありません。

<h3>firewalldへのアクセス設定の許可</h3>

[root@localhost ~]# firewall-cmd --permanent --add-service=http success [/bash]

オプション「--permanent」を入れることで、OSを再起動した後でも設定がそのまま有効になる。ただし、firewalldサービスを再起動して設定を有効化する必要がある。

firewalldのリロード

[bash] [root@localhost ~]# firewall-cmd --reload success [/bash]

再度設定内容を確認。 [bash] [root@localhost ~]# firewall-cmd --list-all dmz (active) target: default icmp-block-inversion: no interfaces: enp0s3 sources: services: http ssh ports: 25565/tcp protocols: masquerade: no forward-ports: sourceports: icmp-blocks: rich rules: [/bash]

これでドキュメントルートにブラウザでアクセスするとApacheの画面が表示されるはずです。

firewalldにアクセス許可した設定を削除する場合

[bash] [root@localhost ~]# firewall-cmd --permanent --remove-service=http [/bash]

設定を反映するには、firewalldのリロードが必要。 [bash] [root@localhost ~]# firewall-cmd --reload success [/bash]