Community discussions

MikroTik App
 
nuttdam
just joined
Topic Author
Posts: 4
Joined: Mon Mar 14, 2022 1:33 pm

How to WoL to different VLAN devices?

Mon Mar 14, 2022 1:38 pm

I have multiple VLAN which I need a device on VLAN 20 (Home Assistant) to WoL a PC on VLAN 10. Previously, before I switch to use MikroTik, both are on the same LAN and it can wake my PC.

I have try to figure this out by add ARP table a ip address with MAC FF:FF:FF:FF:FF:FF and create drc-nat firewall with UDP protocol, dest-port=9, action=drcnat, to-address <ip address from ARP>. Afterthat, I try to send a magic package from Home Assistant, the package counter in Firewall has been increased but my PC does not wake up.

Anything that I missed?
Thank you so much,
 
Zacharias
Forum Guru
Forum Guru
Posts: 3459
Joined: Tue Dec 12, 2017 12:58 am
Location: Greece

Re: How to WoL to different VLAN devices?

Mon Mar 14, 2022 4:56 pm

MikroTIK itself has WoL implemented, you will find it under /tool/wol

Devices to be waked through a WoL packet ( magic packet ) must be in the same Broadcast domain. Since you use VLANs, those broadcast domains are seperated...
I don't know if there is a workaround on this...

But you can try if you can wake the device through the MikroTIK...
 
pe1chl
Forum Guru
Forum Guru
Posts: 10248
Joined: Mon Jun 08, 2015 12:09 pm

Re: How to WoL to different VLAN devices?

Mon Mar 14, 2022 5:01 pm

You can also send the WoL packet to the subnet broadcast address instead of to the global broadcast address.
That is the last address in the subnet. This should be different for each VLAN.
 
User avatar
k6ccc
Forum Guru
Forum Guru
Posts: 1500
Joined: Fri May 13, 2016 12:01 am
Location: Glendora, CA, USA (near Los Angeles)
Contact:

Re: How to WoL to different VLAN devices?

Mon Mar 14, 2022 7:19 pm

I use the built Mikrotik ROS Wake on LAN feature from time to time - mostly from a script (that way you don't remember MAC addresses). Works quite well. I can even trigger the script via port knock sequence from the internet. Use that to turn on the primary desktop at home. Then I can use TeamViewer to access that after it starts up.

Correct, that the WoL has to be from the same Broadcast Domain, and your different VLANs are different Broadcast Domains. Fortunately, in most cases, the router has access to all the VLANs.
 
nuttdam
just joined
Topic Author
Posts: 4
Joined: Mon Mar 14, 2022 1:33 pm

Re: How to WoL to different VLAN devices?

Mon Mar 14, 2022 9:30 pm

You can also send the WoL packet to the subnet broadcast address instead of to the global broadcast address.
That is the last address in the subnet. This should be different for each VLAN.
Could you explain more about sending packet to broadcast address? I am confused that how to do that with simple wol and how to specify MAC address while send packet to a broadcast address
 
nuttdam
just joined
Topic Author
Posts: 4
Joined: Mon Mar 14, 2022 1:33 pm

Re: How to WoL to different VLAN devices?

Mon Mar 14, 2022 9:32 pm

I use the built Mikrotik ROS Wake on LAN feature from time to time - mostly from a script (that way you don't remember MAC addresses). Works quite well. I can even trigger the script via port knock sequence from the internet. Use that to turn on the primary desktop at home. Then I can use TeamViewer to access that after it starts up.

Correct, that the WoL has to be from the same Broadcast Domain, and your different VLANs are different Broadcast Domains. Fortunately, in most cases, the router has access to all the VLANs.
I am thinking about triggering script to run on mikrotik to send wol packet. But I donot know how, could you explain more about triggering script from a device, in my case, homeassistant.
 
User avatar
k6ccc
Forum Guru
Forum Guru
Posts: 1500
Joined: Fri May 13, 2016 12:01 am
Location: Glendora, CA, USA (near Los Angeles)
Contact:

Re: How to WoL to different VLAN devices?

Tue Mar 15, 2022 5:18 am

As to how to do this from your home assistant, I have no good idea. This is what I did to allow remote booting a PC via a WoL packet from the router.

This is a modification of a script that I got years ago here on the forum that would search the router log on a schedule looking for login and logout attempts.

For this script I modified it so that it was looking for the string "PC boot Port Knock Family room" in the log. When it finds it, ultimately it executes the code in the about the last dozen lines that sends a WoL packet three times - 10 seconds apart. It also sends me an E-Mail to tell me that it executed.

Now your next question is how does the string "PC boot Port Knock Family room" get into the router log?

I have a four step port knock process. This last step adds the source address to an address list, but that really doesn't accomplish anything. However, it writes a log entry - and that does.
add action=add-src-to-address-list address-list="PCB Knock-4" \
    address-list-timeout=1s chain=PC-Boot comment=\
    "PC boot Port Knock Family room" dst-port=12345 in-interface-list=WAN log=\
    yes log-prefix="PC boot Port Knock Family room" protocol=tcp \
    src-address-list="PCB Knock-3"

Now that there is the required log entry, here is the script that parses the log and runs the WoL Please don't ask me details on how this script works as I largely can't tell you. I could figure out to modify the script for my own purposes, but that is about it. There is a schedule that runs this script every minute.
# BEGIN SETUP
:local scheduleName "Family Rm PCB from Port Knock"
:local emailAddress1 "jim@xxx.com"
:local emailAddress2 "jim@yyy.org"
:local startBuf [:toarray [/log find message~"PC boot Port Knock Family room"]]
:local removeThese {"zippo";"whatever string you want"}
# END SETUP

# warn if schedule does not exist
:if ([:len [/system scheduler find name="$scheduleName"]] = 0) do={
  /log warning "[LOGMON] ERROR: Schedule does not exist. Create schedule and edit script to match name"
}

# get last time
:local lastTime [/system scheduler get [find name="$scheduleName"] comment]
# for checking time of each log entry
:local currentTime
# log message
:local message
 

# final output
:local output

:local keepOutput false
# if lastTime is empty, set keepOutput to true
:if ([:len $lastTime] = 0) do={
  :set keepOutput true
}


:local counter 0
# loop through all log entries that have been found
:foreach i in=$startBuf do={
 

# loop through all removeThese array items
  :local keepLog true
  :foreach j in=$removeThese do={
#   if this log entry contains any of them, it will be ignored
    :if ([/log get $i message] ~ "$j") do={
      :set keepLog false
    }
  }
  :if ($keepLog = true) do={
   
   :set message [/log get $i message]

#   LOG DATE
#   depending on log date/time, the format may be different. 3 known formats
#   format of jan/01/2002 00:00:00 which shows up at unknown date/time. Using as default
    :set currentTime [ /log get $i time ]
#   format of 00:00:00 which shows up on current day's logs
   :if ([:len $currentTime] = 8 ) do={
     :set currentTime ([:pick [/system clock get date] 0 11]." ".$currentTime)
    } else={
#     format of jan/01 00:00:00 which shows up on previous day's logs
     :if ([:len $currentTime] = 15 ) do={
        :set currentTime ([:pick $currentTime 0 6]."/".[:pick [/system clock get date] 7 11]." ".[:pick $currentTime 7 15])
      }
   }
    

#   if keepOutput is true, add this log entry to output
   :if ($keepOutput = true) do={
     :set output ($output.$currentTime."  ".$message."\r\n\n")
   }
#   if currentTime = lastTime, set keepOutput so any further logs found will be added to output
#   reset output in the case we have multiple identical date/time entries in a row as the last matching logs
#   otherwise, it would stop at the first found matching log, thus all following logs would be output
    :if ($currentTime = $lastTime) do={
     :set keepOutput true
     :set output ""
   }
  }

#   if this is last log entry
  :if ($counter = ([:len $startBuf]-1)) do={
#   If keepOutput is still false after loop, this means lastTime has a value, but a matching currentTime was never found.
#   This can happen if 1) The router was rebooted and matching logs stored in memory were wiped, or 2) An item is added
#   to the removeThese array that then ignores the last log that determined the lastTime variable.
#   This resets the comment to nothing. The next run will be like the first time, and you will get all matching logs
   :if ($keepOutput = false) do={
#     if previous log was found, this will be our new lastTime entry      
     :if ([:len $message] > 0) do={
        :set output ($output.$currentTime." ".$message."\r\n")
      }
    }
  }
  :set counter ($counter + 1)
}


# If we have output, save new date/time, and send email
if ([:len $output] > 0) do={
  /log err "[LOGMON] Family room PC WoL from Port Knock."
  /system scheduler set [find name="$scheduleName"] comment=$currentTime
  :log info "Sending WoL Magic Packet to Family room 2018 PC"
  /tool wol interface=E06-p10_201 mac=11:22:33:44:55:66
  :delay 00:00:10
  /tool wol interface=E06-p10_201 mac=11:22:33:44:55:66
  :delay 00:00:10
  /tool wol interface=E06-p10_201 mac=11:22:33:44:55:66
  :log info "WoL script completed"
}

Now, it I am already into the router (normally that would be via WinBox), there is a MUCH shorter script that I can call to issue the WoL packets
# Policy needed:  Test
:log info "Sending WoL Magic Packet to Family room 2018 PC"
/tool wol interface=E2-p4_101 mac=11:22:33:44:55:66
:delay 00:00:10
/tool wol interface=E2-p4_101 mac=11:22:33:44:55:66
:delay 00:00:10
/tool wol interface=E2-p4_101 mac=11:22:33:44:55:66
:log info "WoL script completed"

FYI, I have several of these so I can remote boot several computers at the house.
 
cpeshalelimpix
just joined
Posts: 1
Joined: Mon Dec 18, 2023 6:06 am

Re: How to WoL to different VLAN devices?

Sat Mar 09, 2024 9:56 am

I struggled getting this to work, hopefully this helps somebody else out.

I followed the advice in this thread to get it to work but was a little confused: https://www.reddit.com/r/mikrotik/comme ... _solution/

Step .1 - Ensure that your WoL works (I had to enable mine in the bios) by going to the Mikrotik gui and selecting tools > WoL, select the VLAN that the device you want to wake up is on and input the MAC address and confirm that the router is able to turn your device on.

For this example let's assume that your Home Assistant IP address is 192.168.0.1/24 and the device that you want to wake up is 172.16.0.1/24

1. You need to make a static ARP entry on the Mikrotik, (go to IP > ARP in the gui) go to Add New and you are going to select an avaialble IP address on your device subnet so let's use 172.16.0.254 and for the MAC address use FF:FF:FF:FF:FF:FF and assign the interface to your VLAN / subnet interface. Ensure Enabled is checked and Published is unchecked

2. Ensure that that traffic is able to flow from 192.168.0.1 to 172.16.0.1 for destination port 9 type UDP in the firewall

3. In Home Assistant add the line "wake_on_lan:" without quotes to your configuration.yaml and then reboot Home Assistant (Developer Tools > Restart > Restart Home Assistant)

4. Go to Settings > Devices & Services > Helpers (tab at top) > Create Helper > Button and then give it a name (Wake up Computer) and Icon

5. Create a new automation (Settings > Automamtions > Create Automation. For the Trigger select device state and then select your new button. For action select 'Call Service' and for the service select Wake on LAN: Send Magic Packet. Input your device's MAC and for broadcast address use 172.16.0.254 and then test


This worked for me and I did not need to create a dstnat rule, good luck!

Who is online

Users browsing this forum: Bing [Bot], Pilo2710, ringrring and 16 guests