wieder mal frage zu iptables

Einrichten des lokalen Netzes, Verbindung zu anderen Computern und Diensten.
Antworten
OttoB
Beiträge: 3
Registriert: 17.02.2007 11:40:36

wieder mal frage zu iptables

Beitrag von OttoB » 17.02.2007 11:54:49

Hallo!

Obwohl ich ganze Menge gute Tips gefunden (Viele Dank, ihre Einträge haben mir sehr geholfen!!!!). bleibt trotzdem eine Frage.

Ich habe mir ein Paar Regeln für iptables generiert, etwa so:
#####################################################
# ausgehende Verbindungen
# Port 22
$iptables -I OUTPUT -o eth0 -p TCP --sport 1024:65535 --dport 22 -m state --state NEW,ESTABLISHED,RELATED -j ACCEPT
$iptables -I INPUT -i eth0 -p TCP --sport 22 --dport 1024:65535 -m state --state ESTABLISHED,RELATED -j ACCEPT
# Port 25
$iptables -I OUTPUT -o eth0 -p TCP --sport 1024:65535 --dport 25 -m state --state NEW,ESTABLISHED,RELATED -j ACCEPT
$iptables -I INPUT -i eth0 -p TCP --sport 25 --dport 1024:65535 -m state --state ESTABLISHED,RELATED -j ACCEPT
# Port 53
$iptables -I OUTPUT -o eth0 -p TCP --sport 1024:65535 --dport 53 -m state --state NEW,ESTABLISHED,RELATED -j ACCEPT
$iptables -I INPUT -i eth0 -p TCP --sport 53 --dport 1024:65535 -m state --state ESTABLISHED,RELATED -j ACCEPT
$iptables -I OUTPUT -o eth0 -p UDP --sport 1024:65535 --dport 53 -m state --state NEW,ESTABLISHED,RELATED -j ACCEPT
$iptables -I INPUT -i eth0 -p UDP --sport 53 --dport 1024:65535 -m state --state ESTABLISHED,RELATED -j ACCEPT
# Port 80
$iptables -I OUTPUT -o eth0 -p TCP --sport 1024:65535 --dport 80 -m state --state NEW,ESTABLISHED,RELATED -j ACCEPT
$iptables -I INPUT -i eth0 -p TCP --sport 80 --dport 1024:65535 -m state --state ESTABLISHED,RELATED -j ACCEPT

#####################################################
# eingehende Verbindungen
# Port 22
$iptables -I INPUT -i eth0 -p TCP --sport 1024:65535 --dport 22 -m state --state NEW,ESTABLISHED,RELATED -j ACCEPT
$iptables -I OUTPUT -o eth0 -p TCP --sport 22 --dport 1024:65535 -m state --state ESTABLISHED,RELATED -j ACCEPT
# Port 80
$iptables -I INPUT -i eth0 -p TCP --sport 1024:65535 --dport 80 -m state --state NEW,ESTABLISHED,RELATED -j ACCEPT
$iptables -I OUTPUT -o eth0 -p TCP --sport 80 --dport 1024:65535 -m state --state ESTABLISHED,RELATED -j ACCEPT

#####################################################
# Erweiterte Sicherheitsfunktionen
# SynFlood
$iptables -A FORWARD -p tcp --syn -m limit --limit 1/s -j ACCEPT
# PortScan
$iptables -A FORWARD -p tcp --tcp-flags SYN,ACK,FIN,RST RST -m limit --limit 1/s -j ACCEPT
# Ping-of-Death
$iptables -A FORWARD -p icmp --icmp-type echo-request -m limit --limit 1/s -j ACCEPT
und danach habe ich versucht, eingehende Verbindungen zu verbieten, da es um ein botnet handelt, etwa so (Ziffern durh "*" ersetzt:
iptables -A INPUT -s **.***.***.*** -j DROP
das war für einzelne IP-Adresse, und für ein Range:
iptables -A INPUT -s 89.138.0.0/16 -j DROP

Mit dem
iptables -L
sehe ich, dass es angenommen wurde.

Aber nach dem start von Apache mit
netstat -aptn
sieht man, dass Verbindugen, die von diesen IPs kommen, wurden trotzdem aufgebaut.

Woran kann es liegen?

Benutzeravatar
herrchen
Beiträge: 3257
Registriert: 15.08.2005 20:45:28
Lizenz eigener Beiträge: MIT Lizenz
Wohnort: Berlin

Re: wieder mal frage zu iptables

Beitrag von herrchen » 17.02.2007 12:09:19

OttoB hat geschrieben:
iptables -A INPUT -s **.***.***.*** -j DROP
die regeln werden mit "-A" hinten angehängt.
dann ist es zu spät, da die verbinfung schon erlaubt wurde.
verwende "-I".

herrchen

OttoB
Beiträge: 3
Registriert: 17.02.2007 11:40:36

Beitrag von OttoB » 17.02.2007 13:43:41

Ja, genau so ist es. Es war nicht besonders schlau von mir die Reienfolge nicht zu beachhten.

"Eine kleine Buchstabe, und so eine große Auswirkung" 8)

Vielen Dank für die Hilfe.

OttoB
Beiträge: 3
Registriert: 17.02.2007 11:40:36

Beitrag von OttoB » 17.02.2007 15:00:25

Und noch eine Frage.

Verstehe ich richtig, dass z.B.

"120.0.0.0/16" = slle IPs from 120.0.0.0 bis 120.0.255.255 (1)
"120.0.0.0/15" = slle IPs from 120.0.0.0 bis 120.1.255.255 (2)
"120.0.0.0/14" = slle IPs from 120.0.0.0 bis 120.3.255.255 (4)
"120.0.0.0/13" = slle IPs from 120.0.0.0 bis 120.7.255.255 ( 8 )
"120.0.0.0/12" = slle IPs from 120.0.0.0 bis 120.15.255.255 (16)
"120.0.0.0/11" = slle IPs from 120.0.0.0 bis 120.31.255.255 (32)
"120.0.0.0/10" = slle IPs from 120.0.0.0 bis 120.63.255.255 (64)
"120.0.0.0/9" = slle IPs from 120.0.0.0 bis 120.127.255.255 (128)

"120.0.0.0/8" = slle IPs from 120.0.0.0 bis 120.255.255.255 (256 oder 1)
"120.0.0.0/7" = slle IPs from 120.0.0.0 bis 121.255.255.255 (2)
"120.0.0.0/6" = slle IPs from 120.0.0.0 bis 123.255.255.255 (4)
"120.0.0.0/5" = slle IPs from 120.0.0.0 bis 127.255.255.255 ( 8 )
"120.0.0.0/4" = slle IPs from 120.0.0.0 bis 135.255.255.255 (16)
"120.0.0.0/3" = slle IPs from 120.0.0.0 bis 151.255.255.255 (32)
"120.0.0.0/2" = slle IPs from 120.0.0.0 bis 183.255.255.255 (64)
"120.0.0.0/1" = slle IPs from 120.0.0.0 bis 247.255.255.255 (128)

Benutzeravatar
mistersixt
Beiträge: 6601
Registriert: 24.09.2003 14:33:25
Lizenz eigener Beiträge: GNU Free Documentation License

Beitrag von mistersixt » 18.02.2007 17:25:41

Installier Dir mal das Tool "ipcalc" (apt-get install ipcalc), da kann man sich sowas anzeigen lassen (als Beispiel):

Code: Alles auswählen

andromeda:~# ipcalc 120.0.0.0/9
Address:   120.0.0.0            01111000.0 0000000.00000000.00000000
Netmask:   255.128.0.0 = 9      11111111.1 0000000.00000000.00000000
Wildcard:  0.127.255.255        00000000.0 1111111.11111111.11111111
=>
Network:   120.0.0.0/9          01111000.0 0000000.00000000.00000000
HostMin:   120.0.0.1            01111000.0 0000000.00000000.00000001
HostMax:   120.127.255.254      01111000.0 1111111.11111111.11111110
Broadcast: 120.127.255.255      01111000.0 1111111.11111111.11111111
Hosts/Net: 8388606               Class A

andromeda:~#
Gruss, mistersixt.
--
System: Debian Bookworm, 6.11.x.-x-amd64, ext4, AMD Ryzen 7 3700X, 8 x 3.8 Ghz., Radeon RX 5700 XT, 32 GB Ram, XFCE

Antworten