嘿所有,我想知道如果你能看看我的剧本,并帮我添加一些东西,
#!/bin/bash # Name of the traffic control command. TC=/sbin/tc # The network interface we're planning on limiting bandwidth. IF=eth0 # Network card interface # Download limit (in mega bits) DNLD=10mbit # DOWNLOAD Limit # Upload limit (in mega bits) UPLD=1mbit # UPLOAD Limit # IP address range of the machine we are controlling IP=192.168.0.1 # Host IP # Filter options for limiting the intended interface. U32="$TC filter add dev $IF protocol ip parent 1:0 prio 1 u32" start() { # Hierarchical Token Bucket (HTB) to shape bandwidth $TC qdisc add dev $IF root handle 1: htb default 30 #Creates the root schedlar $TC class add dev $IF parent 1: classid 1:1 htb rate $DNLD #Creates a child schedlar to shape download $TC class add dev $IF parent 1: classid 1:2 htb rate $UPLD #Creates a child schedlar to shape upload $U32 match ip dst $IP/24 flowid 1:1 #Filter to match the interface, limit download speed $U32 match ip src $IP/24 flowid 1:2 #Filter to match the interface, 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 "Bandwidth shaping status for $IF:" show echo "" ;; *) pwd=$(pwd) echo "Usage: tc.bash {start|stop|restart|show}" ;; esac exit 0
谢谢
如果它们没有被重命名,则可以通过在/sys/class/net/查找与eth*匹配的目录来查找所有以太网设备。 要将这些操作应用于多个NIC和IP地址,请查看循环 。 这是一个例子
#!/bin/bash ADDRESSES="192.0.2.1 192.0.2.2" for I in /sys/class/net/eth* do I=$(basename $I) for A in $ADDRESSES do echo $I $A done done
在具有两个以太网设备的系统上,这将输出
eth0 192.0.2.1
eth0 192.0.2.2
eth1 192.0.2.1
eth1 192.0.2.2
获取以太网链接列表:
/sbin/ip link
获取连接的以太网链接列表:
/sbin/ip link | grep 'UP'
我不明白你的问题的其余部分。