mirror of
https://github.com/MHSanaei/3x-ui.git
synced 2026-12-03 21:18:19 +07:00
[GH-ISSUE #1102] Speed Limit for Inbound and Client #748
Labels
No labels
backlog
bug
clarification needed
documentation
duplicate
enhancement
github_actions
good first issue
invalid
javascript
New Feature
PR welcomed
pull-request
question
wontfix
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set.
Reference
MHSanaei/3x-ui#748
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Originally created by @pro9793 on GitHub (Oct 3, 2023).
Original GitHub issue: https://github.com/MHSanaei/3x-ui/issues/1102
I have to speed limit my clients. May be you can make this new feature to low the cpu usage of the server. To make this I do make the new Inbound for every client, to use different port number, because Ip is dynamic. So that I can limit the speed by tc commands. I use this code to limit 2 clients on ports 64001 and 64002 for example up to 20mbit download rate:
tc qdisc add dev ens3 root handle 1: htb default 1000
tc class add dev ens3 parent 1: classid 1:1 htb rate 20mbit
tc class add dev ens3 parent 1: classid 1:2 htb rate 20mbit
tc filter add dev ens3 protocol ip parent 1:0 prio 1 u32 match ip sport 64001 0xffff flowid 1:1
tc filter add dev ens3 protocol ip parent 1:0 prio 1 u32 match ip sport 64002 0xffff flowid 1:2
You can use these commands to limit the Inbound download speed.
But to limit the clients you need to use Ip instead of port. I used this code in Ikev2 protocol. But in x-ray Ip is dynamic and there is no tunnel interface.
iptables -I FORWARD -s $client1_IP -j MARK --set-mark 1
iptables -I FORWARD -d $client1_IP -j MARK --set-mark 1
tc qdisc add dev ens3 root handle 1: htb
tc class add dev ens3 parent 1:1 classid 1:100 htb rate 20mbit ceil 20mbit
tc qdisc add dev ens3 parent 1:100 sfq perturb 10
tc filter add dev ens3 protocol ip parent 1: prio 1 handle 1 fw flowid 1:100
iptables -I FORWARD -s $client2_IP -j MARK --set-mark 2
iptables -I FORWARD -d $client2_IP -j MARK --set-mark 2
tc class add dev ens3 parent 1:2 classid 1:200 htb rate 20mbit ceil 20mbit
tc qdisc add dev ens3 parent 1:200 sfq perturb 10
tc filter add dev ens3 protocol ip parent 1: prio 1 handle 2 fw flowid 1:200
@kalilovers commented on GitHub (Oct 9, 2023):
yeah i think this is necessary too
@yatakoi commented on GitHub (Oct 16, 2023):
Hello.
Could you please tell me how you configured static client ports?
My one client generates several random UDP ports at once:
I use VLESS and every time a client connects, a dynamic port is allocated for it.
@pro9793 commented on GitHub (Oct 16, 2023):
vless не пробовал,я на shadowsocks настроил - порты слушает те что в панели управления выставил - не рандомные, поэтому tc комманды работают для Inbound. для каждого клиента свой inbound со своим портом
@pro9793 commented on GitHub (Oct 16, 2023):
The best way to limit the speed is to add this code automatically on every change of the client IPs (don't look at for-do code and vars, just for example):
for $client$N_ip in $client$N_ips
do
iptables -I FORWARD -s $client$N_IP -j MARK --set-mark $N
iptables -I FORWARD -d $client$N_IP -j MARK --set-mark $N
done
tc qdisc add dev ens3 root handle 1: htb
tc class add dev ens3 parent 1:$N classid 1:$N00 htb rate 20mbit ceil 20mbit
tc qdisc add dev ens3 parent 1:$N00 sfq perturb 10
tc filter add dev ens3 protocol ip parent 1: prio 1 handle $N fw flowid 1:$N00
Also need to clear the old Ips first with iptables -D or rewrite them with new Ip.
@yatakoi commented on GitHub (Oct 17, 2023):
Спасибо, добрый человек )
@drno88 commented on GitHub (Oct 21, 2023):
personally, I just set up 3proxy and redirect the client to a local socks proxy, but it already limits the speed)
@limjianhui789 commented on GitHub (Dec 22, 2023):
Need this function too
@drno88 commented on GitHub (Dec 22, 2023):
Hello. Can you tell me how to call it? Or is it suggested to add this to the panel code?
@evilnero commented on GitHub (Apr 18, 2025):
FireQOS in Debian/others (part of firehol package) can limit total speed based on souce port, destinatin port...
It sets tc, qdisc, filters, htb and all things automatically. But can harm high-speed channels, and lower their speed in general. If you have 1+ gbit/s channell, using FireQOS will probably limit it, must check enabled/disabled.
For example, use this as fireqos config to set limit to 50 mbit/s:
(change 123.4.5.6 to real ip, as well as network interface and speed)
(docs: https://firehol.org/tutorial/fireqos-new-user/)
@myxeni64b commented on GitHub (Jun 8, 2026):
Try https://github.com/myxeni64b/xui-bw-guard (https://github.com/myxeni64b/xui-bw-guard)