이니미니

traffic shaping(트래픽제한) 본문

linux&server/issue

traffic shaping(트래픽제한)

OYG 2019. 11. 22. 15:04

클릭하여이동


1. 트래픽 모니터링


2. 트래픽 제한






앞포스팅에선 네트워크 상태를 모니터링 하였고


이젠 트래픽 제한을 걸려고 한다.


1) 요구 사항
– iproute RPM 패키지가 설치되어있어야 함
– 리눅스 커널의 iproute 파트의 Traffic Control 옵션(Netlink포함)이 활성화 되어있어야 함.
– 리눅스 커널 2.4버젼 이후의 경우 기본적으로 대부분의 Traffic Control 옵션이 활성화 되어있음.



/etc/init.d/shaping



 # tc명령어의 위치

TC=/sbin/tc


# 대상 이더넷 인터페이스

IF= eno1 


# 다운로드 속도 [데이터이동 : client -> server]

DNLD=15mbit


# 업로드 속도  [데이터이동 : client <- server]

UPLD=12mbit


# 속도 제한을 적용할 호스트

IP= [ host ] 

 
# Filter options for limiting the intended interface.

U32="$TC filter add dev $IF protocol ip parent 1:0 prio 1 u32"


# We’ll use Hierarchical Token Bucket (HTB) to shape bandwidth.
# For detailed configuration options, please consult Linux man
# page.

start(){

        $TC qdisc add dev $IF root handle 1: htb default 30

        $TC class add dev $IF parent 1: classid 1:1 htb rate $DNLD

        $TC class add dev $IF parent 1: classid 1:2 htb rate $UPLD

        $U32 match ip dst $IP/32 flowid 1:1

        $U32 match ip src $IP/32 flowid 1:2


# The first line creates the root qdisc, and the next two lines
# create two child qdisc that are to be used to shape download 
# and upload bandwidth.
#
# The 4th and 5th line creates the filter to match the interface.
# The ‘dst’ IP address is used to limit download speed, and the 
# ‘src’ IP address is used to limit upload speed.

}


stop(){


# Stop the bandwidth shaping.

        $TC qdisc del dev $IF root

}


restart(){


# Self-explanatory.

        stop

        sleep 1

        start

}


show(){


# Display status of traffic control status.

        $TC -s qdisc ls dev $IF

}



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 -n "Bandwidth shaping status for $IF: "

                show

                echo "done"

                ;;

        *)

        pwd=$(pwd)

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

        ;;

esac


exit 0





실행권한을 주고 실행하면 된다.


$ chmod 755 /etc/init.d/shaping



'linux&server > issue' 카테고리의 다른 글

iftop 트래픽 모니터링 / ubuntu  (0) 2019.11.22
mysql linux서버 외부접속  (0) 2018.04.06
Comments