LoginSignup
19
17

More than 3 years have passed since last update.

firewalldをインストールする方法

Posted at
  • 環境
    • Red Hat Enterprise Linux Server release 7.7 (Maipo)

Red HatとCentOSの7からiptablesはfirewalldになった

RHEL/CentOS7ではiptablesではなくfirewalld - Qiita

EC2のRed Hatにはfirewalldがインストールされていない

【AWS】RedHat の EC2 インスタンスにはファイアウォール(firewalld)はインストールされていない | 100%レンタルサーバーを使いこなすサイト

# サービスにない
$ sudo systemctl status firewalld
Unit firewalld.service could not be found.

# やっぱりサービスにない
$ systemctl list-unit-files | grep firewalld
$

# 探してもない
$ sudo ls -la /usr/lib/systemd/system | grep firewalld
$

firwalldをインストールする

ファイアウォール firewalld インストール | CentOSサーバー構築マニュアル.com

# 1. yumを更新する
$ sudo yum update
読み込んだプラグイン:amazon-id, search-disabled-repos
github_git-lfs/x86_64/signature                                                                                                                                                             |  833 B  00:00:00
...省略...
置換:
  iwl7265-firmware.noarch 0:22.0.7.0-72.el7

完了しました!

# 2. インストールする
$ sudo yum -y install firewalld
[sudo] ponsuke のパスワード:
読み込んだプラグイン:amazon-id, search-disabled-repos
github_git-lfs/x86_64/signature                                                                                                                                                             |  833 B  00:00:00
github_git-lfs/x86_64/signature                                                                                                                                                             | 1.0 kB  00:00:00 !!!
github_git-lfs-source/signature                                                                                                                                                             |  833 B  00:00:00
...省略...
インストール:
  firewalld.noarch 0:0.6.3-8.el7_8.1

依存性関連をインストールしました:
  ebtables.x86_64 0:2.0.10-16.el7         firewalld-filesystem.noarch 0:0.6.3-8.el7_8.1        ipset.x86_64 0:7.1-1.el7        ipset-libs.x86_64 0:7.1-1.el7        python-firewall.noarch 0:0.6.3-8.el7_8.1
  python-slip.noarch 0:0.4.0-4.el7        python-slip-dbus.noarch 0:0.4.0-4.el7

完了しました!

# 3. 状態を確認する
$ sudo systemctl status firewalld
● firewalld.service - firewalld - dynamic firewall daemon
   Loaded: loaded (/usr/lib/systemd/system/firewalld.service; enabled; vendor preset: enabled)
   Active: inactive (dead)
     Docs: man:firewalld(1)

起動する

systemctlでよくつかうオプションまとめ - かべぎわブログ

# 1. 起動する
$ sudo systemctl start firewalld

# 2. 状態を確認する
$ sudo systemctl status firewalld
● firewalld.service - firewalld - dynamic firewall daemon
   Loaded: loaded (/usr/lib/systemd/system/firewalld.service; enabled; vendor preset: enabled)
   Active: active (running) since 金 2020-05-01 11:40:28 JST; 3s ago
     Docs: man:firewalld(1)
 Main PID: 28562 (firewalld)
   CGroup: /system.slice/firewalld.service
           └─28562 /usr/bin/python2 -Es /usr/sbin/firewalld --nofork --nopid

 5月 01 11:40:28 ip-10-0-6-202.ap-northeast-1.compute.internaldev01.othelve.com systemd[1]: Starting firewalld - dynamic firewall daemon...
 5月 01 11:40:28 ip-10-0-6-202.ap-northeast-1.compute.internaldev01.othelve.com systemd[1]: Started firewalld - dynamic firewall daemon.
 5月 01 11:40:28 ip-10-0-6-202.ap-northeast-1.compute.internaldev01.othelve.com firewalld[28562]: WARNING: AllowZoneDrifting is enabled. This is considered an insecure configuration option. It will ...g it now.
Hint: Some lines were ellipsized, use -l to show in full.

# 3. 自動起動を有効化する
$ sudo systemctl enable firewalld

# 4. 自動起動が有効になったことを確認する
$ sudo systemctl is-enabled firewalld
enabled

設定を確認する

インストール直後は何も設定されていないので必要な設定をしていく

$ sudo firewall-cmd --list-all
public (active)
  target: default
  icmp-block-inversion: no
  interfaces: eth0
  sources:
  services: dhcpv6-client ssh
  ports:
  protocols:
  masquerade: no
  forward-ports:
  source-ports:
  icmp-blocks:
  rich rules:
19
17
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
19
17