Die Klassen werden zwar erzeugt, aber ich bekomme es nicht hin, Pakete zu markieren. Alles wandert in die Standardklasse.
Vielleicht wäre ein Profi so nett, mal einen Blick auf mein Skript zu werfen. Zurzeit würde es mir schon reichen, wenn nur ssh (Port 22) bevorzugt (--set-mark 20) werden würde.
Code: Alles auswählen
#!/bin/sh
###############################
# ultimatives Firewall-script #
###############################
LAN="192.168.0.1/24"
LAN_IFACE="eth0"
LAN2_IFACE="eth1"
INET_IFACE=ppp0
INET_IP="`/sbin/ifconfig ppp0|/usr/bin/awk '/inet addr:/ {print $2}'|/bin/sed 's/addr://'`"
LAN_BCAST_ADRESS="192.168.0.255/32"
LO_IFACE="lo"
LO_IP="127.0.0.1/24"
BW_UP=125kbit
IPTABLES="/sbin/iptables"
# Traffic-Shaping Klassen ggf loeschen
tc qdisc del dev $INET_IFACE root 2> /dev/null
case "$1" in
'start')
#
# Traffic-Shaping vorbereiten
#
# root qdisc
tc qdisc add dev $INET_IFACE root handle 1: htb default 30 r2q 7
# root class anlegen
tc class add dev $INET_IFACE parent 1: classid 1:1 htb rate $BW_UP burst 2k prio 0
# 4 klassen anlegen
# 1. tcp acks (pakete <= 64byte) hoechste prio
tc class add dev $INET_IFACE parent 1:1 classid 1:10 htb rate 20kbit ceil 80kbit prio 0
# 2. bevorzugter Traffic
tc class add dev $INET_IFACE parent 1:1 classid 1:20 htb rate 80kbit ceil $BW_UP prio 1
# 3. Standardtraffic
tc class add dev $INET_IFACE parent 1:1 classid 1:30 htb rate 20kbit ceil $BW_UP prio 2
# 4. benachteiligter Traffic
tc class add dev $INET_IFACE parent 1:1 classid 1:40 htb rate 5kbit ceil 80kbit prio 3
# Filter anlegen, die die Pakete je nach Markierung durch iptables
# in die einzelnen Klassen lenken
tc filter add dev $INET_IFACE parent 1: prio 0 protocol ip handle 10 fw flowid 1:10
tc filter add dev $INET_IFACE parent 1: prio 1 protocol ip handle 20 fw flowid 1:20
tc filter add dev $INET_IFACE parent 1: prio 2 protocol ip handle 30 fw flowid 1:30
tc filter add dev $INET_IFACE parent 1: prio 3 protocol ip handle 40 fw flowid 1:40
#
# Traffic-Shaping vorbereiten beendet
#
# forwarding einschalten
echo "1" > /proc/sys/net/ipv4/ip_forward
$IPTABLES -t nat -A POSTROUTING -o $INET_IFACE -j SNAT --to-source $INET_IP
$IPTABLES -I FORWARD -p tcp --tcp-flags SYN,RST SYN -j TCPMSS --clamp-mss-to-pmtu
# packete akzeptieren die forwarded werden
$IPTABLES -A FORWARD -i $LAN_IFACE -j ACCEPT
$IPTABLES -A FORWARD -i $LAN2_IFACE -j ACCEPT
$IPTABLES -A FORWARD -m state --state ESTABLISHED,RELATED -j ACCEPT
$IPTABLES -A FORWARD -m limit --limit 3/minute --limit-burst 3 -j ULOG --ulog-prefix "IPT FORWARD packet died: "
# policy drop all
$IPTABLES -P INPUT DROP
$IPTABLES -P OUTPUT DROP
$IPTABLES -P FORWARD DROP
#
# Ports per Traffic-Shaping bevorzugen
#
# ssh
$IPTABLES -I INPUT -t mangle -p tcp -s 0/0 --dport 22 -j MARK --set-mark 20
$IPTABLES -I OUTPUT -t mangle -p tcp -s 0/0 --dport 22 -j MARK --set-mark 20
$IPTABLES -I FORWARD -t mangle -p tcp -s 0/0 --dport 22 -j MARK --set-mark 20
#
# Ports per Traffic-Shaping bevorzugen ENDE
#
# erstellen eigener chains fuer ICMP TCP UDP
$IPTABLES -N icmp_packets
$IPTABLES -N tcp_packets
$IPTABLES -N udpincoming_packets
$IPTABLES -N forblock
# allow chain fuer TCP
$IPTABLES -N allowed
$IPTABLES -A allowed -p TCP --syn -j ACCEPT
$IPTABLES -A allowed -p TCP -m state --state ESTABLISHED,RELATED -j ACCEPT
$IPTABLES -A allowed -p TCP -j DROP
# ICMP regeln
$IPTABLES -A icmp_packets -p ICMP -s 0/0 --icmp-type 0 -j ACCEPT
$IPTABLES -A icmp_packets -p ICMP -s 0/0 --icmp-type 3 -j ACCEPT
$IPTABLES -A icmp_packets -p ICMP -s 0/0 --icmp-type 5 -j ACCEPT
$IPTABLES -A icmp_packets -p ICMP -s 0/0 --icmp-type 8 -j ACCEPT
$IPTABLES -A icmp_packets -p ICMP -s 0/0 --icmp-type 11 -j ACCEPT
## TCP regeln
$IPTABLES -A tcp_packets -p TCP -s 0/0 --dport 22 -j allowed
## UDP regeln
#$IPTABLES -A udpincoming_packets -p UDP -s 0/0 --source-port 53 -j ACCEPT
$IPTABLES -A FORWARD -j forblock
# PREROUTING chain.
#
# IP spoofing checken
$IPTABLES -t nat -A PREROUTING -i $INET_IFACE -s 192.168.0.0/16 -j DROP
$IPTABLES -t nat -A PREROUTING -i $INET_IFACE -s 10.0.0.0/8 -j DROP
$IPTABLES -t nat -A PREROUTING -i $INET_IFACE -s 172.16.0.0/12 -j DROP
# INPUT chain
# boese TCP pakete entfernen
$IPTABLES -A INPUT -p tcp ! --syn -m state --state NEW -j ULOG --ulog-prefix "New not syn:"
$IPTABLES -A INPUT -p tcp ! --syn -m state --state NEW -j DROP
# fuer passiven FTP und IRC
$IPTABLES -A INPUT -p TCP -m state --state RELATED -j ACCEPT
# Internet Packete in die chains leiten
$IPTABLES -A INPUT -p ICMP -i $INET_IFACE -j icmp_packets
$IPTABLES -A INPUT -p TCP -i $INET_IFACE -j tcp_packets
$IPTABLES -A INPUT -p UDP -i $INET_IFACE -j udpincoming_packets
# Regeln fuer das interne Netz, was alles darf
$IPTABLES -A INPUT -p ALL -i $LAN_IFACE -d $LAN_BCAST_ADRESS -j ACCEPT
$IPTABLES -A INPUT -p ALL -i $LO_IFACE -d $LO_IP -j ACCEPT
$IPTABLES -A INPUT -p ALL -i $LAN_IFACE -d $LAN -j ACCEPT
$IPTABLES -A INPUT -p ALL -d $INET_IP -m state --state ESTABLISHED,RELATED -j ACCEPT
$IPTABLES -A INPUT -m limit --limit 3/minute --limit-burst 3 -j ULOG --ulog-prefix "IPT INPUT A packet died: "
# OUTPUT chain
$IPTABLES -A OUTPUT -p tcp ! --syn -m state --state NEW -j ULOG --ulog-prefix "New not syn:"
$IPTABLES -A OUTPUT -p tcp ! --syn -m state --state NEW -j DROP
$IPTABLES -A OUTPUT -p ALL -s $LO_IP -j ACCEPT
$IPTABLES -A OUTPUT -p ALL -s $INET_IP -j ACCEPT
$IPTABLES -A OUTPUT -m limit --limit 3/minute --limit-burst 3 -j ULOG --ulog-prefix "IPT B OUTPUT packet died: "
# lokale zugriffe erlauben
$IPTABLES -A OUTPUT -p ALL -s $LAN -j ACCEPT
$IPTABLES -A INPUT -p ALL -i $LAN_IFACE -s $LAN -j ACCEPT
$IPTABLES -A INPUT -i lo -j ACCEPT
$IPTABLES -A OUTPUT -o lo -j ACCEPT
# Rest loggen & droppen
$IPTABLES -A OUTPUT -j ULOG --ulog-prefix "Nicht raus: "
$IPTABLES -A OUTPUT -j DROP
$IPTABLES -A FORWARD -j ULOG --ulog-prefix "Nicht durch: "
$IPTABLES -A FORWARD -j DROP
$IPTABLES -A INPUT -j ULOG --ulog-prefix "Nicht rein: "
$IPTABLES -A INPUT -j DROP
echo "Firewall-Regeln geladen !!"
;;
*)
echo "Usage: $0 {start}"
;;
esac
exit 0
Code: Alles auswählen
class htb 1:1 root rate 125Kbit ceil 125Kbit burst 2Kb cburst 1759b
Sent 2986498 bytes 8199 pkts (dropped 0, overlimits 0)
rate 3478bps 7pps
lended: 4309 borrowed: 0 giants: 0
tokens: 123902 ctokens: 105472
class htb 1:10 parent 1:1 prio 0 rate 20Kbit ceil 80Kbit burst 1624b cburst 1701b
Sent 0 bytes 0 pkts (dropped 0, overlimits 0)
lended: 0 borrowed: 0 giants: 0
tokens: 649999 ctokens: 170199
class htb 1:20 parent 1:1 prio 1 rate 80Kbit ceil 125Kbit burst 1701b cburst 1759b
Sent 0 bytes 0 pkts (dropped 0, overlimits 0)
lended: 0 borrowed: 0 giants: 0
tokens: 170199 ctokens: 112640
class htb 1:30 parent 1:1 prio 2 rate 20Kbit ceil 125Kbit burst 1624b cburst 1759b
Sent 2986498 bytes 8199 pkts (dropped 0, overlimits 0)
rate 3493bps 7pps
lended: 3890 borrowed: 4309 giants: 0
tokens: -150769 ctokens: 105472
class htb 1:40 parent 1:1 prio 3 rate 5Kbit ceil 80Kbit burst 1605b cburst 1701b
Sent 0 bytes 0 pkts (dropped 0, overlimits 0)
lended: 0 borrowed: 0 giants: 0
tokens: 2569600 ctokens: 170199
Ich habe per Google gelesen, dass man nicht wie unter Tipps beschrieben "-A", sondern "-I" verwenden sollte, da diese Regeln an den Anfang gestellt werden sollten. "-A" bringt bei mir auch keine Änderung.