Re: Router na SBC z Debianem - jak skonfigurować firewall
: 26 września 2016, 10:16
Pokaż te obecne regułki, bo nie mam się do czego odnieść.
Polski portal użytkowników dystrybucji Debian GNU/Linux, dyskusje, artykuły, nowości, blog, porady, pomoc.
https://www.debian.pl/
To teraz tak:dedito pisze:Pokaż te obecne regułki, bo nie mam się do czego odnieść.
Kod: Zaznacz cały
#!/bin/bash
### BEGIN INIT INFO
# Provides: firewall.sh
# Required-Start: $local_fs $remote_fs
# Required-Stop: $local_fs $remote_fs
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Short-Description: Start daemon at boot time
# Description: Enable service provided by daemon.
### END INIT INFO
# CZYSZCZENIE STARYCH REGUŁ
iptables -F
iptables -X
iptables -F -t nat
iptables -X -t nat
iptables -F -t filter
iptables -X -t filter
# USTAWIENIE POLITYKI DZIAŁANIA
iptables -P INPUT DROP
iptables -P FORWARD DROP
iptables -P OUTPUT ACCEPT
iptables -A INPUT -i lo -j ACCEPT
iptables -A INPUT -m state --state ESTABLISHED,RELATED -j ACCEPT
iptables -A INPUT -p icmp --icmp-type echo-request -j REJECT --reject-with icmp-host-unreachable
# OCHRONA PRZED SKANOWANIEM ACK SCAN
iptables -A INPUT -m conntrack --ctstate NEW -p tcp --tcp-flags SYN,RST,ACK,FIN,URG,PSH ACK -j LOG --log-prefix "ACK scan: "
iptables -A INPUT -m conntrack --ctstate NEW -p tcp --tcp-flags SYN,RST,ACK,FIN,URG,PSH ACK -j DROP # Metoda ACK (nmap -sA)
#OCHRONA PRZED SKANOWANIEM FIN SCAN
iptables -A INPUT -m conntrack --ctstate NEW -p tcp --tcp-flags SYN,RST,ACK,FIN,URG,PSH FIN -j LOG --log-prefix "FIN scan: "
iptables -A INPUT -m conntrack --ctstate NEW -p tcp --tcp-flags SYN,RST,ACK,FIN,URG,PSH FIN -j DROP # Skanowanie FIN (nmap -sF)
#OCHRONA PRZED SKANOWANIEM XMAS TREE SCAN
iptables -A INPUT -m conntrack --ctstate NEW -p tcp --tcp-flags SYN,RST,ACK,FIN,URG,PSH PSH -j LOG --log-prefix "Xmas scan: "
iptables -A INPUT -m conntrack --ctstate NEW -p tcp --tcp-flags SYN,RST,ACK,FIN,URG,PSH FIN,URG,PSH -j DROP # Metoda Xmas Tree (nmap -sX)
#OCHRONA PRZED SKANOWANIEM NULL SCAN
iptables -A INPUT -m conntrack --ctstate INVALID -p tcp ! --tcp-flags SYN,RST,ACK,FIN,PSH,URG SYN,RST,ACK,FIN,PSH,URG -j LOG --log-prefix "Null scan: "
#OCHRONA PRZED ATAKIEM Dos
iptables -A INPUT -m conntrack --ctstate INVALID -p tcp ! --tcp-flags SYN,RST,ACK,FIN,PSH,URG SYN,RST
iptables -N syn-flood
iptables -A INPUT -p tcp --syn -j syn-flood
iptables -A syn-flood -m limit --limit 1/s --limit-burst 4 -j RETURN
iptables -A syn-flood -m limit --limit 1/s --limit-burst 4 -j LOG --log-prefix "SYN-flood: "
iptables -A syn-flood -j DROP
# OCHRONA PRZED ATAKIEM PING OF DEATH
iptables -A INPUT -p icmp --icmp-type echo-request -m limit --limit 1/s -j LOG --log-prefix "Ping: "
iptables -A INPUT -p icmp --icmp-type echo-request -m limit --limit 1/s -j ACCEPT # Ping of death
# ZABLOKOWANIE PINGOWANIA
iptables -A INPUT -p icmp --icmp-type echo-request -j REJECT --reject-with icmp-host-unreachable
# BLOKOWANIE TELNETU
iptables -A OUTPUT -p tcp --dport telnet -j REJECT
iptables -A INPUT -p tcp --dport telnet -j REJECT
# MASKARADA
iptables -t nat -A POSTROUTING -o ppp0 -j MASQUERADE
iptables -A FORWARD -i ppp0 -o eth1 -m state --state RELATED,ESTABLISHED -j ACCEPT
iptables -A FORWARD -i eth1 -o ppp0 -j ACCEPT
iptables -A FORWARD -i ppp0 -o wlan0 -m state --state RELATED,ESTABLISHED -j ACCEPT
iptables -A FORWARD -i wlan0 -o ppp0 -j ACCEPT
# ODBLOKOWANIE DHCP
iptables -I INPUT -i eth1 -p udp --dport 67:68 --sport 67:68 -j ACCEPT
iptables -I INPUT -i wlan0 -p udp --dport 67:68 --sport 67:68 -j ACCEPT
# ODBLOKOWANIE WWW
iptables -A INPUT -p tcp -m tcp --dport 80 -j ACCEPT
#ZAPIS DO LOGA ODRZUCONYCH PAKIETÓW PRZYCHODZĄCYCH W KATALOGU var/log/messages
iptables -N LOGGING
iptables -A INPUT -j LOGGING
iptables -A LOGGING -m limit --limit 2/min -j LOG --log-prefix "IPTables-Dropped: " --log-level 4
iptables -A LOGGING -j DROP
Kod: Zaznacz cały
# USTAWIENIE POLITYKI DZIAŁANIA
iptables -P INPUT DROP
iptables -P FORWARD DROP
iptables -P OUTPUT ACCEPT
Kod: Zaznacz cały
# MASKARADA
iptables -t nat -A POSTROUTING -o ppp0 -j MASQUERADE
iptables -A FORWARD -i ppp0 -o eth1 -m state --state RELATED,ESTABLISHED -j ACCEPT
iptables -A FORWARD -i eth1 -o ppp0 -j ACCEPT
iptables -A FORWARD -i ppp0 -o wlan0 -m state --state RELATED,ESTABLISHED -j ACCEPT
iptables -A FORWARD -i wlan0 -o ppp0 -j ACCEPT
Kod: Zaznacz cały
# ODBLOKOWANIE DHCP
iptables -I INPUT -i eth1 -p udp --dport 67:68 --sport 67:68 -j ACCEPT
iptables -I INPUT -i wlan0 -p udp --dport 67:68 --sport 67:68 -j ACCEPT
Kod: Zaznacz cały
iptables -nvL && iptables -t nat -nvL
dedito pisze:Obecny stan firewalla w zakresie potrzebnym do tego wątku:Kod: Zaznacz cały
iptables -nvL && iptables -t nat -nvL
Kod: Zaznacz cały
root@orangepipcplus:~# iptables -nvL && iptables -t nat -nvL
Chain INPUT (policy DROP 0 packets, 0 bytes)
pkts bytes target prot opt in out source destination
0 0 ACCEPT udp -- wlan0 * 0.0.0.0/0 0.0.0.0/0 udp spts:67:68 dpts:67:68
0 0 ACCEPT udp -- eth1 * 0.0.0.0/0 0.0.0.0/0 udp spts:67:68 dpts:67:68
0 0 ACCEPT all -- lo * 0.0.0.0/0 0.0.0.0/0
13 924 ACCEPT all -- * * 0.0.0.0/0 0.0.0.0/0 state RELATED,ESTABLISHED
0 0 REJECT icmp -- * * 0.0.0.0/0 0.0.0.0/0 icmptype 8 reject-with icmp-host-unreachable
0 0 LOG tcp -- * * 0.0.0.0/0 0.0.0.0/0 ctstate NEW tcp flags:0x3F/0x10 LOG flags 0 level 4 prefix "ACK scan: "
0 0 DROP tcp -- * * 0.0.0.0/0 0.0.0.0/0 ctstate NEW tcp flags:0x3F/0x10
0 0 LOG tcp -- * * 0.0.0.0/0 0.0.0.0/0 ctstate NEW tcp flags:0x3F/0x01 LOG flags 0 level 4 prefix "FIN scan: "
0 0 DROP tcp -- * * 0.0.0.0/0 0.0.0.0/0 ctstate NEW tcp flags:0x3F/0x01
0 0 LOG tcp -- * * 0.0.0.0/0 0.0.0.0/0 ctstate NEW tcp flags:0x3F/0x08 LOG flags 0 level 4 prefix "Xmas scan: "
0 0 DROP tcp -- * * 0.0.0.0/0 0.0.0.0/0 ctstate NEW tcp flags:0x3F/0x29
0 0 LOG tcp -- * * 0.0.0.0/0 0.0.0.0/0 ctstate INVALID tcp flags:!0x3F/0x3F LOG flags 0 level 4 prefix "Null scan: "
0 0 tcp -- * * 0.0.0.0/0 0.0.0.0/0 ctstate INVALID tcp flags:!0x3F/0x06
0 0 syn-flood tcp -- * * 0.0.0.0/0 0.0.0.0/0 tcp flags:0x17/0x02
0 0 LOG icmp -- * * 0.0.0.0/0 0.0.0.0/0 icmptype 8 limit: avg 1/sec burst 5 LOG flags 0 level 4 prefix "Ping: "
0 0 ACCEPT icmp -- * * 0.0.0.0/0 0.0.0.0/0 icmptype 8 limit: avg 1/sec burst 5
0 0 REJECT icmp -- * * 0.0.0.0/0 0.0.0.0/0 icmptype 8 reject-with icmp-host-unreachable
0 0 REJECT tcp -- * * 0.0.0.0/0 0.0.0.0/0 tcp dpt:23 reject-with icmp-port-unreachable
0 0 ACCEPT tcp -- * * 0.0.0.0/0 0.0.0.0/0 tcp dpt:80
3 1728 LOGGING all -- * * 0.0.0.0/0 0.0.0.0/0
Chain FORWARD (policy DROP 0 packets, 0 bytes)
pkts bytes target prot opt in out source destination
1 98 ACCEPT all -- ppp0 eth1 0.0.0.0/0 0.0.0.0/0 state RELATED,ESTABLISHED
2 150 ACCEPT all -- eth1 ppp0 0.0.0.0/0 0.0.0.0/0
0 0 ACCEPT all -- ppp0 wlan0 0.0.0.0/0 0.0.0.0/0 state RELATED,ESTABLISHED
0 0 ACCEPT all -- wlan0 ppp0 0.0.0.0/0 0.0.0.0/0
Chain OUTPUT (policy ACCEPT 7 packets, 880 bytes)
pkts bytes target prot opt in out source destination
0 0 REJECT tcp -- * * 0.0.0.0/0 0.0.0.0/0 tcp dpt:23 reject-with icmp-port-unreachable
Chain LOGGING (1 references)
pkts bytes target prot opt in out source destination
3 1728 LOG all -- * * 0.0.0.0/0 0.0.0.0/0 limit: avg 2/min burst 5 LOG flags 0 level 4 prefix "IPTables-Dropped: "
3 1728 DROP all -- * * 0.0.0.0/0 0.0.0.0/0
Chain syn-flood (1 references)
pkts bytes target prot opt in out source destination
0 0 RETURN all -- * * 0.0.0.0/0 0.0.0.0/0 limit: avg 1/sec burst 4
0 0 LOG all -- * * 0.0.0.0/0 0.0.0.0/0 limit: avg 1/sec burst 4 LOG flags 0 level 4 prefix "SYN-flood: "
0 0 DROP all -- * * 0.0.0.0/0 0.0.0.0/0
Chain PREROUTING (policy ACCEPT 0 packets, 0 bytes)
pkts bytes target prot opt in out source destination
Chain INPUT (policy ACCEPT 0 packets, 0 bytes)
pkts bytes target prot opt in out source destination
Chain OUTPUT (policy ACCEPT 0 packets, 0 bytes)
pkts bytes target prot opt in out source destination
Chain POSTROUTING (policy ACCEPT 0 packets, 0 bytes)
pkts bytes target prot opt in out source destination
0 0 MASQUERADE all -- * ppp0 0.0.0.0/0 0.0.0.0/0
dedito pisze:Nie widzę abyś zezwolił na przekazywanie pakietów odpowiednią zmienną w kernelu.
Kod: Zaznacz cały
root@orangepipcplus:~# cat /proc/sys/net/ipv4/ip_forward
1
Miałeś czuja - pinguje. Czyli mam problem z DNS.dedito pisze:A z eth1 działa ping na np: 8.8.8.8 ?
Kod: Zaznacz cały
# IPv4
nameserver 208.67.222.222
nameserver 208.67.220.220
nameserver 208.67.222.220
nameserver 208.67.220.222
# IPv6
nameserver 2620:0:ccc::2
nameserver 2620:0:ccd::2
Niestety nie rozumiem tego. Cała moja konfiguracja DHCP to ten dnsmasq.conf:dedito pisze:Jeśli w DHCP skonfigurowałeś, że brama jest jednocześnie serwerem DNS to chyba jest powód problemów.
Kod: Zaznacz cały
# nasłuchiwanie
interface=eth1
interface=wlan0
# zakresy adresów
dhcp-range=eth1,192.168.1.100,192.168.1.150,12h
dhcp-range=wlan0,192.168.2.100,192.168.2.150,2h
dhcp-host=XX:XX:XX:XX:XX:XX,192.168.1.100
Kod: Zaznacz cały
#!/bin/bash
### BEGIN INIT INFO
# Provides: firewall.sh
# Required-Start: $local_fs $remote_fs
# Required-Stop: $local_fs $remote_fs
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Short-Description: Start daemon at boot time
# Description: Enable service provided by daemon.
### END INIT INFO
# CZYSZCZENIE STARYCH REGUŁ
iptables -F
iptables -X
iptables -F -t nat
iptables -X -t nat
iptables -F -t filter
iptables -X -t filter
# USTAWIENIE POLITYKI DZIAŁANIA
iptables -P INPUT DROP
iptables -P FORWARD DROP
iptables -P OUTPUT ACCEPT
iptables -A INPUT -i lo -j ACCEPT
iptables -A INPUT -m state --state ESTABLISHED,RELATED -j ACCEPT
iptables -A INPUT -p icmp --icmp-type echo-request -j REJECT --reject-with icmp-host-unreachable
# ODBLOKOWANIE DNS
iptables -I INPUT -i eth1 -p tcp --dport 53 -j ACCEPT
iptables -I INPUT -i wlan0 -p tcp --dport 53 -j ACCEPT
iptables -I INPUT -i eth1 -p udp --dport 53 -j ACCEPT
iptables -I INPUT -i wlan0 -p udp --dport 53 -j ACCEPT
# ODBLOKOWANIE DHCP
iptables -I INPUT -i eth1 -p udp --dport 67:68 --sport 67:68 -j ACCEPT
iptables -I INPUT -i wlan0 -p udp --dport 67:68 --sport 67:68 -j ACCEPT
# OCHRONA PRZED SKANOWANIEM ACK SCAN
iptables -A INPUT -m conntrack --ctstate NEW -p tcp --tcp-flags SYN,RST,ACK,FIN,URG,PSH ACK -j LOG --log-prefix "ACK scan: "
iptables -A INPUT -m conntrack --ctstate NEW -p tcp --tcp-flags SYN,RST,ACK,FIN,URG,PSH ACK -j DROP # Metoda ACK (nmap -sA)
#OCHRONA PRZED SKANOWANIEM FIN SCAN
iptables -A INPUT -m conntrack --ctstate NEW -p tcp --tcp-flags SYN,RST,ACK,FIN,URG,PSH FIN -j LOG --log-prefix "FIN scan: "
iptables -A INPUT -m conntrack --ctstate NEW -p tcp --tcp-flags SYN,RST,ACK,FIN,URG,PSH FIN -j DROP # Skanowanie FIN (nmap -sF)
#OCHRONA PRZED SKANOWANIEM XMAS TREE SCAN
iptables -A INPUT -m conntrack --ctstate NEW -p tcp --tcp-flags SYN,RST,ACK,FIN,URG,PSH PSH -j LOG --log-prefix "Xmas scan: "
iptables -A INPUT -m conntrack --ctstate NEW -p tcp --tcp-flags SYN,RST,ACK,FIN,URG,PSH FIN,URG,PSH -j DROP # Metoda Xmas Tree (nmap -sX)
#OCHRONA PRZED SKANOWANIEM NULL SCAN
iptables -A INPUT -m conntrack --ctstate INVALID -p tcp ! --tcp-flags SYN,RST,ACK,FIN,PSH,URG SYN,RST,ACK,FIN,PSH,URG -j LOG --log-prefix "Null scan: "
#OCHRONA PRZED ATAKIEM Dos
iptables -A INPUT -m conntrack --ctstate INVALID -p tcp ! --tcp-flags SYN,RST,ACK,FIN,PSH,URG SYN,RST
iptables -N syn-flood
iptables -A INPUT -p tcp --syn -j syn-flood
iptables -A syn-flood -m limit --limit 1/s --limit-burst 4 -j RETURN
iptables -A syn-flood -m limit --limit 1/s --limit-burst 4 -j LOG --log-prefix "SYN-flood: "
iptables -A syn-flood -j DROP
# OCHRONA PRZED ATAKIEM PING OF DEATH
iptables -A INPUT -p icmp --icmp-type echo-request -m limit --limit 1/s -j LOG --log-prefix "Ping: "
iptables -A INPUT -p icmp --icmp-type echo-request -m limit --limit 1/s -j ACCEPT # Ping of death
# ZABLOKOWANIE PINGOWANIA Z WAN
iptables -A INPUT -i ppp0 -p icmp --icmp-type echo-request -j REJECT --reject-with icmp-host-unreachable
# BLOKOWANIE TELNETU Z WAN
iptables -A OUTPUT -p tcp --dport telnet -j REJECT
iptables -A INPUT -p tcp --dport telnet -j REJECT
# MASKARADA
iptables -t nat -A POSTROUTING -o ppp0 -j MASQUERADE
iptables -A FORWARD -i ppp0 -o eth1 -m state --state RELATED,ESTABLISHED -j ACCEPT
iptables -A FORWARD -i eth1 -o ppp0 -j ACCEPT
iptables -A FORWARD -i ppp0 -o wlan0 -m state --state RELATED,ESTABLISHED -j ACCEPT
iptables -A FORWARD -i wlan0 -o ppp0 -j ACCEPT
# ODBLOKOWANIE WWW Z WAN
iptables -A INPUT -p tcp -m tcp --dport 80 -j ACCEPT
# ODBLOKOWANIE SSH Z LAN I WLAN
iptables -A OUTPUT -p tcp --dport 22 -j ACCEPT
iptables -A INPUT -i eth1 -p tcp --dport 22 -j ACCEPT
iptables -A OUTPUT -p tcp --dport 22 -j ACCEPT
iptables -A INPUT -i wlan0 -p tcp --dport 22 -j ACCEPT
#ZAPIS DO LOGA ODRZUCONYCH PAKIETÓW PRZYCHODZĄCYCH W KATALOGU var/log/messages
iptables -N LOGGING
iptables -A INPUT -j LOGGING
iptables -A LOGGING -m limit --limit 2/min -j LOG --log-prefix "IPTables-Dropped: " --log-level 4
iptables -A LOGGING -j DROP
Kod: Zaznacz cały
iptables -P INPUT DROP