Portál AbcLinuxu, 13. května 2025 20:29
#!/bin/bash INET_IFACE="eth1" LAN_IFACE="eth0" HATES="192.168.1.0/24" LAN="192.168.2.0/24" WAN="192.168.3.0/24" # vymaze hlavni qdisc a zaridi novy iptables -t mangle --flush tc qdisc del dev $INET_IFACE root tc qdisc add dev $INET_IFACE root handle 1:0 htb #hlavni trida tc class add dev $INET_IFACE parent 1:0 classid 1:1 htb rate 4096kbit burst 5k quantum 1700 tc class add dev $INET_IFACE parent 1:1 classid 1:10 htb rate 4096kbit ceil 4096kbit burst 1k quantum 1700 prio 0 #tc class add dev $INET_IFACE parent 1:1 classid 1:99 htb rate 1024kbit burst 1k quantum 1700 prio 7 ############################################################################################ # HATES tc class add dev $INET_IFACE parent 1:10 classid 1:20 htb rate 1024kbit ceil 2048kbit burst 1k quantum 1700 prio 2 #www iptables -t mangle -A FORWARD -o $INET_IFACE -d $HATES -p tcp --dport 80 -j MARK --set-mark 201 tc class add dev $INET_IFACE parent 1:20 classid 1:201 htb rate 1024kbit ceil 2048kbit burst 1k quantum 1700 prio 4 tc qdisc add dev $INET_IFACE parent 1:201 handle 201:0 sfq perturb 10 tc filter add dev $INET_IFACE protocol ip prio 20 handle 201 fw flowid 1:201 #ostatni iptables -t mangle -A FORWARD -o $INET_IFACE -d $HATES -j MARK --set-mark 203 tc class add dev $INET_IFACE parent 1:20 classid 1:203 htb rate 256kbit ceil 256kbit burst 1k quantum 1700 prio 6 tc qdisc add dev $INET_IFACE parent 1:203 handle 203:0 sfq perturb 10 tc filter add dev $INET_IFACE protocol ip prio 30 handle 203 fw flowid 1:203 ############################################################################################ ############################################################################################ # LAN tc class add dev $INET_IFACE parent 1:10 classid 1:30 htb rate 1024kbit ceil 1024kbit burst 1k quantum 1700 prio 2 #www iptables -t mangle -A FORWARD -o $INET_IFACE -d $LAN -p tcp --dport 80 -j MARK --set-mark 301 tc class add dev $INET_IFACE parent 1:30 classid 1:301 htb rate 512kbit ceil 512kbit burst 1k quantum 1700 prio 4 tc qdisc add dev $INET_IFACE parent 1:301 handle 301:0 sfq perturb 10 tc filter add dev $INET_IFACE protocol ip prio 20 handle 301 fw flowid 1:301 #ostatni iptables -t mangle -A FORWARD -o $INET_IFACE -d $LAN -j MARK --set-mark 303 tc class add dev $INET_IFACE parent 1:30 classid 1:303 htb rate 512kbit ceil 512kbit burst 1k quantum 1700 prio 6 tc qdisc add dev $INET_IFACE parent 1:303 handle 303:0 sfq perturb 10 tc filter add dev $INET_IFACE protocol ip prio 30 handle 303 fw flowid 1:303 ############################################################################################ ############################################################################################ # WAN tc class add dev $INET_IFACE parent 1:10 classid 1:40 htb rate 1024kbit ceil 1024kbit burst 1k quantum 1700 prio 2 #www iptables -t mangle -A FORWARD -o $INET_IFACE -d $WAN -p tcp --dport 80 -j MARK --set-mark 401 tc class add dev $INET_IFACE parent 1:40 classid 1:401 htb rate 512kbit ceil 512kbit burst 1k quantum 1700 prio 4 tc qdisc add dev $INET_IFACE parent 1:401 handle 401:0 sfq perturb 10 tc filter add dev $INET_IFACE protocol ip prio 20 handle 401 fw flowid 1:401 #ostatni iptables -t mangle -A FORWARD -o $INET_IFACE -d $WAN -j MARK --set-mark 403 tc class add dev $INET_IFACE parent 1:40 classid 1:403 htb rate 512kbit ceil 512kbit burst 1k quantum 1700 prio 6 tc qdisc add dev $INET_IFACE parent 1:403 handle 403:0 sfq perturb 10 tc filter add dev $INET_IFACE protocol ip prio 30 handle 403 fw flowid 1:403 ############################################################################################pokud si vyjedu prikazem tc -s -d qdisc tak to vypise tohle
server1:/home/hates# tc -d -s qdisc qdisc pfifo_fast 0: dev eth0 bands 3 priomap 1 2 2 2 1 2 0 0 1 1 1 1 1 1 1 1 Sent 1444546287 bytes 1885888 pkts (dropped 0, overlimits 0) qdisc sfq 403: dev eth1 limit 128p quantum 1514b flows 128/1024 perturb 10sec Sent 0 bytes 0 pkts (dropped 0, overlimits 0) qdisc sfq 401: dev eth1 limit 128p quantum 1514b flows 128/1024 perturb 10sec Sent 0 bytes 0 pkts (dropped 0, overlimits 0) qdisc sfq 303: dev eth1 limit 128p quantum 1514b flows 128/1024 perturb 10sec Sent 0 bytes 0 pkts (dropped 0, overlimits 0) qdisc sfq 301: dev eth1 limit 128p quantum 1514b flows 128/1024 perturb 10sec Sent 0 bytes 0 pkts (dropped 0, overlimits 0) qdisc sfq 203: dev eth1 limit 128p quantum 1514b flows 128/1024 perturb 10sec Sent 0 bytes 0 pkts (dropped 0, overlimits 0) qdisc sfq 201: dev eth1 limit 128p quantum 1514b flows 128/1024 perturb 10sec Sent 0 bytes 0 pkts (dropped 0, overlimits 0) qdisc htb 1: dev eth1 r2q 10 default 0 direct_packets_stat 11277 ver 3.16 Sent 4593547 bytes 11277 pkts (dropped 0, overlimits 0)coz mi pripada jako kdyz by provoz nechtel test pres jine tridy ale tekl porad pouze pres hlavni
iptables -t mangle -A POSTROUTING -o $LAN_IFACE -d $LAN -p tcp --dport 80 -j MARK --set-mark 1sitova karta eth1 je do internetu ale nema verejnou IP je na ni privedena rychlost 4096kbit, co potrebuji omezovat tak provoz ze site do internetu ale chtel bych se vyhnout omezovani provozu ze site na server.
eth1------------------eth0 INTERNET -----------| ROUTER |------------------LAN 10.10.10.1------------------192.168.1.1/22 (192.168.1.0/22) #!/bin/bash INET_IFACE="eth1" LAN_IFACE="eth0" LAN="192.168.1.0/24" WAN1="192.168.2.0/24" WAN2="192.168.3.0/24" # vymaze hlavni qdisc a zaridi novy iptables -t mangle --flush tc qdisc del dev $LAN_IFACE root tc qdisc del dev $INET_IFACE root tc qdisc add dev $LAN_IFACE root handle 1:0 htb #hlavni trida tc class add dev $LAN_IFACE parent 1:0 classid 1:1 htb rate 3584kbit burst 5k quantum 1700 ############################################################################################ # LAN tc class add dev $LAN_IFACE parent 1:1 classid 1:101 htb rate 1536kbit ceil 1536kbit burst 1k quantum 1700 prio 1 iptables -t mangle -A POSTROUTING -o $LAN_IFACE -d $LAN -p tcp --dport 80 -j MARK --set-mark 1 tc class add dev $LAN_IFACE parent 1:101 classid 1011 htb rate 512kbit ceil 1024kbit burst 1k quantum 1700 prio 2 tc qdisc add dev $LAN_IFACE parent 1:1011 handle 1011:0 sfq perturb 10 tc filter add dev $LAN_IFACE protocol ip prio 20 handle 1 fw flowid 1:1011 iptables -t mangle -A POSTROUTING -o $LAN_IFACE -d $LAN -j MARK --set-mark 11 tc class add dev $LAN_IFACE parent 1:101 classid 1012 htb rate 512kbit ceil 1024kbit burst 1k quantum 1700 prio 3 tc qdisc add dev $LAN_IFACE parent 1:1012 handle 1012:0 sfq perturb 10 tc filter add dev $LAN_IFACE protocol ip prio 20 handle 11 fw flowid 1:1012 ############################################################################################ # WAN1 tc class add dev $LAN_IFACE parent 1:1 classid 1:102 htb rate 1024kbit ceil 1024kbit burst 1k quantum 1700 prio 1 iptables -t mangle -A POSTROUTING -o $LAN_IFACE -d $WAN1 -j MARK --set-mark 2 tc qdisc add dev $LAN_IFACE parent 1:102 handle 102:0 sfq perturb 10 tc filter add dev $LAN_IFACE protocol ip prio 20 handle 2 fw flowid 1:102 ############################################################################################ # WAN2 tc class add dev $LAN_IFACE parent 1:11 classid 1:103 htb rate 1024kbit ceil 1024kbit burst 1k quantum 1700 prio 1 iptables -t mangle -A POSTROUTING -o $LAN_IFACE -d $WAN2 -j MARK --set-mark 3 tc qdisc add dev $LAN_IFACE parent 1:103 handle 103:0 sfq perturb 10 tc filter add dev $LAN_IFACE protocol ip prio 20 handle 3 fw flowid 1:103
iptables -t mangle -A POSTROUTING -o $LAN_IFACE -d $LAN -p tcp --sport 80 -j MARK --set-mark 1
Tiskni
Sdílej:
ISSN 1214-1267, (c) 1999-2007 Stickfish s.r.o.