CentOS 7 の firewalld
CentOS 7 の firewalld で,http, https 接続を許可して,ssh は送信元IPアドレスを制限する。
CentOS 7 は VittualBox 上に vagrant で作成した。Windows に vagrant をインストールしておくと,出来合いの CentOS 7 仮想マシンがネット経由で作成できる。
https://royalwin.blog.so-net.ne.jp/2018-12-16
初期設定は dhcpv6-client sshサービスが許可されていた。
[root@localhost vagrant]# 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:
始めに http https 接続を許可する。
firewall-cmd --zone=public --add-service=http
firewall-cmd --zone=public --add-service=https
ssh は送信元制限を行うリッチルールを設定する。192.168.0.109 と 192.168.0.110 からの ssh 接続を許可する。
firewall-cmd --zone=public --add-rich-rule="rule family="ipv4" source address="192.168.0.109" port protocol="tcp" port="22" accept"
firewall-cmd --zone=public --add-rich-rule="rule family="ipv4" source address="192.168.0.110" port protocol="tcp" port="22" accept"
初期設定の ssh 接続全部許可を削除する。
firewall-cmd --zone=public --remove-service=ssh
firewall-cmd --list-all でランタイム状態を確認する。
[root@localhost vagrant]# firewall-cmd --list-all
public (active)
target: default
icmp-block-inversion: no
interfaces: eth0
sources:
services: dhcpv6-client https http
ports:
protocols:
masquerade: no
forward-ports:
source-ports:
icmp-blocks:
rich rules:
rule family="ipv4" source address="192.168.0.109" port port="22" protocol="tcp" accept
rule family="ipv4" source address="192.168.0.110" port port="22" protocol="tcp" accept
ランタイムの変更は再起動時に消えて無効になってしまうので,runtime を permanent にする。
firewall-cmd --runtime-to-permanent
firewall-cmd –permanent でコマンドを実行した場合は保存されるが,リアルタイムに有効にならない。
その場合は,firewall-cmd –reload の実行で有効になる。
コメント 0