目次

iptables

コマンド

iptables -nvL

iptables -nvL –line-numbers

iptables -t nat -nvL

文法

! を付ける

セキュリティ

hashlimit

通過する NIC は eth0, 送信元は 1.2.3.0/24

  iptables -A INPUT -p tcp -m state --syn --state NEW --dport 22 -i eth0 -s 1.2.3.0/24 -m hashlimit --hashlimit-name t_sshd --hashlimit 1/m --hashlimit-burst 2 --hashlimit-mode srcip --hashlimit-htable-expire 60000 -j ACCEPT 
* UDP\\ 
  連続した UDP のパケットを防ぐ場合、ESTABLISHED 許可よりも前に hashlimit を定義しておく。\\ 
  UDP のパケットが 1度通過すると、しばらくの間 ESTABLISHED の状態が続くため。\\ 
  <code> 

iptables -A INPUT -p udp –dport 53 -m hashlimit –hashlimit-name t_dns –hashlimit 1/m –hashlimit-burst 4 –hashlimit-mode srcip –hashlimit-htable-expire 65000 -j ACCEPT
iptables -A INPUT -p udp –dport 53 -j LOG –log-prefix '[IPTABLES_UDP_DNS_DROP] : ' –log-level=debug
iptables -A INPUT -p udp –dport 53 -j DROP
iptables -A INPUT -m state –state ESTABLISHED,RELATED -j ACCEPT
</code>

 
iptables -N DNS_LIMIT 
iptables -A DNS_LIMIT -p udp --dport 53 -m hashlimit --hashlimit-name t_dns --hashlimit 1/m --hashlimit-burst 4 --hashlimit-mode srcip --hashlimit-htable-expire 65000 -j ACCEPT 
iptables -A DNS_LIMIT -p udp --dport 53 -j LOG --log-prefix '[IPTABLES_DNS_DROP] : ' --log-level=debug 
iptables -A DNS_LIMIT -p udp --dport 53 -j DROP 

# その他の定義 

iptables -A INPUT -j DNS_LIMIT 
iptables -A INPUT  -m state --state ESTABLISHED,RELATED  -j ACCEPT 

recent

 
iptables -N SSH_RECENT 
iptables -A SSH_RECENT -p tcp --dport 22 -m state --syn --state NEW -m recent --set --name ssh_attack 
iptables -A SSH_RECENT -p tcp --dport 22 -m state --syn --state NEW -m recent --update --seconds 10 --hitcount 3 --rttl --name ssh_attack -j LOG --log-prefix '[SSH_DROP]' 
iptables -A SSH_RECENT -p tcp --dport 22 -m state --syn --state NEW -m recent --update --seconds 10 --hitcount 3 --rttl --name ssh_attack -j DROP 
iptables -A INPUT -j SSH_RECENT 

sudo vi /etc/modprobe.d/iptables.conf

  (/etc/modprobe.d ディレクトリに作成するファイル名は何でも良い)\\ 
  <code>options ipt_recent ip_pkt_list_tot=100</code>