Reset RDP Sessions

When using Windows RDP you may encounter the error message ‘The terminal server has exceeded the maximum number of allowed connections’. You can delete open sessions or use the admin switch to administer the server.

At the command prompt:
To administer the server:

mstsc /v:<server> /admin

To obtain a list of current sessions:

query session /server:<server>

To close a session – [ID] can be found from session list

reset session [ID] /server:<server>

Add Google Analytics To A WordPress Site

Paste the following code into your functions.php file replacing the UA-xxxxxxxx-x code with your Google Analytics code.

function googleanalytics(){
<script type="text/javascript">

  var _gaq = _gaq || [];
  _gaq.push(['_setAccount', 'UA-xxxxxxxx-x']);

  (function() {
    var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
    ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '';
    var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);


add_action('wp_head', 'googleanalytics', 100);

Force Files To Download Instead Of Open In Web Browser

You can change the file directivies for a folder by adding a .htaccess file in the folder and including the following code:

<IfModule mod_headers.c>
<FilesMatch "\.(?i:mp3|ogg)$">
      ForceType application/octet-stream
      Header set Content-Disposition attachment

This will force .mp3 and .ogg files to prompt for action rather than open with the default browser setting. The IfModule condition is recommended as it will prevent an error message if the Apache headers module is not installed.

Prevent Access And Directory Listing To A Folder Using .htaccess

If someone browses to a folder on your website that does not have an index file it will, by default, list the directory’s contents. If you have an Apache based web server you can prevent access to this folder by placing a .htaccess file within it containing the following code:

Options -Indexes

This can also be placed at the root of your site as it will be inherited through the sub-directories. Using Options -Indexes does not prevent access to the folders from scripts running on your website so you can still, for example, list the contents with PHP and download the files.

IP Forwarding and Masquerading in Linux Using UFW

In this example we have 2 private subnets and where only addresses can directly access the router at We want to access the internet from both subnets.

We need a machine connected to both networks and allow IP forwarding from to Although probably better with 2 NICs it can be done usings network aliases using only 1 network interface.

Presuming you have a configured NIC with an address for eth0 on the range and on eth0:1 an address from we can start configuring the machine. This machine will act as the gateway for the range.

First check if packet forwarding is activated.
Step 1:
Check /etc/default/ufw and make sure DEFAULT_FORWARD_POLICY is set to ACCEPT.


Step 2:
Type the following to test for IP forwarding

cat /proc/sys/net/ipv4/ip_forward

If this returns 0 we need to turn it on. Edit /etc/ufw/sysctl.conf and uncomment


Now to configure IP masquerading, network address translation
Edit the file /etc/ufw/before.rules and add the following code to the top.


#Forward traffic from the alias range through eth0


To activate new firewall settings type

ufw disable
ufw enable

If ufw was not already enabled you may need to alter some rules as it may now be blocking some routes and ports. In this example we may need to add rules such as.

ufw allow from
ufw allow to
ufw allow from
ufw allow to

Tested with ubuntu server 11.10