0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

firewalldを設定する(自サーバのHTTP/HTTPSへのアクセスを可能にする)

Last updated at Posted at 2023-11-21

firewalld の設定について復習を兼ねて書いていきます。思いつきで書いているので順番バラバラです。内容間違ってたらすいません。

  • 常に恒久的な設定として使いたいので、--permanent オプションを使います。一時的に使いたいだけなら --permanent を除去してください。
  • 環境は Redhat9系です。AlmaLinux9で設定しています。
  • firewalld は起動してください。 systemctl start firewalld
  • selinux は切って(disable)ください。分かる人は有効に。

今回のパターン

  • サーバのNICは ens0p3 という名前 (VirtualBoxだったので)
  • このサーバではApacheサーバが動作していて、それをアクセスさせたいのでHTTPとHTTPSを通信許可したい。

image.png

1.ゾーンの選定

どのゾーンを使っても良いのですが(ゾーン設定をいじくり回せばどのゾーンでも好きな動作をさせることができる)、色々いじるのは面倒なので今回はexternalを使用します。externalゾーンは初期では以下のような感じになっています。

基本的な動作:全てを拒否
PING応答: OK(PING応答する)
通信OKのサービス :ssh

2.externalゾーンから不要なサービスを削除する

  • ゾーンexternalの通信OKから ssh を削除する
    firewall-cmd --permanent --zone=external --remove-service=ssh

3.externalゾーンに必要なサービスを追加します

  • ゾーンexternalの通信OKにHTTPを追加する
    firewall-cmd --permanent --zone=external --add-service=http

4.ゾーンexternalを インターフェース enp0s3 に割り当てる

firewall-cmd --permanent --zone=external --change-interface=enp0s3

5. 設定を有効化する

firewall-cmd --reload

6. externalゾーンの設定を確認する

firewall-cmd --info-zone=external
多分こんな感じ

external (avtive)
  target: default
  icmp-block-inversion: no
  interfaces: enp0s3
  sources:
  services: http https
  ports:
  protocols:
  forward: yes
  masquerade: yes
  forward-ports:
  source-ports:
  itmp-blocks
  rich rules:

以上で http サービスにアクセスができるようになると思います。

0
0
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
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?