UbuntuでOS再起動後もiptablesの設定を有効化させる方法

概要

UbuntuでOS再起動後iptablesの情報が読み込まれずハマった。

インストール

apt-get install iptables-persistent

このパッケージを入れると設定ファイルに書き出してくれる。

依存関係で netfilter-persistent パッケージがインストールされる。

/etc/iptables/rules.v4

に書き出される。

保存

service netfilter-persistent save


読み込み

service netfilter-persistent reload


デーモンの起動

systemctl status netfilter-persistent.service


自動起動設定

systemctl enable netfilter-persistent.service


依存関係

# apt-cache depends netfilter-persistent
netfilter-persistent
  Depends: lsb-base
  Depends: init-system-helpers
  Breaks: iptables-persistent
  Suggests: iptables-persistent
  Replaces: iptables-persistent


# apt-cache rdepends netfilter-persistent
netfilter-persistent
Reverse Depends:
  iptables-persistent


パッケージの中身

# dpkg -L iptables-persistent
/.
/etc
/etc/iptables
/usr
/usr/share
/usr/share/doc
/usr/share/doc/iptables-persistent
/usr/share/doc/iptables-persistent/copyright
/usr/share/netfilter-persistent
/usr/share/netfilter-persistent/plugins.d
/usr/share/netfilter-persistent/plugins.d/15-ip4tables
/usr/share/netfilter-persistent/plugins.d/25-ip6tables
/usr/share/doc/iptables-persistent/README
/usr/share/doc/iptables-persistent/changelog.gz


# dpkg -L netfilter-persistent
/.
/etc
/etc/default
/etc/default/netfilter-persistent
/etc/init.d
/etc/init.d/netfilter-persistent
/lib
/lib/systemd
/lib/systemd/system
/lib/systemd/system/netfilter-persistent.service
/usr
/usr/sbin
/usr/sbin/netfilter-persistent
/usr/share
/usr/share/doc
/usr/share/doc/netfilter-persistent
/usr/share/doc/netfilter-persistent/README
/usr/share/doc/netfilter-persistent/changelog.gz
/usr/share/doc/netfilter-persistent/copyright
/usr/share/man
/usr/share/man/man8
/usr/share/man/man8/netfilter-persistent.8.gz
/usr/share/netfilter-persistent
/usr/share/netfilter-persistent/plugins.d