[[iptables設定例]]
差分
この文書の現在のバージョンと選択したバージョンの差分を表示します。
| — |
iptables設定例 [2009/02/07 23:29] (現在) ebi 作成 |
||
|---|---|---|---|
| ライン 1: | ライン 1: | ||
| + | ====== 規定のポリシーを設定する ====== | ||
| + | たとえば規定でINPUTは許可、FORWARDは不許可、OUTPUTは許可とするには以下のようにする。 | ||
| + | <code bash> | ||
| + | iptables -P INPUT ACCEPT | ||
| + | iptables -P FORWARD DROP | ||
| + | iptables -P OUTPUT ACCEPT | ||
| + | </code> | ||
| + | ====== IP Masquerade設定(NAT設定) ====== | ||
| + | eth0から出て行く際にNAT変換されるようにする。(SourceのIPアドレスが全てeth0のアドレスになる) | ||
| + | <code bash> | ||
| + | iptables -t nat -A POSTROUTING -o eth0 -jMASQUERADE | ||
| + | </code> | ||
| + | |||
| + | ====== 1対1NAT設定 ====== | ||
| + | A.A.A.A(グローバルIPアドレス)とB.B.B.B(プライベートIPアドレス)を対応付ける。 | ||
| + | <code bash> | ||
| + | iptables -t nat -A PREROUTING -d <A.A.A.A> -j DNAT --to-destination B.B.B.B | ||
| + | iptables -t nat -A POSTROUTING -s <B.B.B.B> -j SNAT --to-source <A.A.A.A> | ||
| + | </code> | ||
| + | |||
| + | ====== 特定ホストへのポート指定の通信許可 ====== | ||
| + | B.B.B.B(プライベートIPアドレス)への通信に関してC(ポート番号)を許可する。 | ||
| + | <code bash> | ||
| + | iptables -A FORWARD -p tcp -d <B.B.B.B> --destination-port <C> -j ACCEPT | ||
| + | </code> | ||
| + | |||
| + | ====== 特定ポートへの通信許可 ====== | ||
| + | 自身へのC(ポート番号)への通信を許可する | ||
| + | <code bash> | ||
| + | iptables -A INPUT -p tcp --destination-port <C> -j ACCEPT | ||
| + | </code> | ||
| + | |||
| + | ====== 特定のIPアドレスからのHTTP通信を不許可 ====== | ||
| + | <code bash> | ||
| + | iptables -I INPUT -p tcp -s <SOURCE IPADDR> --destination-port 80 -j DROP | ||
| + | </code> | ||
| + | |||
| + | ====== 設定例 ====== | ||
| + | <code bash> | ||
| + | iptables -A INPUT -p icmp -j ACCEPT | ||
| + | iptables -A INPUT -i lo -j ACCEPT | ||
| + | iptables -A INPUT -p tcp --dport 80 -j ACCEPT | ||
| + | iptables -A INPUT -p tcp --dport 21 -j ACCEPT | ||
| + | iptables -A INPUT -p tcp --dport 110 -j ACCEPT | ||
| + | iptables -A INPUT -p tcp --dport 25 -j ACCEPT | ||
| + | iptables -A INPUT -p tcp --dport 22 -j ACCEPT | ||
| + | iptables -A INPUT -p tcp --dport 143 -j ACCEPT | ||
| + | iptables -A INPUT -m state --state ESTABLISHED,RELATED -j ACCEPT | ||
| + | iptables -P INPUT DROP | ||
| + | </code> | ||
