example.json
· 90 B · JSON
Raw
{
"eth0": {
"high": [22,80,443],
"medium": [8096,9091],
"low": [51413]
}
}
1 | { |
2 | "eth0": { |
3 | "high": [22,80,443], |
4 | "medium": [8096,9091], |
5 | "low": [51413] |
6 | } |
7 | } |
netprio.sh
· 1.7 KiB · Bash
Raw
#!/bin/bash
# Check if jq is installed
if ! command -v jq &> /dev/null
then
echo "jq is not installed. Please install it before running the script."
exit 1
fi
# Check if a JSON file is provided as an argument
if [ -z "$1" ]; then
echo "Please provide the JSON configuration file as an argument."
exit 1
fi
# Read the JSON file
JSON_FILE=$1
# Apply rules for each network interface (eno1, wg0, etc.)
for interface in $(jq -r 'keys[]' "$JSON_FILE"); do
echo "Applying rules for interface $interface..."
# Delete existing qdisc if it exists
tc qdisc del dev "$interface" root 2>/dev/null
# Set the prio queue for the interface
tc qdisc add dev "$interface" root handle 1: prio
# Set high priority ports
high_ports=$(jq -r ".\"$interface\".high[]" "$JSON_FILE")
for port in $high_ports; do
echo " Setting port $port as high priority on $interface..."
tc filter add dev "$interface" protocol ip parent 1: prio 0 u32 match ip dport "$port" 0xffff flowid 1:0
done
# Set medium priority ports
medium_ports=$(jq -r ".\"$interface\".medium[]" "$JSON_FILE")
for port in $medium_ports; do
echo " Setting port $port as medium priority on $interface..."
tc filter add dev "$interface" protocol ip parent 1: prio 1 u32 match ip dport "$port" 0xffff flowid 1:1
done
# Set low priority ports
low_ports=$(jq -r ".\"$interface\".low[]" "$JSON_FILE")
for port in $low_ports; do
echo " Setting port $port as low priority on $interface..."
tc filter add dev "$interface" protocol ip parent 1: prio 2 u32 match ip dport "$port" 0xffff flowid 1:2
done
done
echo "Rules have been successfully applied."
1 | #!/bin/bash |
2 | |
3 | # Check if jq is installed |
4 | if ! command -v jq &> /dev/null |
5 | then |
6 | echo "jq is not installed. Please install it before running the script." |
7 | exit 1 |
8 | fi |
9 | |
10 | # Check if a JSON file is provided as an argument |
11 | if [ -z "$1" ]; then |
12 | echo "Please provide the JSON configuration file as an argument." |
13 | exit 1 |
14 | fi |
15 | |
16 | # Read the JSON file |
17 | JSON_FILE=$1 |
18 | |
19 | # Apply rules for each network interface (eno1, wg0, etc.) |
20 | for interface in $(jq -r 'keys[]' "$JSON_FILE"); do |
21 | echo "Applying rules for interface $interface..." |
22 | |
23 | # Delete existing qdisc if it exists |
24 | tc qdisc del dev "$interface" root 2>/dev/null |
25 | |
26 | # Set the prio queue for the interface |
27 | tc qdisc add dev "$interface" root handle 1: prio |
28 | |
29 | # Set high priority ports |
30 | high_ports=$(jq -r ".\"$interface\".high[]" "$JSON_FILE") |
31 | for port in $high_ports; do |
32 | echo " Setting port $port as high priority on $interface..." |
33 | tc filter add dev "$interface" protocol ip parent 1: prio 0 u32 match ip dport "$port" 0xffff flowid 1:0 |
34 | done |
35 | |
36 | # Set medium priority ports |
37 | medium_ports=$(jq -r ".\"$interface\".medium[]" "$JSON_FILE") |
38 | for port in $medium_ports; do |
39 | echo " Setting port $port as medium priority on $interface..." |
40 | tc filter add dev "$interface" protocol ip parent 1: prio 1 u32 match ip dport "$port" 0xffff flowid 1:1 |
41 | done |
42 | |
43 | # Set low priority ports |
44 | low_ports=$(jq -r ".\"$interface\".low[]" "$JSON_FILE") |
45 | for port in $low_ports; do |
46 | echo " Setting port $port as low priority on $interface..." |
47 | tc filter add dev "$interface" protocol ip parent 1: prio 2 u32 match ip dport "$port" 0xffff flowid 1:2 |
48 | done |
49 | done |
50 | |
51 | echo "Rules have been successfully applied." |