DSL + Firewall + Traffic Shaping + QoS

Maledictus

FreeBSD ftw
Hallo Leute,
ich hab bisher noch kein Thema und Tutorial zu diesem Thema gefunden, und so dachte ich mir, vielleicht können wir ja was zusammen auf die Beine stellen.

Also, es geht um folgendes:
Ich möchte mit meinem NAT Router, den Traffic managen, der von meinem internen Netz nach draussen geht (und umgekehrt).
Mit managen meine ich so lustige Sachen wie Firewall, Bandbreitenbegrenzung (Traffic Shaping), und bevorzugen von "wichtigen" Paketen (QoS).

Wichtig wäre mir zum Beispiel, das ACK Pakete vor allem anderen Vorrang haben, dann SSH und Online-Spiele, dann erst HTTP, FTP, etc.
Ich will aber für diese Sachen keine feste Bandbreite "reservieren", dann würde etwas verschenkt, wenn SSH mal nicht läuft. (Das ginge auch recht einfach mit pipes.)
Stattdessen will ich "Prioritäten" setzen (gewichten).

Der Aufbau des Systems und der Regeln sollten für viele Leute die gleichen sein, deswegen hoffe ich auf rege mitarbeit ;)

Bei mir siehts so aus:

Internet(DSL) --- FreeBSD NAT Router --- Internes Netz
(kommt euch sicherlich bekannt vor ;) )

Ich hab die "normale" DSL Bandbreite von
748KBit/s Downstream
128KBit/s Upstream

Es fängt natürlich alles beim Kernel an:
options IPFIREWALL
options IPFIREWALL_VERBOSE
options IPFIREWALL_VERBOSE_LIMIT=300
options DUMMYNET
options HZ=1000
options IPFW2

(unter 4.x muss man vor dem Kernel auch noch ein paar andere Sachen kompilieren,
siehe http://www.bsdforen.de/forums/showthread.php?s=&threadid=148)

Und jetzt hoffe ich auf euch,
lasst uns zusammen die Regeln für ipfw machen, ich habe da schon folgendes zu gefunden:

# High prioriy queues
queue 1 config pipe 10 weight 60
queue 2 config pipe 20 weight 60

# Low priority queues
queue 3 config pipe 10 weight 30
queue 4 config pipe 20 weight 30

queue 5 config pipe 10 weight 10
queue 6 config pipe 20 weight 10

# upstream pipe
pipe 10 config bw 128kbit/s

# downstream pipe
pipe 20 config bw 748kbit/s

# high priority protocols
add 000014 queue 1 tcp from any to any 22,53,80,3389 out xmit fxp0
add 000015 queue 2 tcp from any 22,53,80,3389 to any in recv fxp0
add 000016 queue 1 udp from any to any 53 out xmit fxp0
add 000017 queue 2 udp from any 53 to any in recv fxp0

# low priority protocols
add 000020 queue 3 tcp from any to any 21 out xmit fxp0
add 000021 queue 4 tcp from any 21 to any in recv fxp0

# lowest priority protocols
add 000030 queue 5 tcp from any to any 119,6667,25 out xmit fxp0
add 000031 queue 6 tcp from any 119,6667,25 to any in recv fxp0

Das stimmt natürlich vorne und hinten noch nicht, vor allem das mysteriöse red/gred ist nicht enthalten.
Fragt mich nicht was das ist, ich habs nicht verstanden, wenn jemand das erklären kann, so tue er dies bitte. (vor allem die Parameter)
Ist aber ein guter Ansatz.

Falls jemand schon etwas ähnliches aufgesetzt hat, bitte die Regeln posten (auch Teile).

Bevor ichs vergesse, ich benutze das builtin NAT von ppp, also kann meinetwegen das ganze ohne natd und divert über die Bühne gehen :)

Für die "normalen" Firewall regeln habe ich folgenden Vorschlag:
00100 allow ip from any to any via lo0
00500 check-state
01000 allow tcp from any to any out setup keep-state
02000 allow udp from any to any out keep-state
03000 allow icmp from any to any icmptypes 3 in
03100 allow icmp from any to any icmptypes 4
03200 allow icmp from any to any icmptypes 8 out
03300 allow icmp from any to any icmptypes 0 in
03400 allow icmp from any to any icmptypes 11 in
65000 allow log ip from any to any
65535 deny ip from any to any

Die Stimmen auch noch nicht, die ersten "any" sollten die IP's und Masken des internen Netzes sein.
Aber funktionieren tun sie auf jeden Fall, wenn auch nur wegen der vorletzten Regel, die ich zu testzwecken drin hab.

So denn, schiesst los, ich hau mich hin, is spät geworden, entschuldigt die länge des Textes, aber ich finde das Ganze recht komplex.

Gute Nacht
Maledictus
 
Hiho, ich hab mich auch damit mal rumgeschlagen, leider bekomme ich die Dummynet Geschichte nicht hin (ich schau mir daher grade pf+altq an).

Wer sich über die seltsame Konstruktion zum flushen wundert: Damit killt er bei mir nicht meine ssh Verbindungen bei einem update der firewall.

ipfw.rules:
#-f flush
####### Prepare new ruleset
set disable 1
delete set 1
####### Stupid SMB clients
add 10 set 1 reset tcp from 127.0.0.1 to 127.0.0.1 445 in via lo
add 20 set 1 reset tcp from 192.168.0.0/16 to me 80,445 in via rl0
#add 30 set 1 reset tcp from 192.168.0.0/16 to me 80,445 in via wi0
####### Trusted lo and LAN (rl0), basic anti-spoofing, wi0 is secured via IPSec (required)
add 100 set 1 allow ip from any to any via lo0
add 110 set 1 deny log ip from any to 127.0.0.0/8
add 200 set 1 allow ip from any to any via rl0
add 210 set 1 allow ip from any to any via wi0
#add 210 set 1 allow esp from any to any via wi0 #doesn't work
add 220 set 1 deny log ip from any to 192.168.0.0/16
add 400 set 1 deny log ip from any to 0.0.0.0/8
add 500 set 1 deny log ip from any to any not via tun0
####### Traffic Shaping
#add 1000 set 1 pipe 1 ip from me to any out via tun0
#add 1001 set 1 queue 1 ip from 192.168.0.1 to any out via tun0
#add 1002 set 1 queue 2 ip from 192.168.0.2 to any out via tun0
#add 1003 set 1 queue 3 ip from 192.168.0.3 to any out via tun0
#add 1100 set 1 queue 100 ip from me to any out via tun0
#add 1999 set 1 queue 100 ip from me to any out via tun0
#add 2000 set 1 pipe 2 ip from any to me in via tun0
####### Open Server Services
add 10000 set 1 allow tcp from any to me 5662,8666 in via tun0
add 10010 set 1 allow udp from any to me 5666,8666 in via tun0
#add 10020 set 1 allow icmp from any to me icmptypes 8 in via tun0
#add 10020 set 1 allow icmp from any to me in via tun0
add 10100 set 1 reset tcp from any to any 113 in via tun0
####### Allow outgoing Server connections stateful
add 20000 set 1 check-state
add 20100 set 1 allow ip from me to any out via tun0 keep-state
####### Divert to NATD. Everything from here is NATed
add 30000 set 1 divert natd ip from any to any via tun0
add 30100 set 1 allow ip from me to any out via tun0
add 30200 set 1 allow ip from any to 192.168.0.0/16 in via tun0
####### 60000-60999 is used by NATD punch_fw
####### Deny the rest
add 64000 set 1 deny all from any to any out via tun0
add 65000 set 1 deny log all from any to any
####### Activate new ruleset
set swap 1 0
delete set 1
set enable 1
zero
resetlog
####### Configure pipes
-f queue flush
-f pipe flush
#pipe 1 config bw 128KBit/s queue 1KByte
#pipe 2 config bw 768KBit/s queue 7KByte red 0.002/30/80/0.1
#queue 1 config pipe 1 weight 50
#queue 2 config pipe 1 weight 20
#queue 3 config pipe 1 weight 5
#queue 100 config pipe 1 weight 1

natd.rules:
dynamic yes
log no
log_denied no
log_ipfw_denied no
log_facility security
deny_incoming yes
use_sockets yes
same_ports yes
unregistered_only yes
punch_fw 60000:999
#redirect_port tcp 192.168.0.1:6073 6073
#redirect_port tcp 192.168.0.1:2302-2400 2302-2400
#redirect_port udp 192.168.0.1:2302-2400 2302-2400

rc.conf:
log_in_vain="0"
icmp_drop_redirect="YES"
icmp_log_redirect="YES"
tcp_drop_synfin="NO"

sysctl.conf:
#net.inet.tcp.rfc1644=1
net.inet.ip.check_interface=1
net.inet.tcp.blackhole=2
net.inet.udp.blackhole=1
net.inet.tcp.inflight_enable=1
#net.inet.tcp.inflight_min=6144
#net.inet.tcp.recvspace=65535
#net.inet.tcp.sendspace=65535
net.inet.ip.fw.dyn_max=8192
net.inet.ip.fw.verbose_limit=10
net.inet.ip.fw.one_pass=0

Die auskommentierten Sachen dienen lediglich zur Erinnerung an verschiedene Features, oder Sachen die mehr schaden als sie nützlich sind.

Wenn jemand Dummynet auch nur irgendwie (vernünftig) zum laufen bekommen hat: HILFE!!!!
 
Zuletzt bearbeitet:
Achja eine Sache noch wegen QoS:
ppp.conf:
set urgent tcp 22
set urgent udp 53

Das berücksichtigt wohl auch Pakete mit TCP_NO_DELAY, bringt aber nicht den gewünschten Effekt.
 
Zurück
Oben