computerの日記

Cisco,SHELL,C,Qt,C++,Linux,ネットワーク,Windows Scriptなどの発言です

CentOS 7系 で firewalld ではなく iptables を使う

CentOS 7系では、firewalld がデフォルトですが、iptables を使うこともできます。

以下、手順となります。

 

1. iptables-services パッケージをインストールする

# yum install iptables-services

ls -la /etc/sysconfig/iptables

設定ファイルが、既にファイル化されていました。

 

2.  firewalld が吐いたポリシを、iptables のポリシに変換する

# iptables -S | tee ~/firewalld_iptables_rules
# ip6tables -S | tee ~/firewalld_ip6tables_rules

 以下のようなコマンドで、firewalld のポリシを /etc/sysconfig/iptables にコピペできるようになると思います。これでひっかからないものでも、作成したものを忘れずにコピーしましょう。

grep 'ACCEPT\|DROP\|QUEUE\|RETURN\|REJECT\|LOG' ~/firewalld_iptables_rules > firewalld_iptables_rules_x

適宜、firewalld のポリシルールを /etc/sysconfig/iptables にコピーします。

 

3. サービス起動の設定

firewalld が立ち上がらないようにして、iptables が立ち上がるようにしましょう。

# systemctl disable firewalld.service

# systemctl mask firewalld.service

# systemctl enable iptables.service

システム再起動

 

4. 調整

# systemctl status iptables.service

うまく立ち上がっていなかったら、ログを見て、調整してください。

たぶん、firewalld 特有の設定をコピーしているのかもしれませんので、適宜直してください。

 

(参考)
https://www.digitalocean.com/community/tutorials/how-to-migrate-from-firewalld-to-iptables-on-centos-7