Packet Shaping – Packet Filter di FreeBSD

Original Link :  http://unilanet.unila.ac.id/~gigih/index.php?option=com_content&task=view&id=37&Itemid=34

Banyak yang tanya ke Gue gimana sih cara mengatur bandwidth, kalo mesin servernya Pake FreeBSD

di FreeBSD dikenal ALTQ yang berfungsi sebagai traffick shapper untuk membatasi bandwith client. Sebelum versi FreeBSD 5.3 keluar service NAT,Firewall,ALTQ   diinstall terpisah,  Setelah generasi 5.xx keluar, muncul teknologi baru di FREEBSD yaitu PF (Packet Filter).

Teknologi ini merupakan penggabungan dari service NAT,Firewall,ALTQ dalam satu kesatuan yang utuh.

Ok lansung aja deh kita eksperiment, otre…….

Asumsi saya, Mesin yang akan kita konfigurasi sudah terhubung dengan jaringan bisa ping-pingan dan bisa resolv DNS. Jika belom baca lagi deh manual gua tentang

pemberian “identitas” pada FreeBSD

pastikan bahwa   statement  pf_enable=”YES” telah dimasukkan di /etc/rc.conf

Jika udah langsung aja buak editor Vi kesayangan anda

Dibawah ini merupakan contoh  konfigurasi Traffick shapping dengan Menggunakan PF

proxy# vi /etc/pf.conf

############################################################
# Basic (Working) RULE For BSD TELKOM GW
# NO IMPROVEMENT YET
# Update 07-12-2005
# Gigih Forda Nama :
############################################################ 

eIF  = “rl0”  ## Menuju ke TELKOM
iIF  = “em0” ## Network 1
dIF  = “re0”  ## Ke Inherent Dikti

altq on $iIF hfsc bandwidth 40Mb queue { local, internet }
queue internet bandwidth 4Mb { qPROXY, qGIGIH, qGATEDIAL, qWIFI, qMGT, qAKT, qBBS, qSCSC }

queue qPROXY bandwidth 2744Kb priority 5 hfsc(realtime 2744Kb
upperlimit 2744Kb linkshare 60% red)
queue qGATEDIAL bandwidth 400Kb priority 4 hfsc(realtime 400Kb
upperlimit 400Kb linkshare 10% red)
queue qMGT bandwidth 64Kb priority 4 hfsc(realtime 66Kb
upperlimit 66Kb linkshare 5% red)
queue qAKT bandwidth 64Kb priority 4 hfsc(realtime 66Kb
upperlimit 66Kb linkshare 5% red)
queue qSCSC bandwidth 64Kb priority 4 hfsc(realtime 64Kb
upperlimit 64Kb linkshare 1% red)
queue qWIFI bandwidth 256Kb priority 4 hfsc(realtime 256Kb
upperlimit 256Kb linkshare 3% red)
queue qGIGIH bandwidth 64Kb priority 4 hfsc(realtime 64Kb
upperlimit 64Kb linkshare 1% red)
queue qBBS bandwidth 128Kb priority 4 hfsc(realtime 256Kb
upperlimit 1500Kb linkshare 5% red)
queue local bandwidth 90% hfsc(default)

nat on $dIF from 192.168.1.1 to 152.118.0.0/16 -> 203.88.66.49
nat on $dIF from 192.168.1.204 to 167.205.0.0/16 ->  167.205.143.5

binat on $dIF from 192.168.10.252 to any -> 167.205.143.9

##### 2). Rules KE UI   #########
nat      on $dIF from {192.168.9.9,192.168.113.0/24}   to  152.118.0.0/16 -> 167.205.143.10
##### 3). RULES  KE UGM   #######
nat      on $dIF from { 192.168.90.0/24,192.168.112.0/24,192.168.113.0/24}   to  222.124.0.0/16 -> 167.205.143.10

## Transparent PROXY SQUID
rdr on $iIF inet proto tcp from 192.168.1.0/24 to !192.168.0.0/16 port www -> 127.0.0.1 port 3128

# from lan to internet
pass in  log on $iIF inet from any to any
pass out log on $iIF inet from any to any

pass  in      on $iIF inet from 192.168.1.0/24 to any keep state queue qBBS
pass  in  log on $iIF inet from 192.168.1.0/24 to
{ $iIF, 172.16.1.0/27, 203.88.66.32/27, 202.72.204.32/27, 202.174.156.128/27 } keep state
pass  in      on $iIF inet proto tcp from 192.168.1.0/24 to { 127.0.0.1, $iIF:0 } port 3128 keep state queue qBBS
pass  in      on $iIF inet proto tcp from 192.168.1.215  to any keep state queue qGATEDIAL
pass  in      on $iIF inet proto tcp from {192.168.1.235,192.168.9.13,192.168.9.0/24}  to any keep state queue qWIFI
pass  in      on $iIF inet proto tcp from { 192.168.112.15, 192.168.112.16 } to any keep state queue qMGT
pass  in      on $iIF inet proto tcp from { 192.168.113.8 } to any keep state queue qAKT
pass  in      on $iIF inet proto tcp from 192.168.1.115    to $iIF:0 port 3128 keep state queue qPROXY
pass  in      on $iIF inet proto tcp from 192.168.30.2   to any keep state queue qSCSC
pass  in      on $iIF inet proto tcp from 192.168.1.204 to any  keep state queue qGIGIH
pass  in      on $iIF inet proto tcp from 192.168.0.0/16 to $iIF:0 port 8080 keep state queue qSQAUTH

pass  out log on $iIF inet proto tcp from $iIF to any keep state flags S/SA

pass quick on lo0 all
#pass in all
pass out all

pass quick on $eIF from any to any
pass quick on $dIF from any to any

Yang mesti diingat, urut-urutan dari PF ini harus benar

  • Rules ALTQ pada posisi paling atas
  • Rules NAT harus setelah ALQ
  • Rule firewall setelah NAT

jika urutan nya tidak sesuai maka akan tampil pesan error, please be ware

Setelah itu reboot server anda

untuk mengecek apakah ALTQ sudah berjalan sesuai harapan ketik command berikut

pfctl -vvsq

Selamat mencoba, semoga bermanfaat

please leave a comment  if u feel confious

Leave a Reply

Your email address will not be published. Required fields are marked *