Community discussions

MikroTik App
 
Corbie
just joined
Topic Author
Posts: 20
Joined: Thu Apr 01, 2021 12:37 pm

Limit bandwith per ip in vlan

Fri Aug 27, 2021 12:42 pm

Hi,

Need to limit internet speed per ip in vlan.

Using simple queue for that. It only works to limit internet speed for whole vlan. But not specific IP in that vlan.
[admin@MKTK-RYBNA] /queue simple> print
Flags: X - disabled, I - invalid, D - dynamic 
 0    name="internet_limit" target=10.0.0.0/24 parent=none packet-marks="" priority=8/8 queue=default-small/default-small limit-at=0/0 
      max-limit=10M/10M burst-limit=0/0 burst-threshold=0/0 burst-time=0s/0s bucket-size=0.1/0.1 

 1    name="internet_exception_target" target=10.0.0.151/32 parent=none packet-marks="" priority=8/8 queue=default-small/default-small limit-at=0/0 max-limit=0/0 burst-limit=0/0 
      burst-threshold=0/0 burst-time=0s/0s bucket-size=0.1/0.1 
[admin@MKTK-RYBNA] /queue simple> add name=limit_target target=10.0.0.151/24 max-limit=0/0
invalid value for argument target:
    input does not match any value of target-interface
    invalid value for argument target-address:
        value of ip-address must have all host bits zero, as in 10.0.0.0/24
        value of ipv6-address must have IPv6 address before '/'

It only let me add IP address with /32 CIDR, but when i add ip address with /24 address i get the error above.

PS: fasttrack rule is disabled.
 
sindy
Forum Guru
Forum Guru
Posts: 10206
Joined: Mon Dec 04, 2017 9:19 pm

Re: Limit bandwith per ip in vlan

Fri Aug 27, 2021 2:44 pm

Several points.

First, the error message itself tells you what is wrong. The target is a prefix (subnet), so .151/32 is OK but .151/24 is not because non-zero bits of the address exist on the bit positions that are zero in the mask. The only place where you can use the shortcut form of .151/24 is when you define the IP address together with the subnet this way; everywhere else (item of an address-list, dst-address of a route, target of /queue simple item, ...) the address bits must be zero where the mask bits are zero.

Second, there are two basic categories of queues - the pcq ones and the rest, which is the "normal" ones. The "normal" ones have no embedded intelligence, so they handle all the traffic of the target equally. The pcq ones behave as autonomous queue trees - they autonomously sub-classify the traffic they get and they apply the limitations to each class separately. You can define which properties of a stream (connection) will be taken into account. Any combination of source address, destination address, source port, destination port can be used for that.

So to reach your goal of giving each tenant some guaranteed bandwidth and possibly also some bonus bandwidth they can use while others aren't maxing out their guaranteed quotas, you have two options:
  • to configure a dedicated simple queue for each tenant, setting its target to the individual IP address of the tenant
  • to configure a single pcq-type simple queue for all of them, setting its target to the whole subnet (10.0.0.0/24 in your case) and setting its pcq-classifier to dst-address for the download queue and to src-address for the upload queue.
The first approach is more complex, the second one may be too limiting when you want to give different bandwidth limits to different tenants. But you can combine the approaches as the rules in /queue simple (and in /queue tree as well) are evaluated top to botom until first match, like firewall rules. So if there are some small businesses among the tenants, you assign them e.g. addresses from 10.0.0.0/28, put the queue rules for them higher in the list, with this more specific prefix (10.0.0.0/28) in target, and then place the single queue rule for "the rest", with target=10.0.0.0/24.

See https://wiki.mikrotik.com/wiki/Manual:Q ... Q_Examples for more details.

Third, I suppose each tenant will get just a single IP address from you and you expect them to NAT their home network to it. So you probably want to make sure that they don't connect a switch and use multiple addresses from 10.0.0.0/24 to overcome the bandwidth limitations, which is complicated unless the switch they are connected to is a managed one and you can somehow enforce a single MAC per port on it. But if the router doing the NAT is provided by you, you can restrict the service only to known MAC addresses. Tenants who wish to use their own routers will have to tell you the MAC address of its WAN interface so that you could allow it.

Outside the bandwidth shaping topic:
  • it is a recommended security measure to prevent direct L2 forwarding between tenants, because if one of them has some malware on their gear, it cannot spread to the other ones (unless it manages to infect your own gear of course, so make sure your firewall prevents tenants from managing any of your own gear). This is called port isolation and it also requires a manageable switch supporting such function.
  • unless you get an IP address from 100.64.0.0/10 from the upstream ISP, it is recommendable to use this range for the tenants. The thing is that this range is not in conflict with any private IP range the tenants may choose for their LAN, nor it is a public range so they won't ever need to connect to anything in that range
 
Corbie
just joined
Topic Author
Posts: 20
Joined: Thu Apr 01, 2021 12:37 pm

Re: Limit bandwith per ip in vlan

Fri Aug 27, 2021 3:13 pm

@sindy

I would be glad just for simplest solution. Its not big complicated network. Just building with few apartments.
They get address from DHCP pool in vlan with MAC binding on their router WAN port.

I need to give different tenants different speed, thats why i tried to do simple dedicated queue. But for example one of ip adress which tenant can get is the "10.0.0.151",10.0.0.50", etc. doesnt matter just address from 10.0.0.0./24
And when i use this addresses as target it automatically assign /32 CIDR and the limitation doesnt work.

Tenants are on their own vlan where is just internet access.
 
sindy
Forum Guru
Forum Guru
Posts: 10206
Joined: Mon Dec 04, 2017 9:19 pm

Re: Limit bandwith per ip in vlan

Fri Aug 27, 2021 3:39 pm

I'm lost. If you need to get different speeds to different tenants, then the target for each tenant's individual queue must be that tenant's /32 address, so there is no point in using 10.0.0.0/24 as target, except maybe for the last rule in the list, defining a common queue for everyone who hasn't got their own dedicated rule.

In your /queue simple print, the topmost queue rule matches on target=10.0.0.0/24, so it catches all the traffic to/from any address in that VLAN subnet, and the packets to/from 10.0.0.151/32 never reach the second rule.

Besides, there is some undocumented optimisation - if you set both limit-at and max-limit to 0/0, the whole rule is ignored no matter what the target is.

So move the rule for 10.0.0.151/32 before the first one, and set some unreasonably high max-limit (like 10G/10G) if you want that single IP to have unrestricted speeds and all the other addresses in 10.0.0.0/24 to share a common max-limit of 10M/10M.
 
Corbie
just joined
Topic Author
Posts: 20
Joined: Thu Apr 01, 2021 12:37 pm

Re: Limit bandwith per ip in vlan

Mon Aug 30, 2021 4:33 pm

@sindy

So basically when i do just this rule:
Flags: X - disabled, I - invalid, D - dynamic 
 0    name="APT1" target=10.0.0.151/32 parent=none packet-marks="" priority=8/8 queue=ethernet-default/ethernet-default limit-at=0/0 max-limit=20M/20M 
      burst-limit=20M/20M burst-threshold=10M/10M burst-time=5s/5s bucket-size=0.1/0.1 
[admin@MKTK-RYBNA] /queue simple> 
its gonna limit the speed on 0.151/32 and the rest of the network is gonna be unlimited i quesss? Cause its not working, when i connect my PC to that vlan and i get this ip address on the computer on speedtest i still measure around 150mb, which is full speed from ISP
 
User avatar
anav
Forum Guru
Forum Guru
Posts: 19371
Joined: Sun Feb 18, 2018 11:28 pm
Location: Nova Scotia, Canada
Contact:

Re: Limit bandwith per ip in vlan

Mon Aug 30, 2021 4:51 pm

See basic queues as part of this overall presentation.
https://mum.mikrotik.com/presentations/ ... 712741.pdf

More indepth on Users and Services
http://mum.mikrotik.com/presentations/T ... 619134.pdf

Fun video........
https://www.youtube.com/watch?v=Ro3B1kQUokE
 
sindy
Forum Guru
Forum Guru
Posts: 10206
Joined: Mon Dec 04, 2017 9:19 pm

Re: Limit bandwith per ip in vlan

Mon Aug 30, 2021 5:05 pm

Yes, the guess/expectation is correct. Since it doesn't work as expected, please do the following:
  1. /queue simple reset-counters-all
  2. run the speedtest from .151
  3. /queue simple print stats
What's the output of the last command?
 
Corbie
just joined
Topic Author
Posts: 20
Joined: Thu Apr 01, 2021 12:37 pm

Re: Limit bandwith per ip in vlan

Mon Aug 30, 2021 5:24 pm

@sindy

Oh sry i had fasttrack rule enabled back for some reason. Its working now.
 
User avatar
anav
Forum Guru
Forum Guru
Posts: 19371
Joined: Sun Feb 18, 2018 11:28 pm
Location: Nova Scotia, Canada
Contact:

Re: Limit bandwith per ip in vlan

Mon Aug 30, 2021 5:27 pm

Another example where
/export hide-sensitive file=anynameyouwish is the quickest way to resolve most issues.
Posters only put where they think the problem is,,,,,, and thats a problem unto itself

Who is online

Users browsing this forum: Google [Bot] and 180 guests