1
2

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 5 years have passed since last update.

備忘録 CentOS 7 firewalld

Last updated at Posted at 2017-03-22

去年もCentOSやRedHat7を使っていましたが、firewalldがよくわからなく、firewalldを無効にしてiptablesをインストール・設定してつかってました。

今年は、そんなことは言ってられないので、firewalldにチャレンジ。

firewalldの設定

Webブラウザからアクセス

まずは、Apacheを導入後、/var/www/html/index.htmlファイルを作成してアクセスしていみます。

2017032101.JPG

タイムアウトを起こしました。

ポートの確認

以前はnetstatコマンドで確認していましたが、CentOS 7はssコマンドを使用して確認します。

# ss -nat
State      Recv-Q Send-Q              Local Address:Port                             Peer Address:Port
LISTEN     0      128                             *:22                                          *:*
LISTEN     0      100                     127.0.0.1:25                                          *:*
ESTAB      0      0                  192.168.56.106:22                               192.168.56.1:50242
ESTAB      0      64                 192.168.56.106:22                               192.168.56.1:64639
LISTEN     0      128                            :::80                                         :::*
LISTEN     0      128                            :::22                                         :::*
LISTEN     0      100                           ::1:25                                         :::*

80 portがListenされていることがわかります。

firewalldの確認

次に、firewalldを確認してみます。

# 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  2017-03-22 16:43:08 JST; 39min ago
 Main PID: 22589 (firewalld)
   CGroup: /system.slice/firewalld.service
           └─22589 /usr/bin/python -Es /usr/sbin/firewalld --nofork --nopid

 3 22 16:43:07 brighton005 systemd[1]: Starting firewalld - dynamic firewall daemon...
 3 22 16:43:08 brighton005 systemd[1]: Started firewalld - dynamic firewall daemon.

runningとなっているため、firewalldは起動しています。

firewalldが許可しているサービスを確認する

現在、有効な機能とゾーンを確認してみます。

# firewall-cmd --list-all
public (default, active)
  interfaces: enp0s3 enp0s8
  sources:
  services: dhcpv6-client ssh
  ports:
  masquerade: no
  forward-ports:
  icmp-blocks:
  rich rules:

または、以下のコマンドでも確認できます。

# firewall-cmd --list-service --zone=public
dhcpv6-client ssh

httpの機能がオープンされていないことがわかります。

httpを許可する

httpのポートを永続的に許可します。

# firewall-cmd --permanent --add-service=http
success

設定内容を反映させます。

# firewall-cmd --reload
success

反映されたことを確認します。

# firewall-cmd --list-all
public (default, active)
  interfaces: enp0s3 enp0s8
  sources:
  services: dhcpv6-client http ssh
  ports:
  masquerade: no
  forward-ports:
  icmp-blocks:
  rich rules:

httpが追加されたことがわかります。

Webブラウザから確認

Webブラウザからアクセスできることを確認します。

2017032102.JPG

参考:CentOS7のfirewalldでネットワークゾーンにhttpとhttpsの許可、sshで特定のポート、IPアドレスを許可する設定

1
2
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
1
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?