LoginSignup
38
39

More than 5 years have passed since last update.

Ubuntuでiptablesを再起動後にも保持する方法

Last updated at Posted at 2016-10-29

やりたいこと

Ubuntuでiptablesの設定を保持したい。
他のディストリだと

~/
sudo iptables save

とかで出来ちゃうんだけども、Ubuntuだと何故か出来ない。

環境

Ubuntu 16.04 LTS

方法

iptables-persistentを使えば簡単に出来る。

~/ 16.04より古い方はapt-getで
sudo apt install iptables-persistent

おわり。めっちゃ簡単。rebootしてみて設定が残ってるか確認してね。

~/ 再起動後
sudo iptables --list

ちなみに

直接保存や再読込をさせることも出来ます。

~/ 保存と再読込
sudo /etc/init.d/netfilter-persistent save
sudo /etc/init.d/netfilter-persistent reload

やったぜ。

ちなみ2

UbuntuでパーソナルFWを使用するならiptablesをそのまま使うよりもufwが便利です。(ufwはiptablesのラッパーです。)
特別なこだわりの無い方はufw使って幸せになりましょう。
http://qiita.com/tukiyo3/items/56525cb1b30cdd19fade

また、以下の様な方法を用いることでiptablesでしか書けない処理をufwに追記することが出来ます。便利ですね。
Ubuntu の ufw で NAT サーバを作る

参考文献

38
39
1

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
38
39