트래픽 제한 스크립트

첨부파일 서버에 업로드하고 확장자만 txt-> sh 로 변경해서 아래처럼 쓰면되요

사용법

# 10Mbps 로 대역폭 제한
/root/script/traffic.sh eth0 10000

# 대역폭 제한 확인
/root/script/traffic.sh eth0

# 대역폭 제한 해제
/root/script/traffic.sh eth0 del


#!/bin/sh

if [ $# == 0 ]; then
  echo Please read the man page for the wondershaper and
  echo the file /usr/share/doc/wondershaper/README.Debian
  exit
fi

if [ $# == 1 ]; then
  /sbin/tc -s qdisc ls dev $1
  /sbin/tc -s class ls dev $1
  exit
fi

if [ "$2" == "del" ]; then
  /sbin/tc qdisc del dev $1 root    2> /dev/null > /dev/null
  echo Wondershaper queues have been cleared.
  exit
fi

# please read the README before filling out these values
#
# Set the following values to somewhat less than your actual download
# and uplink speed. In kilobits. Also set the device that is to be shaped.
UPLINK=$2
DEV=$1

#########################################################

# clean existing down- and uplink qdiscs, hide errors
/sbin/tc qdisc del dev $DEV root    2> /dev/null > /dev/null

###### uplink

# install root HTB
/sbin/tc qdisc add dev $DEV root handle 1:0 htb default 15

# main class
/sbin/tc class add dev $DEV parent 1:0 classid 1:1 htb rate ${UPLINK}kbit

# high prio class 1:5
/sbin/tc class add dev $DEV parent 1:1 classid 1:5 htb rate $(($UPLINK/2))kbit \
    ceil ${UPLINK}kbit prio 2

# bulk and default class 1:10 - gets slightly less traffic,
#  and a lower priority:
/sbin/tc class add dev $DEV parent 1:1 classid 1:10 htb rate $(($UPLINK/2))kbit \
    ceil ${UPLINK}kbit prio 6

# 'traffic we hate'
/sbin/tc class add dev $DEV parent 1:1 classid 1:15 htb rate $(($UPLINK/2))kbit \
    ceil ${UPLINK}kbit prio 10

# all get Stochastic Fairness:
/sbin/tc qdisc add dev $DEV parent 1:5 handle 5: sfq perturb 10
/sbin/tc qdisc add dev $DEV parent 1:10 handle 10: sfq perturb 10
/sbin/tc qdisc add dev $DEV parent 1:15 handle 15: sfq perturb 10

'Security > OS 관련' 카테고리의 다른 글

공유메모리 관련  (0) 2023.11.07
QOS (트래픽 제한 두번째 방법)  (0) 2023.11.07
mod_security 탐지 걸린 룰 해제시 방법  (0) 2023.11.07
apache 2.4 mod 시큐리티  (0) 2023.11.07
mod_security 적용 방법  (0) 2023.11.07

+ Recent posts