Community discussions

MikroTik App
 
davids356
newbie
Topic Author
Posts: 25
Joined: Fri Jul 01, 2022 10:37 pm

Help adding option3 to static lease via command line

Fri Jul 01, 2022 10:41 pm

I have set up the mikrotik router, added a DHCP server and it is all working fine. However, I have now added option3 to the DHCP server options for providing an alternative gateway.
I can add this option3 to a static lease in order to modify the gateway of that device - that works fine when i add it from the winbox interface.

However, I cant work out the command that I need to do this from command line.
This is what I am trying but it does not work, can someone help?

/ip dhcp-server network set 31 dhcp-option=option3

(Where 31 is the ID of the lease that I want to modify). When I run this command it says "no such item".
 
User avatar
rextended
Forum Guru
Forum Guru
Posts: 11982
Joined: Tue Feb 25, 2014 12:49 pm
Location: Italy
Contact:

Re: Help adding option3 to static lease via command line  [SOLVED]

Fri Jul 01, 2022 10:58 pm

on /ip dhcp-server network, as you write, the leases do not exist, so if 31 is the id of the lease, is useless....

you can find the leases inside....
/ip dhcp-server lease

and this syntax is better....
/ip dhcp-server lease set [find where mac-address=AA:BB:CC:DD:EE:FF] dhcp-option=option3
(if option3 exist inside /ip dhcp-server option)
 
davids356
newbie
Topic Author
Posts: 25
Joined: Fri Jul 01, 2022 10:37 pm

Re: Help adding option3 to static lease via command line

Fri Jul 01, 2022 11:25 pm

thats great thanks so much! It worked :-)

I dont know if its the best way to do it, but I have two gateways on my network (one for BT and one for Virgin) so I configured the mikrotik as effectively a DHCP and DNS server, then set BT router as primary gateway and Virgin router as secondary gateway, then created a BAT script that uses Putty to issue command to Mikrotik to either add the option3 to a particular device, or to remove and re-add the lease without option3, thereby switching any particular client from BT to Virgin or vice-versa.
 
User avatar
rextended
Forum Guru
Forum Guru
Posts: 11982
Joined: Tue Feb 25, 2014 12:49 pm
Location: Italy
Contact:

Re: Help adding option3 to static lease via command line

Sat Jul 02, 2022 12:10 am

use 3 pool and 3 network
1st pool, not really existant of IP that must use gateway a
2nd pool, not really existant of IP that must use gateway b
3rd pool really existant for dynamic lease that use preferred gateway (can be only a or only b)
 
User avatar
rextended
Forum Guru
Forum Guru
Posts: 11982
Joined: Tue Feb 25, 2014 12:49 pm
Location: Italy
Contact:

Re: Help adding option3 to static lease via command line

Sat Jul 02, 2022 12:18 am

On this example:
BT Gateway = 10.0.0.1
Virgin Gateway = 10.0.0.2
/ip dhcp-server
add address-pool=pool-example-c-dynamic-by-bt disabled=no interface=bri-lan name=dhcp-example

/ip pool
add name=pool-example-a-static-by-bt ranges=10.0.0.3-10.0.0.62
add name=pool-example-b-static-by-virgin ranges=10.0.0.65-10.0.0.126
add name=pool-example-c-dynamic-by-bt ranges=10.0.0.129-10.0.0.254

/ip dhcp-server network
add address=10.0.0.0/26 gateway=10.0.0.1 netmask=24
add address=10.0.0.64/26 gateway=10.0.0.2 netmask=24
add address=10.0.0.128/25 gateway=10.0.0.1 netmask=24
 
davids356
newbie
Topic Author
Posts: 25
Joined: Fri Jul 01, 2022 10:37 pm

Re: Help adding option3 to static lease via command line

Sat Jul 02, 2022 12:59 am

Thanks. So then how would I make clients use specific pools?

Ideally I want majority of clients to use a single gateway (BT), but a couple of clients (my office computers) I want them to be able to easily switch between networks (basically because on Virgin I have 1GB connection so it’s great for downloading large files, but it’s not as stable as BT for general use).

So could I configure clients to use one of those pools by default and then have some form of command to switch a client from one pool to another?

(At the moment I just have a BAT file that connects and sends commands via putty, to the MikroTik, so as long as I have a command or commands to switch network, then I can make that as easy as running the bat file).

I do have that working now with the current method of changing the dhcp options, but if the way you suggested is more logical then I will do that way.
 
User avatar
rextended
Forum Guru
Forum Guru
Posts: 11982
Joined: Tue Feb 25, 2014 12:49 pm
Location: Italy
Contact:

Re: Help adding option3 to static lease via command line

Sat Jul 02, 2022 1:01 am

you must assign static IP leases to the devices (what you already do) and change simply the IP,
and on next renewal change automatically ip and gateway (for conntrack is better than change gateway oinly...)
OR set a static IP directly on the machine ;)
 
davids356
newbie
Topic Author
Posts: 25
Joined: Fri Jul 01, 2022 10:37 pm

Re: Help adding option3 to static lease via command line

Sat Jul 02, 2022 1:02 am

Ah right now I understand :-)
 
User avatar
rextended
Forum Guru
Forum Guru
Posts: 11982
Joined: Tue Feb 25, 2014 12:49 pm
Location: Italy
Contact:

Re: Help adding option3 to static lease via command line

Sat Jul 02, 2022 1:04 am

You do not let me finish to write :lol:
 
davids356
newbie
Topic Author
Posts: 25
Joined: Fri Jul 01, 2022 10:37 pm

Re: Help adding option3 to static lease via command line

Sat Jul 02, 2022 1:08 am

Oh right, I get it; so I set the assignment as static on the router, then I can simply run command to change the ip, and dependant upon what pool the ip is in, will dictate what gateway is used?

But the only issue; doing it this way, is there a way that most clients can just pick up a dynamic ip (if they don’t need to change between gateways) or do all ips have to be statically assigned?
 
User avatar
rextended
Forum Guru
Forum Guru
Posts: 11982
Joined: Tue Feb 25, 2014 12:49 pm
Location: Italy
Contact:

Re: Help adding option3 to static lease via command line

Sat Jul 02, 2022 1:15 am

on the example: pool-example-c-dynamic-by-bt

1/4 of /24 are for static leases with "forced" BT

1/4 of /24 are for static leases with "forced" Viacom

and the 1/2 are for dynamic leases with BT gateway
(and if you change mind to use Viacom, you need only to set ip on dhcp-server network accordingly,
and gradually when dynamic devices renew, also changing gateway)
 
davids356
newbie
Topic Author
Posts: 25
Joined: Fri Jul 01, 2022 10:37 pm

Re: Help adding option3 to static lease via command line

Sat Jul 02, 2022 1:53 am

Right I see. Thanks I will try this tomorrow.

Funny thing is; this router was for a client originally but it’s so flexible I’ve decided to keep it for myself, just ordred another one for the client :-)
 
User avatar
rextended
Forum Guru
Forum Guru
Posts: 11982
Joined: Tue Feb 25, 2014 12:49 pm
Location: Italy
Contact:

Re: Help adding option3 to static lease via command line

Sat Jul 02, 2022 2:00 am

ehhh... RouterOS....

Who is online

Users browsing this forum: Bing [Bot], gigabyte091 and 14 guests