我如何通过 xen 客户机在 Linux 中进行流量整形?

我如何通过 xen 客户机在 Linux 中进行流量整形?

我希望能够像这样设置两个 xen 客户机:

xen-create-image --hostname=xen1.example.com --size=10Gb --swap=512Mb --ip=192.168.0.101 --force --memory=256Mb --arch=i386 --debootstrap

xen-create-image --hostname=xen1.example.com --size=10Gb --swap=512Mb --ip=192.168.0.102 --force --memory=256Mb --arch=i386 --debootstrap

(区别在于 ips '192.168.0.102' 和 '192.168.0.101')我想设置它,以便 '192.168.0.102' 具有拨号速度,而 '192.168.0.101' 具有到 xen1.example.com 的未整形连接速度。我对流量整形一无所知,也不知道我需要安装什么才能做到这一点。所以我想当你回答时会非常关心新手。

    #! /bin/bash
NETCARD=eth0
MAXBANDWIDTH=100000

# reinit
tc qdisc del dev $NETCARD root handle 1
tc qdisc add dev $NETCARD root handle 1: htb default 9999

# create the default class
tc class add dev $NETCARD parent 1:0 classid 1:9999 htb rate $(( $MAXBANDWIDTH ))kbit ceil $(( $MAXBANDWIDTH ))kbit burst 5k prio 9999

# control bandwidth per IP
declare -A ipctrl
# define list of IP and bandwidth (in kilo bits per seconds) below
ipctrl[192.168.1.1]="256"
ipctrl[192.168.1.2]="128"
ipctrl[192.168.1.3]="512"
ipctrl[192.168.1.4]="32"

mark=0
for ip in "${!ipctrl[@]}"
do
    mark=$(( mark + 1 ))
    bandwidth=${ipctrl[$ip]}

    # traffic shaping rule
    tc class add dev $NETCARD parent 1:0 classid 1:$mark htb rate $(( $bandwidth ))kbit ceil $(( $bandwidth ))kbit burst 5k prio $mark

    # netfilter packet marking rule
    iptables -t mangle -A INPUT -i $NETCARD -s $ip -j CONNMARK --set-mark $mark

    # filter that bind the two
    tc filter add dev $NETCARD parent 1:0 protocol ip prio $mark handle $mark fw flowid 1:$mark

    echo "IP $ip is attached to mark $mark and limited to $bandwidth kbps"
done

#propagate netfilter marks on connections
iptables -t mangle -A POSTROUTING -j CONNMARK --restore-mark

我确实看到了上面的内容,但我不知道我需要编辑什么配置文件。

所以要说清楚。我想用两个 IP 访问同一个网站,但一个 IP 有拨号速度,另一个没有。非常感谢!

答案1

我为此使用了我的 pfSense 防火墙。

ipfw 和 freebsd 在这类事情上比 Linux 更好

希望你尝试一下 :D

相关内容