linux:commands:network:iptables

iptables

filter テーブル

$ sudo iptables -nL

※管理者でパスが通っていない場合は、以下のように呼び出す必要がある。

$ sudo /sbin/iptables -nL

nat テーブル

$ sudo iptables -t nat -nL

nat テーブルの PREROUTING チェイン

$ sudo iptables -t nat -nL PREROUTING
$ sudo iptables -t nat -A PREROUTING -i eth1 -p tcp -m tcp --dport 80 -j REDIRECT --to-ports 3128
$ sudo iptables -t nat -A PREROUTING -i eth1 -p tcp -m tcp --dport 443 -j REDIRECT --to-ports 3129

$ sudo iptables -t nat -nL PREROUTING
Chain PREROUTING (policy ACCEPT)
target     prot opt source               destination
REDIRECT   tcp  --  0.0.0.0/0            0.0.0.0/0            tcp dpt:80 redir ports 3128
REDIRECT   tcp  --  0.0.0.0/0            0.0.0.0/0            tcp dpt:443 redir ports 3129

iptables -t <table> -nL <chain> –line-numbers - ルール番号の表示
iptables -t <table> -D <chain> <rule num> - ルールの削除

$ sudo iptables -t nat -nL PREROUTING --line-numbers
Chain PREROUTING (policy ACCEPT)
num  target     prot opt source               destination
1    REDIRECT   tcp  --  0.0.0.0/0            0.0.0.0/0            tcp dpt:80 redir ports 3128
2    REDIRECT   tcp  --  0.0.0.0/0            0.0.0.0/0            tcp dpt:443 redir ports 3129

$ sudo iptables -t nat -D PREROUTING 2
$ sudo iptables -t nat -D PREROUTING 1

$ sudo iptables -t nat -nL PREROUTING --line-numbers
Chain PREROUTING (policy ACCEPT)
num  target     prot opt source               destination
$ sudo iptables-save
$ sudo iptables-save > iptables_save.txt
$ sudo iptables-restore < iptables_save.txt
  • linux/commands/network/iptables.txt
  • 最終更新: 2020/02/10 08:53
  • by ともやん