Temat: Własny firewall
Czytam sobie szereg linków na temat tego jak przerobić ten wbudowany filtr pakietów na coś bardziej przejrzystego, min. te poniższe kawałki:
http://eko.one.pl/?p=openwrt-customfirewall
http://wiki.openwrt.org/doc/uci/firewall
Udało mi się pozbyć niepotrzebnych modułów i całkowicie wyłączyć zaporę. Po tym wyczynie napisałem sobie małego skrypta, który ustawia parę reguł. Wprawdzie jest on jeszcze nie kompletny, bo nie ma implementacji tc, fwknop , ipseta i tam paru jeszcze innych rzeczy ale chciałbym by ktoś rzucił okiem na te poniższe regułki i powiedział czy czegoś tam brakuje lub/i czy coś się da poprawić.
iptables -t raw -N notrack_in
iptables -t raw -A notrack_in -i lo -j NOTRACK
iptables -t raw -A notrack_in -i lo -j ACCEPT
iptables -t nat -A PREROUTING -i eth0 -p tcp --dport 12345 -j DNAT --to 192.168.1.150
iptables -t nat -A PREROUTING -i eth0 -p udp --dport 12345 -j DNAT --to 192.168.1.150
iptables -t nat -A POSTROUTING -o eth0 -s 192.168.1.0/24 -j MASQUERADE
iptables -t filter -P INPUT DROP
iptables -t filter -P FORWARD DROP
iptables -t filter -P OUTPUT ACCEPT
iptables -t filter -N tcp
iptables -t filter -N udp
iptables -t filter -N icmp_in
iptables -t filter -N fw-interfaces
iptables -t filter -N fw-open
iptables -t filter -N fwknop_input
iptables -t filter -A INPUT -m conntrack --ctstate RELATED,ESTABLISHED -j ACCEPT
iptables -t filter -A INPUT -i lo -j ACCEPT
iptables -t filter -A INPUT -m conntrack --ctstate INVALID -j DROP
iptables -t filter -A INPUT -p icmp -j icmp_in
iptables -t filter -A INPUT -p udp -m conntrack --ctstate NEW -j udp
# iptables -t filter -A INPUT -p tcp ! --syn -m conntrack --ctstate NEW -j DROP -m comment --comment "Connections not started by SYN"
iptables -t filter -A INPUT -p tcp -m tcp --tcp-flags FIN,SYN,RST,ACK SYN -m conntrack --ctstate NEW -j tcp
iptables -t filter -A INPUT -p tcp -m recent --set --name tcp-portscan -j REJECT --reject-with tcp-reset
iptables -t filter -A INPUT -p udp -m recent --set --name udp-portscan -j REJECT --reject-with icmp-port-unreachable
iptables -t filter -A INPUT -j REJECT --reject-with icmp-proto-unreachable
iptables -t filter -A OUTPUT -m conntrack --ctstate INVALID -j DROP
iptables -t filter -A FORWARD -m conntrack --ctstate RELATED,ESTABLISHED -j ACCEPT
iptables -t filter -A FORWARD -m conntrack --ctstate INVALID -j DROP
iptables -t filter -A FORWARD -j fw-interfaces
iptables -t filter -A FORWARD -j fw-open
iptables -t filter -A FORWARD -j REJECT --reject-with icmp-host-unreachable
iptables -t filter -A icmp_in -p icmp -i br-lan -s 192.168.1.0/24 -m conntrack --ctstate NEW -j ACCEPT
iptables -t filter -A icmp_in -p icmp -m conntrack --ctstate NEW -j LOG --log-prefix "* IPTABLES: ICMP_NEW * "
# iptables -t filter -A icmp_in -p icmp -m conntrack --ctstate NEW -j SET --add-set autoban src --timeout 7200
iptables -t filter -A icmp_in -p icmp -m icmp --icmp-type echo-request -m conntrack --ctstate NEW -j DROP -m comment --comment "echo-request"
iptables -t filter -A icmp_in -p icmp -m icmp --icmp-type timestamp-request -j DROP -m comment --comment "timestamp-request"
iptables -t filter -A icmp_in -p icmp -m conntrack --ctstate NEW -j DROP
iptables -t filter -A udp -p udp -m recent --update --seconds 600 --name udp-portscan -j REJECT --reject-with icmp-port-unreachable
# iptables -t filter -A udp -p udp --dport 12345 -m conntrack --ctstate NEW -j ACCEPT -m comment --comment "torrent"
iptables -t filter -A udp -p udp -i br-lan -s 192.168.1.0/24 -j ACCEPT
# iptables -t filter -A udp -p udp -s 192.168.22.22 --dport 68 -m comment --comment "Allow-DHCP-Renew" -j ACCEPT
iptables -t filter -A tcp -p tcp -m recent --update --seconds 600 --name tcp-portscan -j REJECT --reject-with tcp-reset
# iptables -t filter -A tcp -p tcp --dport 12345 -m conntrack --ctstate NEW -j ACCEPT -m comment --comment "torrent"
iptables -t filter -A tcp -p tcp -i br-lan -s 192.168.1.0/24 -j ACCEPT
iptables -t filter -A fw-interfaces -i br-lan -s 192.168.1.0/24 -j ACCEPT
iptables -t filter -A fw-open -i eth0 -o br-lan -d 192.168.1.150 -p tcp --dport 12345 -j ACCEPT
iptables -t filter -A fw-open -i eth0 -o br-lan -d 192.168.1.150 -p udp --dport 12345 -j ACCEPT