How to use the command 'wakeonlan' (with examples)
The wakeonlan
command is a utility used to send special network packets, known as “magic packets,” to remotely wake up computers that are equipped with a Wake-on-LAN (WOL) feature. This capability is particularly useful for network administrators and users who wish to control a network of computers without needing physical access. Instead of manually switching on a computer or relying on a scheduled power-up, wakeonlan
enables users to power up devices on demand, thereby enhancing efficiency and flexibility in managing network resources.
Send packets to all devices on the local network with a specified MAC address
Code:
wakeonlan 01:02:03:04:05:06
Motivation:
This command is perfect when a user desires to wake up all devices on the local network using their MAC address. It is particularly useful in settings where a simple and broad approach is needed, such as ensuring all computers on a network are powered on at the beginning of a workday, or in scenarios where machines are used intermittently and need to be ready for spontaneous access.
Explanation:
wakeonlan
: This part of the command is calling the utility to initiate the sending of “magic packets.”01:02:03:04:05:06
: This is the MAC address, a unique identifier assigned to each network interface. The command uses it to direct the magic packet to the precise network interface or device intended to be awakened.
Example Output:
Sending magic packet to 01:02:03:04:05:06 with broadcast 255.255.255.255
Send packet to a specific device via IP address
Code:
wakeonlan 01:02:03:04:05:06 -i 192.168.178.2
Motivation:
Using this command is crucial for targeting a specific device in a network, especially in larger networks where broadcasting to all devices is not efficient or desirable. It is extremely useful for focused tasks such as waking up a specific server that needs to remain offline to save power unless actively being used, or remotely powering up a desktop computer in an office setting for specific tasks like backups or updates.
Explanation:
wakeonlan
: Again, this initiates the use of the WOL utility.01:02:03:04:05:06
: The MAC address is specified to identify the device that should be receiving the magic packet.-i 192.168.178.2
: The-i
option is used to define the specific IP address of the target device, allowing the packet to be sent directly to this address, ensuring only the intended device is awakened.
Example Output:
Sending magic packet to 01:02:03:04:05:06 (192.168.178.2)
Print the commands, but don’t execute them (dry-run)
Code:
wakeonlan -n 01:02:03:04:05:06
Motivation:
A dry run is exceptionally useful during setup or troubleshooting phases to verify the command syntax and intended device configuration without actually waking the devices. Users often prefer this approach to ensure accuracy and understand the command’s behavior before executing it, reducing the risk of unintentional network or device wake-up.
Explanation:
wakeonlan
: This is the command initializer.-n
: The dry-run option tells the command to “simulate” executing the command without sending actual packets.01:02:03:04:05:06
: Again, the MAC address is used to specify which devices are intended to be affected by the command.
Example Output:
Would send magic packet to 01:02:03:04:05:06
Run in quiet mode
Code:
wakeonlan -q 01:02:03:04:05:06
Motivation:
Quiet mode is suited for scripting environments or scenarios where the output noise should be minimal, such as when automating tasks or creating logs where only errors should be reported. This helps keep logs clean and concise, removing unnecessary output that can clutter command execution results.
Explanation:
wakeonlan
: The core command for sending magic packets.-q
: The quiet mode flag suppresses the usual output from the command, only showing results if there’s an error.01:02:03:04:05:06
: This is the device’s MAC address which the magic packet targets.
Example Output:
No output unless an error occurs.
Conclusion:
The wakeonlan
command offers a versatile set of tools for managing devices on a network remotely. Whether an administrator needs to wake all devices on a LAN, target a specific device through its IP address, verify command execution with a dry run, or integrate quietly into scripts, wakeonlan
provides efficient solutions for various network management tasks.