iptables 
top

Gentoo Linuxでiptablesを使う。

起動時

/etc/conf.d/iptablesに設定が書かれている。

# Location in which iptables initscript will save set rules on
# service shutdown
IPTABLES_SAVE="/var/lib/iptables/rules-save"

# Change to "yes" to enable forwarding support in the kernel.  Please
# note that this will override any setting placed in /etc/sysctl.conf.
ENABLE_FORWARDING_IPv4="no"
ENABLE_FORWARDING_IPv6="no"

再起動した時には、/var/lib/iptables/rules-saveに書かれたルールが読み込まれる。 /etc/init.d/iptables stopを実行すると、現在のルールがこのファイルに書き込まれる。

コマンド

現在のパケットフィルタの設定を見る(-L) iptables -L

設定

このマシン上で動いているapacheをLANからしかアクセスできなくする。

iptables -A INPUT -p tcp --dport 80 -d 192.168.0.100 -s 192.168.0.0/24 -j ACCEPT
iptables -A INPUT -p tcp --dport 80 -d 192.168.0.100 -j DENY

アクセスを拒否する際、ログを残す

iptables -A INPUT -p tcp --dport 80 -d 192.168.0.100 -s 192.168.0.0/24 -j ACCEPT
# iptables -A INPUT -p tcp --dport 80 -j LOG --syn --log-prefix 'FILTER:'
iptables -A INPUT -p tcp --dport 80 -d 192.168.0.100 -j DENY
SSH接続をログに残す #### imported