Topologi jaringan dan desain htb
Kriteria dalam pembuatan traffic control ini:
- Traffic control hanya untuk trafik eggress dari device lan (eth0) dan wan (eth1).
- Trafik dari local area network (lan) ke router dan sebaliknya tidak melalui traffic control.
- Trafik dari internet ke lan (downstream) akan melalui traffic control, kecuali trafik dari port 80 (www) yang mempunyai tanda TOS 0×30 atau DSCP 12 (cache hit).
- Setiap pc atau anggota lan akan memiliki class dan qdisc sendiri-sendiri.
- Tidak ada class default untuk handle traffic untuk object yang tidak didefinisikan atau unclassified traffic.
Catatan: trafik ke internet port 80 akan melalui server proxy remote secara transparent.
Topologi network
Network LAN : 192.168.41.0/24
IP Router : 192.168.41.1
IP Client : 192.168.41.2 - 192.168.41.14
Device LAN : eth0
Device WAN : eth1
Alokasi bandwidth internet downstream
Root
- Ceiling : 384kbps
- Rate : 384kbps
Client
- Ceiling : 384kbps
- Rate : 16kbps
Alokasi bandwidth internet upstream
Root
- Ceiling : 128kbps
- Rate : 128kbps
Client
- Ceiling : 128kbps
- Rate : 16kbps
Source Code tc-3.sh
019 | IPTABLES= "/usr/sbin/iptables" |
056 | $IPTABLES -F -t mangle |
064 | iptables -A PREROUTING -t mangle -i $WAN -p tcp --sport 80 -m dscp --dscp 12 -j MARK -- set -mark 5 |
065 | iptables -A PREROUTING -t mangle -i $WAN -p tcp --sport 80 -m dscp --dscp 12 -j RETURN |
067 | iptables -A PREROUTING -t mangle -i $WAN -j MARK -- set -mark 6 |
072 | iptables -A PREROUTING -t mangle -i $LAN -j MARK -- set -mark 7 |
080 | iptables -A FORWARD -t mangle -p tcp -m mark --mark 5 -j MARK -- set -mark 0x212 |
086 | iptables -A FORWARD -t mangle -d 192.168.41.$i -m mark --mark 6 -j MARK -- set -mark $j |
095 | iptables -A FORWARD -t mangle -s 192.168.41.$i -m mark --mark 7 -j MARK -- set -mark $j |
106 | tc qdisc del dev $LAN root |
107 | tc qdisc add dev $LAN root handle 1:0 htb |
108 | tc class add dev $LAN parent 1:0 classid 1:2 htb rate ${RATEDW}kbit ceil ${CEILDW}kbit quantum 1500 prio 6 |
118 | tc class add dev $LAN parent 1:2 classid 1:$j htb rate ${RATESUBDW}kbit \ |
119 | ceil ${CEILSUBDW}kbit quantum 1500 prio 6 |
121 | tc qdisc add dev $LAN parent 1:$j handle $j sfq perturb 10 |
132 | tc filter add dev $LAN protocol ip parent 1:0 prio 6 handle $j fw flowid 1:$j |
139 | tc qdisc del dev $WAN root |
140 | tc qdisc add dev $WAN root handle 1:0 htb |
141 | tc class add dev $WAN parent 1:0 classid 1:2 htb rate ${RATEUP}kbit ceil ${CEILUP}kbit quantum 1500 prio 6 |
151 | tc class add dev $WAN parent 1:2 classid 1:$j htb rate ${RATESUBUP}kbit \ |
152 | ceil ${CEILSUBUP}kbit quantum 1500 prio 6 |
154 | tc qdisc add dev $WAN parent 1:$j handle $j sfq perturb 10 |
165 | tc filter add dev $WAN protocol ip parent 1:0 prio 6 handle $j fw flowid 1:$j |
Untuk memahami aliran paket atau traffic flow dalam router silahkan simak gambar di bawah:
Sumber: Manual mikrotik refman2.9.pdf.
Analisa paket mangle dan traffic control untuk trafik downstream
Perhatikan baris-baris yang tercetak tebal.
- tc -s -d qdisc show dev eth0; iptables -L FORWARD -t mangle -nv| head -n 16
qdisc htb 1: r2q 10 default 0 direct_packets_stat 6144 ver 3.17
Sent 31783127 bytes 49709 pkts (dropped 0, overlimits 5839)
qdisc sfq 12: parent 1:12 limit 128p quantum 1514b flows 128/1024 perturb 10sec
Sent 5118517 bytes 15858 pkts (dropped 0, overlimits 0)
qdisc sfq 13: parent 1:13 limit 128p quantum 1514b flows 128/1024 perturb 10sec
Sent 81859 bytes 206 pkts (dropped 0, overlimits 0)
qdisc sfq 14: parent 1:14 limit 128p quantum 1514b flows 128/1024 perturb 10sec
Sent 6626893 bytes 6817 pkts (dropped 0, overlimits 0)
qdisc sfq 15: parent 1:15 limit 128p quantum 1514b flows 128/1024 perturb 10sec
Sent 0 bytes 0 pkts (dropped 0, overlimits 0)
qdisc sfq 16: parent 1:16 limit 128p quantum 1514b flows 128/1024 perturb 10sec
Sent 0 bytes 0 pkts (dropped 0, overlimits 0)
qdisc sfq 17: parent 1:17 limit 128p quantum 1514b flows 128/1024 perturb 10sec
Sent 11525 bytes 45 pkts (dropped 0, overlimits 0)
qdisc sfq 18: parent 1:18 limit 128p quantum 1514b flows 128/1024 perturb 10sec
Sent 8475558 bytes 11965 pkts (dropped 0, overlimits 0)
qdisc sfq 19: parent 1:19 limit 128p quantum 1514b flows 128/1024 perturb 10sec
Sent 3277886 bytes 4621 pkts (dropped 0, overlimits 0)
qdisc sfq 20: parent 1:20 limit 128p quantum 1514b flows 128/1024 perturb 10sec
Sent 0 bytes 0 pkts (dropped 0, overlimits 0)
qdisc sfq 21: parent 1:21 limit 128p quantum 1514b flows 128/1024 perturb 10sec
Sent 4558 bytes 23 pkts (dropped 0, overlimits 0)
qdisc sfq 22: parent 1:22 limit 128p quantum 1514b flows 128/1024 perturb 10sec
Sent 0 bytes 0 pkts (dropped 0, overlimits 0)
qdisc sfq 23: parent 1:23 limit 128p quantum 1514b flows 128/1024 perturb 10sec
Sent 0 bytes 0 pkts (dropped 0, overlimits 0)
qdisc sfq 24: parent 1:24 limit 128p quantum 1514b flows 128/1024 perturb 10sec
Sent 3012356 bytes 4030 pkts (dropped 0, overlimits 0)
Chain FORWARD (policy ACCEPT 1676K packets, 904M bytes)
pkts bytes target prot opt in out source destination
4921 4911K MARK tcp -- * * 0.0.0.0/0 0.0.0.0/0 MARK match 0x5 MARK set 0x212
15858 4897K MARK all -- * * 0.0.0.0/0 192.168.41.2 MARK match 0x6 MARK set 0xc
206 78975 MARK all -- * * 0.0.0.0/0 192.168.41.3 MARK match 0x6 MARK set 0xd
6817 6531K MARK all -- * * 0.0.0.0/0 192.168.41.4 MARK match 0x6 MARK set 0xe
0 0 MARK all -- * * 0.0.0.0/0 192.168.41.5 MARK match 0x6 MARK set 0xf
0 0 MARK all -- * * 0.0.0.0/0 192.168.41.6 MARK match 0x6 MARK set 0x10
45 10895 MARK all -- * * 0.0.0.0/0 192.168.41.7 MARK match 0x6 MARK set 0x11
11966 8308K MARK all -- * * 0.0.0.0/0 192.168.41.8 MARK match 0x6 MARK set 0x12
4621 3213K MARK all -- * * 0.0.0.0/0 192.168.41.9 MARK match 0x6 MARK set 0x13
0 0 MARK all -- * * 0.0.0.0/0 192.168.41.10 MARK match 0x6 MARK set 0x14
23 4236 MARK all -- * * 0.0.0.0/0 192.168.41.11 MARK match 0x6 MARK set 0x15
0 0 MARK all -- * * 0.0.0.0/0 192.168.41.12 MARK match 0x6 MARK set 0x16
0 0 MARK all -- * * 0.0.0.0/0 192.168.41.13 MARK match 0x6 MARK set 0x17
4030 2956K MARK all -- * * 0.0.0.0/0 192.168.41.14 MARK match 0x6 MARK set 0x18
Analisa paket mangle dan traffic control untuk trafik upstream
Perhatikan baris-baris yang tercetak tebal.
- tc -s -d qdisc show dev eth1; iptables -L FORWARD -t mangle -nv
qdisc htb 1: r2q 10 default 0 direct_packets_stat 191743 ver 3.17
Sent 45055014 bytes 244485 pkts (dropped 0, overlimits 4314)
qdisc sfq 22: parent 1:22 limit 128p quantum 1514b flows 128/1024 perturb 10sec
Sent 3539507 bytes 16353 pkts (dropped 0, overlimits 0)
qdisc sfq 23: parent 1:23 limit 128p quantum 1514b flows 128/1024 perturb 10sec
Sent 55439 bytes 324 pkts (dropped 0, overlimits 0)
qdisc sfq 24: parent 1:24 limit 128p quantum 1514b flows 128/1024 perturb 10sec
Sent 1213280 bytes 6968 pkts (dropped 0, overlimits 0)
qdisc sfq 25: parent 1:25 limit 128p quantum 1514b flows 128/1024 perturb 10sec
Sent 0 bytes 0 pkts (dropped 0, overlimits 0)
qdisc sfq 26: parent 1:26 limit 128p quantum 1514b flows 128/1024 perturb 10sec
Sent 0 bytes 0 pkts (dropped 0, overlimits 0)
qdisc sfq 27: parent 1:27 limit 128p quantum 1514b flows 128/1024 perturb 10sec
Sent 9806 bytes 56 pkts (dropped 0, overlimits 0)
qdisc sfq 28: parent 1:28 limit 128p quantum 1514b flows 128/1024 perturb 10sec
Sent 2949492 bytes 15990 pkts (dropped 0, overlimits 0)
qdisc sfq 29: parent 1:29 limit 128p quantum 1514b flows 128/1024 perturb 10sec
Sent 1039116 bytes 6678 pkts (dropped 0, overlimits 0)
qdisc sfq 30: parent 1:30 limit 128p quantum 1514b flows 128/1024 perturb 10sec
Sent 0 bytes 0 pkts (dropped 0, overlimits 0)
qdisc sfq 31: parent 1:31 limit 128p quantum 1514b flows 128/1024 perturb 10sec
Sent 5156 bytes 39 pkts (dropped 0, overlimits 0)
qdisc sfq 32: parent 1:32 limit 128p quantum 1514b flows 128/1024 perturb 10sec
Sent 0 bytes 0 pkts (dropped 0, overlimits 0)
qdisc sfq 33: parent 1:33 limit 128p quantum 1514b flows 128/1024 perturb 10sec
Sent 0 bytes 0 pkts (dropped 0, overlimits 0)
qdisc sfq 34: parent 1:34 limit 128p quantum 1514b flows 128/1024 perturb 10sec
Sent 1071110 bytes 6334 pkts (dropped 0, overlimits 0)
Chain FORWARD (policy ACCEPT 1693K packets, 912M bytes)
pkts bytes target prot opt in out source destination
......
16471 3316K MARK all -- * * 192.168.41.2 0.0.0.0/0 MARK match 0x7 MARK set 0x16
331 51239 MARK all -- * * 192.168.41.3 0.0.0.0/0 MARK match 0x7 MARK set 0x17
7154 1125K MARK all -- * * 192.168.41.4 0.0.0.0/0 MARK match 0x7 MARK set 0x18
0 0 MARK all -- * * 192.168.41.5 0.0.0.0/0 MARK match 0x7 MARK set 0x19
1 40 MARK all -- * * 192.168.41.6 0.0.0.0/0 MARK match 0x7 MARK set 0x1a
56 9022 MARK all -- * * 192.168.41.7 0.0.0.0/0 MARK match 0x7 MARK set 0x1b
17496 2811K MARK all -- * * 192.168.41.8 0.0.0.0/0 MARK match 0x7 MARK set 0x1c
7498 986K MARK all -- * * 192.168.41.9 0.0.0.0/0 MARK match 0x7 MARK set 0x1d
0 0 MARK all -- * * 192.168.41.10 0.0.0.0/0 MARK match 0x7 MARK set 0x1e
39 4610 MARK all -- * * 192.168.41.11 0.0.0.0/0 MARK match 0x7 MARK set 0x1f
0 0 MARK all -- * * 192.168.41.12 0.0.0.0/0 MARK match 0x7 MARK set 0x20
0 0 MARK all -- * * 192.168.41.13 0.0.0.0/0 MARK match 0x7 MARK set 0x21
6913 1019K MARK all -- * * 192.168.41.14 0.0.0.0/0 MARK match 0x7 MARK set 0x22
Hal yang menarik di sini adalah
- Semua paket yang lewat chain FORWARD table mangle dengan tujuan lan mempunyai jumlah paket yang sama dengan yang tercatat di qdisc dev eth0 (lan).
- Semua paket yang lewat chain FORWARD table mangle dengan tujuan wan mempunyai jumlah paket yang senantiasa sama atau lebih besar dengan yang tercatat di qdisc dev eth1 (wan). Hal ini karena ada beberapa paket yang di-DROP di chain FORWARD table default. Terlihat pada gambar trafik flow di atas, setelah paket melewati chain FORWARD table mangle selanjutnya akan masuk chain FORWARD table filter.
- Jika ingin membatasi trafik upstream dari lan tanpa melewati chain FORWARD, maka ini bisa dilakukan di chain PREROUTING table mangle.
Tidak ada komentar:
Posting Komentar