iptables-save → Преобразует текущие правила в текст.
iptables-restore → Преобразует текст из iptables-save в правила.
iptables по умолчанию резолвит host и port.
-n #Не резолвить host и port
iptables -L -v iptables -L -v -n # без резолва hostname
iptables -F INPUT
iptables -L НАЗВАНИЕ_ЦЕПОЧКИ --line-numbers iptables -D INPUT 10 #Для удаления 10ого правила в INPUT Для удаления "iptables -A INPUT -j DROP" используй iptables -D INPUT -j DROP
iptables -A INPUT -i lo -j ACCEPT iptables -A INPUT -m tcp -p tcp -s 127.0.0.0/8 -j ACCEPT iptables -A INPUT -m tcp -p tcp -s 78.108.88.0/23 -j ACCEPT # где 78.108.88.0/23 наша подсеть
Правила iptables грузятся из /etc/sysconfig/iptables при старте системы. Так что, iptables-save > /etc/sysconfig/iptables
iptables -A[INPUT|OUTPUT|FORWARD|Some_other] [-s 192.168.1.1] [-d 192.168.1.1] iptables -A[...] -p [tcp|udp] [--sport 11:222] [--dport 11:222] iptables -A[...] -m [limit --limit 5/second --limit-burst 10][mac --mac-source 00:00:00:00:00:01][multiport --source-port 22,53,80,110 --port 22,53,80,110] iptables -A[...] [-s 192.168.1.1] -j [Some_rool|ACCEPT|DROP|REJECT|DNAT --to-destination 192.168.1.1-192.168.1.10|LOG --log-prefix "Tumba-Umba " --log-level debug|REDIRECT --to-ports 8080|MASQUERADE|MIRROR|RETURN|ULOG]
iptables -t nat -A PREROUTING --dst $INET_IP -p tcp --dport 80 -j DNAT --to-destination $HTTP_IP #Чтобы внешние видели iptables -t nat -A POSTROUTING -p tcp --dst $HTTP_IP --dport 80 -j SNAT --to-source $FireWall_IP #Чтобы внутненние тоже видели iptables -t nat -A OUTPUT --dst $INET_IP -p tcp --dport 80 -j DNAT --to-destination $HTTP_IP #ЧТобы файрвол тоже видел
iptables -A INPUT -s 46.16.15.246 -j DROP
vi /etc/sysconfig/iptables -A INPUT -s 78.111.111.111 -j ACCEPT #добавляем /etc/init.d/iptables restart
-A INPUT -i lo -j ACCEPT -A INPUT -p tcp -m tcp --dport 443 -j DROP -A INPUT -p tcp -m tcp --dport 80 -j DROP
Chain INPUT (policy ACCEPT) target prot opt source destination MJ-RULES-IN all -- anywhere anywhere Chain FORWARD (policy ACCEPT) target prot opt source destination REJECT_LOG all -- anywhere anywhere Chain OUTPUT (policy ACCEPT) target prot opt source destination MJ-RULES-OUT all -- anywhere anywhere Chain LIMITS (9 references) target prot opt source destination ACCEPT all -- anywhere anywhere limit: avg 50/min burst 5 REJECT_LOG all -- anywhere anywhere Chain MJ-RULES-IN (1 references) target prot opt source destination ACCEPT all -- anywhere anywhere REJECT_LOG all -- anywhere loopback/8 ACCEPT all -- anywhere anywhere state RELATED,ESTABLISHED ACCEPT all -- anywhere anywhere ACCEPT tcp -- anywhere anywhere tcp dpt:ftp state NEW ACCEPT tcp -- anywhere anywhere tcp dpt:ssh state NEW ACCEPT tcp -- anywhere anywhere tcp dpt:smtp state NEW ACCEPT tcp -- anywhere anywhere tcp dpt:2525 state NEW ACCEPT tcp -- anywhere anywhere tcp dpt:www state NEW ACCEPT tcp -- anywhere anywhere tcp dpt:https state NEW ACCEPT tcp -- anywhere anywhere tcp dpt:pop3 state NEW ACCEPT tcp -- anywhere anywhere tcp dpt:imaps state NEW ACCEPT tcp -- anywhere anywhere tcp dpt:pop3s state NEW LIMITS icmp -- anywhere anywhere REJECT_LOG all -- anywhere anywhere Chain MJ-RULES-OUT (1 references) target prot opt source destination ACCEPT all -- anywhere anywhere state RELATED,ESTABLISHED ACCEPT all -- anywhere loopback/8 REJECT_LOG all -- anywhere loopback/8 ACCEPT all -- anywhere anywhere ACCEPT udp -- anywhere 78.108.80.0/20 udp dpt:domain state NEW LIMITS tcp -- anywhere anywhere tcp dpt:ftp LIMITS tcp -- anywhere anywhere tcp dpt:ssh LIMITS tcp -- anywhere anywhere tcp dpt:smtp LIMITS tcp -- anywhere anywhere tcp dpt:www LIMITS tcp -- anywhere anywhere tcp dpt:http-alt LIMITS tcp -- anywhere anywhere tcp dpt:pop3 LIMITS tcp -- anywhere anywhere tcp dpt:https LIMITS icmp -- anywhere anywhere REJECT_LOG all -- anywhere anywhere Chain REJECT_LOG (6 references) target prot opt source destination LOG all -- anywhere anywhere limit: avg 1/min burst 5 LOG level alert prefix `REJECT : ' REJECT all -- anywhere anywhere reject-with icmp-port-unreachable
Discussion
временно открываем себе доступ
Логирование
Чтобы залоигировать, нужно добавить отдельную строчку перед целевым правилом:
После этого, можно смотреть логи попавшие на правило в файле /var/log/kernel.log
Так же, будет полезно обнулить счетчики iptables -Z
Когда логирование закончено, просто удаляем наше правило