1

i am using this code.sh for limit the ip but I wanted to limit everyone equally

ip * limit -d 1000kb -u 1000kb then result: google 1000Kbps, amazon 1000Kbps, any server ip 1000Kbps

I searched on ufw, iptables, google vpc, google search,wondershapper

I don't understand why the Linux community is so lazy to create complete professional tools to the point that I have to search google every time; I never needed to use google to learn how to use on windows;

How can I do traffic shaping in Linux by IP?

tun0 is eth0 in vm google cloud plataform and dont nic0

#! /bin/bash
NETCARD=tun0
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
  • "I don't understand why the Linux community is so lazy to create complete professional tools to the point that I have to search google every time"... what have you contributed to it? Prey tell how would I do this in Windows without any knowledge of the OS ? (Genuinely, I know where to start in Linux, no clue in Windows) – davidgo May 30 '20 at 08:34
  • I can't understand why people are so lazy to read any documentation that they have to ask everything on SE. ;) – Esa Jokinen May 31 '20 at 15:30
  • for two basic reasons, they were lazily documented and don't explain everything compared to microsoft; https://docs.microsoft.com/en-us/windows/win32/iphlp/managing-network-adapters-using-getadaptersinfo – Escanor Nanatsu no Taizai Jun 01 '20 at 21:18
  • i am studying linux in college is definitely very communist; talks about various things and does nothing; – Escanor Nanatsu no Taizai Jun 01 '20 at 21:18
  • I think linux developers are ex-Nazis, trying to prevent beginners from beating masters as they do on windows; – Escanor Nanatsu no Taizai Jun 01 '20 at 21:19
  • I think you have to be very dumb to support Linux or the iPhone, which has a pseudo capitalist community; – Escanor Nanatsu no Taizai Jun 01 '20 at 21:20

0 Answers0