Set up Wake On LAN (WOL) on a Debian Server

We have a non-mission critical backup server which is hosting our nightly copies of MySQL databases from other servers.

The working principle is as below:

  1. At 2AM, server “A” creates a database backup and copies it on to external HDD.
  2. Server “A” then connects to the backup server and uploads a database copy there.
  3. Server “A” and the backup server are on the same LAN.

So, the backup server doesn’t need to be online 24/7, but on-demand instead. It would be sensible to have the server sleeping and wake up only when needed to transfer backups. This can be done by using wake on LAN messages.


We will be configuring WOL on a Debian server. Update packages list and install ethtool:

# apt-get update && apt-get install ethtool

Configure WOL

We already have WOL enabled on BIOS, and need to check for the type of WOL our Ethernet card supports:

# ethtool eth0
Settings for eth0:
	Supported ports: [ TP ] 
	Supported link modes:   10baseT/Half 10baseT/Full 
	                        100baseT/Half 100baseT/Full 
	                        1000baseT/Half 1000baseT/Full 
	Supports auto-negotiation: Yes
	Advertised link modes:  10baseT/Half 10baseT/Full 
	                        100baseT/Half 100baseT/Full 
	                        1000baseT/Half 1000baseT/Full 
	Advertised pause frame use: No
	Advertised auto-negotiation: Yes
	Speed: 100Mb/s
	Duplex: Full
	Port: Twisted Pair
	Transceiver: internal
	Auto-negotiation: on
	MDI-X: Unknown
	Supports Wake-on: g
	Wake-on: d
	Current message level: 0x000000ff (255)
	Link detected: yes

As we may see above, Ethernet card supports Wake-on: g. Following the man page:

# man ethtool
wol p|u|m|b|a|g|s|d...
 Sets Wake-on-LAN options. Not all devices support this. The
 argument to this option is a string of characters specifying
 which options to enable.
p Wake on PHY activity
u Wake on unicast messages
m Wake on multicast messages
b Wake on broadcast messages
a Wake on ARP
g Wake on MagicPacket™
s Enable SecureOn™ password for MagicPacket™
d Disable (wake on nothing). This option clears all previous options.

So, we can wake our server up by using a so-called magic packet. Let us set the option on a network driver to respond to magic packets:

# ethtool -s eth0 wol g

To make this procedure automated and avoid typing the same command again after the server is restarted, we need to open the network config file /etc/network/interfaces for editing and add the following line (in brown) to our existing network configuration:

auto eth0
iface eth0 inet static
 /sbin/ethtool -s eth0 wol g

Ensure that WOL is enabled:

# ethtool eth0 | grep Wake-on
 Supports Wake-on: g
 Wake-on: g

We now have to find the MAC address of the NIC as it will be required to wake up the backup server. MAC can be retrieved from /sys/class:

# cat /sys/class/net/eth0/address 

Server can be sent to sleep via the pm-suspend command. It’s necessary to have the pm-utils package installed.

Send a Magic Packet

We will send a magic packet (from the server “A”) by using the wakeonlan utility. Install:

# apt-get install wakeonlan

Wakeonlan uses UDP packets and takes NIC MAC address as an argument:

$ wakeonlan 00:21:00:00:00:00
Sending magic packet to with 00:21:00:00:00:00

That’s it. If you have some strict firewall rules for outgoing traffic, makes sure these allow broadcast to leave:

# iptables -A OUTPUT -p udp -d -j ACCEPT

Note to myself. Send WOL from Mikrotik router:

[admin@mikrotik] > tool wol mac=00:21:00:00:00:00 interface=lan-bridge

7 thoughts on “Set up Wake On LAN (WOL) on a Debian Server

  1. This is great! Only thing I needed to do differently to get this to work was to make a small change to the line added in the interfaces file:
    post-up /sbin/ethtool -s eth0 wol g

    Note the addition of ‘post-up’ to the line

Leave a Reply

Your email address will not be published. Required fields are marked *