맛집 여행 캠핑 일상 생활

리눅스 트래픽 제어 본문

LAMP

리눅스 트래픽 제어

영은파더♥ 2016. 1. 26. 14:27

● 리눅스 트래픽 제어


FTP는 자체 환경설정에 속도제어가 있고 아파치는 cband 모듈을 이용해서 트래픽 제어가 가능하다.

그러나 이 외에도 tc 명령어를 이용한 방법도 있다.



#!/bin/bash

#

# shaping       This shell script takes care of starting and stopping

#               Network Traffic Control.

#

# chkconfig: - 60 30

# description: Shaping is a traffic control for network.

#


# tc uses the following units when passed as a parameter.

# kbit: Kilobits per second

# mbit: Megabits per second

#


# Name of the traffic control command.

TC=/sbin/tc


# The network interface we're planning on limiting bandwidth.

DEV=eth0


# Upload limit (unit kbit, mbit)

UPLIMIT=10mbit

DNLIMIT=10mbit


start() {

    ${TC} qdisc add dev ${DEV} root handle 1:0 htb default 1

    ${TC} class add dev ${DEV} parent 1:0 classid 1:1 htb rate ${UPLIMIT}

    ${TC} qdisc add dev ${DEV} handle ffff: ingress

    ${TC} filter add dev ${DEV} parent ffff: protocol ip prio 2 u32 match ip src 0.0.0.0/0 police rate ${DNLIMIT} burst 100kb drop flowid :1

}


stop() {

# Stop the bandwidth shaping.

    ${TC} qdisc del dev ${DEV} root

    ${TC} qdisc del dev ${DEV} ingress

}


restart() {

# Self-explanatory.

    stop

    sleep 1

    start

}


show() {

# Display status of traffic control status.

    ${TC} -s qdisc ls dev ${DEV}

}


case "$1" in

  start)

    echo -n "Starting bandwidth shaping: "

    start

    echo "done"

    ;;

  stop)

    echo -n "Stopping bandwidth shaping: "

    stop

    echo "done"

    ;;

  restart)

    echo -n "Restarting bandwidth shaping: "

    restart

    echo "done"

    ;;

  show)

    echo "Bandwidth shaping status for ${DEV}:"

    show

    echo ""

    ;;

  *)

    pwd=$(pwd)

    echo "Usage: tc.bash {start|stop|restart|show}"

    ;;

esac


exit 0




위의 파일을 /etc/init.d/ 에 적절한 이름으로 저장을 한 다음에

아래 부분을 찾아서 입맛에 맞게 고쳐서 사용을 하면 된다.


TC=/sbin/tc

DEV=eth0

UPLIMIT=10mbit

DNLIMIT=10mbit



'LAMP' 카테고리의 다른 글

ssh 암호 입력 없이 rsync 하는 방법  (0) 2016.01.28
아파치 유저 권한 모듈  (0) 2016.01.28
HTML5 Server-Sent Events 서버 푸쉬  (0) 2016.01.25
Too many open files 에러메시지 대응방법  (0) 2016.01.25
vsftpd 설치 및 설정  (0) 2016.01.25
Trackback : | Comments :