Monthly Archives: July 2017

How to create a swap file on Ubuntu

Swap is particularly useful in situations where physical memory is limited, especially when dealing with low memory VPS/systems. This does not mean that swap is useless in all the other situations. Any system with close to 100% RAM utilization without swap enabled will cause application crashes or even worse, a system crash.

Moreover, some applications, in rare cases, require swap to be enabled regardless of memory capacity/usage, otherwise they simply crash.

To enable swap on Ubuntu follow the steps below (requires administration rights):

Create an empty file called “swapfile” using fallocate:

Feel free to change the “1G” value if you believe you require more or less swap space.

Change the permissions of the swap file to 600 in order to make it accessible only for the root user:

Mark the “swapfile” as swap space:

Enable the swap file:

Note: It is extremely important to note that any changes we have made so far are temporary and will be removed when we reboot the machine.

In order to make our changes permanent we will need to update the fstab file located at /etc/fstab. You can do so by editing the file and adding the following line inside:

Or simply by using this command do insert the line for you in the file:

We put together a one line command using the instructions above. It comes in handy when deploying new machines and we want to speed up the process. Feel free to use and modify it to suit your needs.

Wake-on-Lan (WoL) in C#

Wake on LAN is a computer networking standard that allows devices to be powered on when they receive a specific network message, if your device supports this feature.

In this example we will demonstrate how to craft this “magic” packet in C#. The concept of the packet is fairly simple. The packet must contain anywhere in the payload six (6) 255 bytes in a row (FF in hexadecimal) followed by the MAC address of the device repeated sixteen times.

As an example, if your device MAC address is 01-00-00-00-00-02 the payload will look like this:

You can find the implementation of WoL in C# below:

And the result…
Wireshark WoL Result

Feel free to leave your questions or feedback in the comment section below.