Witam - odpalilem htb na serwerku na ktorym mam takze =
ftp dla sieci
lokalnej. Problem w tym ze htb chyba nie wie czy to =
ftp lan'u czy
zewnetrzne. Czy ktos ma jakis pomysl jak zmodyfikowac =
ponizszy skrypt ?
Kopiowanie z serwera ftpem jest takie jak z netu (a =
przeciez to lan).
Najlepsze jest to ze sciaganie z lokalnego ftp'a =
organicza sciaganie z netu
(wg regul pliku rc.htb).
#!/bin/bash
# rc.htb, (c)PriSM 2oo3
# usage: rc.htb start|stop|restart
# ---------------------------
# CONFIGURATION
# ---------------------------
# switch this to YES to enable the script :)
ENABLE="YES"
# all names must be taken from /etc/hosts
# machine which shares the link (this =
SERVER="server"
# which machines are using the link
USERS="user2 user3 user4 user5 user6 user7 =
user8 user9 user15 user16 user20
user21 user22 user23 user24 user25 user26 user30 =
user31 user32 user40 user41
user42 user50 user51 user52"
# ADVANCED AND IMPORTANT: Changing field delimeter =
used in /etc/hosts.
# If you use TABs in your /etc/host to divide IP from =
host just go further.
# If you use space as delimeter, uncomment the line =
below:
# DELIM="-d ' '"
# your net link speed [kbits] i.e. 115/115, =
512/128
INSPEED=1024
OUTSPEED=256
LINKDEV=eth0 # device which connects you to =
LANSPEED=100000 # your lan-device speed =
[kbits]
LANDEV=eth1 # device which connects your =
lan
# speeds for guests (queuing on link device)
# values are in _percents_ of the whole link =
speed
# do not enter zero anywhere! tc needs 1kbit =
minimum
FAST=15 # 15% of bandwitch for ACKs, =
SSH and ICMP
HTTP_MIN=25 # 25% for www
HTTP_MAX=100 # or max. 100% if no other =
traffic
FTP_MIN=30 # 30% for ftp serving
FTP_MAX=100 # or max. 100% if no other =
traffic
OTHER_MIN=20 # other type of traffic, minimal =
OTHER_MAX=60 # only 60% for max to limit i.e. =
KaZaA sharing
# ----------------------------
# END OF CONFIGURATION
# ----------------------------
# lower speed rates to 99% and calculate some =
INSPEED=$[$INSPEED*99/100]
OUTSPEED=$[$OUTSPEED*99/100]
LANSPEED=$[$LANSPEED*99/100]
SPEED=$[$LANSPEED-$INSPEED]
FAST=$[$OUTSPEED*$FAST/100]
HTTP_MIN=$[$OUTSPEED*$HTTP_MIN/100]
HTTP_MAX=$[$OUTSPEED*$HTTP_MAX/100]
FTP_MIN=$[$OUTSPEED*$FTP_MIN/100]
FTP_MAX=$[$OUTSPEED*$FTP_MAX/100]
OTHER_MIN=$[$OUTSPEED*$OTHER_MIN/100]
OTHER_MAX=$[$OUTSPEED*$OTHER_MAX/100]
IP=""
getip()
{
IP=`grep -v ".*#.*\b$1\b" =
/etc/hosts | grep "\b$1\b" | cut -f 1 $DELIM`
}
USERCOUNT=0
USERSPEED=$INSPEED
calculate()
{
USERCOUNT=$#
USERSPEED=$[$INSPEED/$USERCOUNT]
echo "Setting up for $USERCOUNT users =
(${USERSPEED}kbits for each):"
}
delroot()
{
tc qdisc del root dev $LANDEV 2> =
/dev/null
tc qdisc del root dev $LINKDEV 2> =
/dev/null
}
stop()
{
echo -n "rc.htb: Disabling =
queuing..."
delroot
echo " done."
}
start()
{
check()
{
if [ $ENABLE != "YES" ]; then
echo "rc.htb is not yet configured, please =
exit 1
fi
}
instream()
{
tc qdisc add dev $LANDEV root handle 1:0 htb
tc class add dev $LANDEV parent 1:0 classid 1:1 htb =
rate ${LANSPEED}kbit
ceil ${LANSPEED}kbit
}
linklocal()
{
tc class add dev $LANDEV parent 1:1 classid 1:2 htb =
rate ${INSPEED}kbit ceil
${INSPEED}kbit
tc class add dev $LANDEV parent 1:1 classid 1:3 htb =
rate ${SPEED}kbit ceil
${SPEED}kbit
}
userdiv()
{
for i in `seq 1 $USERCOUNT`;
do
tc class add dev $LANDEV parent 1:2 classid =
1:$[$i+3] htb rate
${USERSPEED}kbit ceil ${INSPEED}kbit
done
}
userfilter()
{
getip $SERVER
tc filter add dev $LANDEV protocol ip parent 1:0 u32 =
match ip src $IP flowid
1:3
NUM=4
for i in $USERS;
do
getip $i
echo " - $i ($IP)"
tc filter add dev $LANDEV protocol ip parent =
1:0 u32 match ip dst $IP
flowid 1:${NUM}
NUM=$(($NUM+1))
done
}
sfqin()
{
tc qdisc add dev $LANDEV parent 1:3 handle 3:0 sfq =
perturb 10
for i in `seq 1 $USERCOUNT`;
do
tc qdisc add dev $LANDEV parent 1:$[$i+3] =
handle $[$i+3]:0 sfq perturb 10
done
}
#---------------------------------------------------------
outstream()
{
tc qdisc add dev $LINKDEV root handle 1: htb default =
40
tc class add dev $LINKDEV parent 1: classid 1:1 htb =
rate ${OUTSPEED}kbit
ceil ${OUTSPEED}kbit burst 6k
}
servdiv()
{
tc class add dev $LINKDEV parent 1:1 classid 1:10 htb =
rate ${FAST}kbit ceil
${OUTSPEED}kbit prio 1
tc class add dev $LINKDEV parent 1:1 classid 1:20 htb =
rate ${HTTP_MIN}kbit
ceil ${HTTP_MAX}kbit prio 2
tc class add dev $LINKDEV parent 1:1 classid 1:30 htb =
rate ${FTP_MIN}kbit
ceil ${FTP_MAX}kbit prio 2
tc class add dev $LINKDEV parent 1:1 classid 1:40 htb =
rate ${OTHER_MIN}kbit
ceil ${OTHER_MAX}kbit prio 2
}
servfilter()
{
# minimal latency for TOS
tc filter add dev $LINKDEV parent 1:0 protocol ip =
prio 10 u32 match ip tos
0x10 0xff flowid 1:10
# ICMP
tc filter add dev $LINKDEV parent 1:0 protocol ip =
prio 10 u32 match ip
protocol 1 0xff flowid 1:10
# ACK packets
tc filter add dev $LINKDEV parent 1: protocol ip prio =
10 u32 \
match ip protocol 6 0xff \
match u8 0x05 0x0f at 0 \
match u16 0x0000 0xffc0 at 2 \
match u8 0x10 0xff at 33 \
flowid 1:10
tc filter add dev $LINKDEV protocol ip parent 1:0 u32 =
match ip sport 80
0xffff flowid 1:20
tc filter add dev $LINKDEV protocol ip parent 1:0 u32 =
match ip sport 20
0xffff flowid 1:30
}
sfqout()
{
for i in `seq 1 4`;
do
tc qdisc add dev $LINKDEV parent 1:$[$i*10] handle =
$[$i*10]:0 sfq perturb 10
done
}
# starting...
echo "rc.htb: Starting..."
check
echo "Performing root erasing..."
delroot
echo "OK, now let's get to work..."
echo "Assuming link-in/link-out/LAN speed: =
$INSPEED/$OUTSPEED/$LANSPEED
kbits."
calculate $USERS
instream
linklocal
userdiv
userfilter
sfqin
echo "Reserving ${FAST}kbits of your bandwitch =
for ACKs, SSH and ICMP."
echo "Assuming Min/Max kbits for HTTP: =
$HTTP_MIN/$HTTP_MAX FTP:
$FTP_MIN/$FTP_MAX Other: =
$OTHER_MIN/$OTHER_MAX"
outstream
servdiv
servfilter
sfqout
echo "rc.htb: Finished starting up, have fun... =
:)"
}
# =
==========================
==========================
===
echo "rc.htb, version 0.22, (c)PriSM 2oo3 - =
under GNU general public
license"
case "$1" in
'start')
start
;;
'stop')
stop
;;
'restart')
stop
start
;;
*)
echo "Usage: $0 =
start|stop|restart"
;;
esac