Debian/Ubuntu Tips and Tricks


Debian/Ubuntu Tips and Tricks

Archive for the 'Networking' Category

How Tos related to networking from accessing remote hosts, configuring a service or administration.

How-To: Prevent SPAM with Apache’s mod security

Posted by chantra on 6th November 2014

WordPress is a great piece of software to run a blog, it is flexible, has tons of plugins are developed for it and updates are really easy to do. To fight spam comments, there is already the Akismet plugin that does a really good job.
While Akismet catches the spam comments and put them in a separate location, making it easy to delete them, as the number of spam grows, WordPress can take long to empty the purge the flush comments and the best option becomes to use a manual SQL query to flush them.
In this article, we will see how we can use RBL to prevent spammer from posting to WordPress's comment page and at the same time, lift a bit of load from the server.
While the rules work for WordPress, with a bit of modifications, it will be easy to get this setup working for any kind of blog/website.

Read the rest of this entry »

Tags: , ,
Posted in Administration, HowTo, HTTP, Networking, System | 1 Comment »

How-To: Fight SPAM with Postfix RBL

Posted by chantra on 26th September 2013

Spam, spam everywhere! If you are hosting your own mail server, fighting spam can become tricky. Antispam solutions do catch a fair amount of them, but still many spam email can still make their way through.

RBL (Real-time Blackhole) is a database of known spammy IPs which is accessible over DNS. Depending on the response received from the DNS server, the IP is classified as spammy or not.

This tutorial will show you how to set up RBL with postfix.

Read the rest of this entry »

Tags: , , ,
Posted in Administration, HowTo, Networking, System | 1 Comment »

How-To: WiFi roaming with wpa-supplicant

Posted by chantra on 18th June 2013

wpa_supplicant can be used as a roaming daemon so you can get your system to automatically connect to different network as you are going from one location to another.

This come in pretty handy on headless machines where you rely on network connection to be up in order to be able to access the machine.

Read the rest of this entry »

Tags: ,
Posted in Administration, HowTo, Networking | No Comments »

How-To: find which program consumes your bandwidth with nethogs

Posted by chantra on 29th March 2013

Let's continue the network monitoring serie with yet another use case.... the "What program is using my bandwidth?" problem while not imposible to solve, still remains a pain. What if there were some kind of top for network?

NetHogs is a nifty tool that will do that for you and will help you finding what is hogging your connection.

Read the rest of this entry »

Tags: , , ,
Posted in Administration, HowTo, Networking | No Comments »

How-To: monitor network bandwidth usage with vnstat

Posted by chantra on 11th March 2013

There is many tools out there that help in monitoring network usage, collect statistics and generate graphs so we can view what happened at a given date/time. Anyhow, finding the bandwidth usage over an hour/day/week/month can be really tricky.

vnstat is a suite of daemon and client programs that monitor network bandwidth usage.

Read the rest of this entry »

Tags: , , ,
Posted in Administration, HowTo, Networking | No Comments »

How-To: OpenVPN on Debian Squeeze with Username/Password authentication

Posted by chantra on 16th January 2013

Creating the configuration

Now that we have our certificates ready, we need to create a set of config for the server and the client.

Server side

On the server side, you will need to create the file /etc/openvpn/server.conf and edit it with:

dev tun
proto udp
port 1194
# since OpenVPN 2.1 we can use topology subnet
topology subnet
# if we want to change the temp directory location
; tmp-dir /dev/shm
# certs
ca keys/ca.crt
cert keys/server01.crt
key keys/server01.key
dh keys/dh1024.pem
tls-auth keys/ta.key 0
# Keepalive
# Ping every 10 seconds, assume that remote
# peer is down if no ping received during
# a 120 second time period.
keepalive 10 120
# Write operational status to this file
status openvpn-status.log
# Drop privileges
user nobody
group nogroup
# As we dropped privileges, make sure we dont
# close/reopen tun interface amd re-read key files
# accross SIGUSR1
# Our subnet
# Redirect all traffic to our OpenVPN server
push "redirect-gateway def1 bypass-dhcp"
# We want client to use our DNS server
push "dhcp-option DNS"
ifconfig-pool-persist ipp.txt
# If you want OpenVPN clients
# to be able to connect directly
# to each others
; client-to-client
# Use PAM authentication
plugin /usr/lib/openvpn/ login
# we dont want to use client certificate
# enable mgmt over telnet
management localhost 1194 mgmt-pw-file
verb 3

Then, we need to copy the certificates/keys in the keys directory of /etc/openvpn:

mkdir /etc/openvpn/keys
cp /etc/openvpn/easy-rsa/2.0/keys/{ca.crt,server01.crt,server01.key,dh1024.pem,ta.key} /etc/openvpn/keys/

And, in order to be able to manage openvpn from a telnet connection, we will create a file called /etc/openvpn/mgmt-pw-file with password "password":

echo password > /etc/openvpn/mgmt-pw-file
chmod 700 /etc/openvpn/mgmt-pw-file
chown root:root /etc/openvpn/mgmt-pw-file

Everything should be setup for the server side, now we need to edht /etc/default/openvpn to make sure that this configuration get started when using the init script. So, edit that file and make sure it contains:


O'rite, you can now restart openvpn service with:

# /etc/init.d/openvpn restart

Now, our server should be up and running. If anything went wrong, /var/log/daemon.log is the place to look into.

At this stage, you should also be able to connect to localhost on TCP port 1194 using telnet. You will be prompted for a password, this is the password you have set in /etc/openvpn/mgmt-pw-file.
Once you logged in, you will be able to access the management interface of openvn!

Enabling IP forwarding

As we will be routing packets, we need to enable IP forwarding. To do this create a file called /etc/sysctl.d/forwarding.conf which contains:


And apply the change with:

root@ovpnrouter:~# sysctl -p /etc/sysctl.d/forwarding.conf
net.ipv4.ip_forward = 1


At this stage, the openvpn server could handle clients, forward packets, but packets would be routed with their original private IP. To give proper network connectivity to our OpenVPN clients, we will need to NAT the traffic.
This can be done by using the following command:

root@ovpnrouter:~# iptables -t nat -I POSTROUTING -s -o eth0 -j MASQUERADE

Configuring Iptable is not in the scope of this article. You might want to refer to IPtables: how to share your internet connection.

Anyhow, let's move forward and set up a client!

Tags: , , , ,
Posted in Administration, HowTo, Networking, Softwares, System | No Comments »

How-To: Set up a L2TP over IPSec VPN using a Radius backend — page 3

Posted by chantra on 18th June 2010

This entry is part 3 of 3 in the series How-To: Set up a L2TP over IPSec VPN using a Radius backend

Using freeradius for authentication

Here I am going to consider that the freeradius server is set up correctly, meaning that you can already authenticate your users with freeradius using radtest utility.

In order to get ppp to use freeradius, we need to install libradius1:

# apt-get install libradius1

No we need to set up the server we use in /etc/radiusclient/servers. Here we use the default password on localhost:

localhost testing123

and finally, we tell ppp to use the radius plugin by adding at the end of /etc/xl2tpd/ppp-options.xl2tpd :


And that should be it!

Tags: , , , ,
Posted in Administration, HowTo, Networking, System | No Comments »

How-To: Set up a L2TP over IPSec VPN using a Radius backend — page 2

Posted by chantra on 18th June 2010

This entry is part 1 of 3 in the series How-To: Set up a L2TP over IPSec VPN using a Radius backend


Now, let's get on the next phase: XL2TP.

Packages Requirements

You can install xl2tp with the following command:

# apt-get install xl2tp


The configuration of xl2tp happens in /etc/xl2tpd/xl2tpd.conf. We are going to provide IPs in the range, being the endpoint IP of the VPN server.

So go ahead and open /etc/xl2tpd/xl2tpd.conf and make it look like:

ipsec saref = yes
listen-addr = your external IP address
port = 1701
[lns default]
ip range =
local ip =
refuse chap = yes
require pap = yes
require authentication = no
name = LinuxVPNserver
hostname = YourHostName
ppp debug = yes
length bit = yes
pppoptfile = /etc/xl2tpd/ppp-options.xl2tpd

Copy an example config from xl2tp doc:

sudo cp /usr/share/doc/xl2tpd/examples/ppp-options.xl2tpd /etc/xl2tpd/ppp-options.xl2tpd

Now go and edit etc/xl2tpd/ppp-options.xl2tpd and make it look like:

idle 1800
mtu 1200
mru 1200
connect-delay 5000

Same here, change it with whatever mstches your settings (DNS...)

Finally test your configuration with:

sudo xl2tpd -D

Tags: , , , ,
Posted in Administration, HowTo, Networking, System | 1 Comment »

How-To: Set up a L2TP over IPSec VPN using a Radius backend

Posted by chantra on 18th June 2010

This entry is part 1 of 3 in the series How-To: Set up a L2TP over IPSec VPN using a Radius backend

Even though I pretty like OpenVPN, there is still some devices that might not support the TUN/TAP driver needed by OpenVPN.

Take IPhones, Android phones for instance, you need to root them in order to get that feature, assuming somebody has already cooked a ROM for your device.

L2TP is quite and old standard that allow setting up VPNs.

On the other end, it does not provide any kind of encryption mechanism, and as such, it is pretty common to get L2TP running over an IPSec link.

In this tutorial, we are going to set up this kind of VPN. First IPSec will create an encrypted link, then L2TP will create a VPN link.

We are going to use a Pre-Shared Key (or PSK) for IPsec.

L2TP will use PAP as an authentication mechanism.
Why PAP? Because that allow us to store encrypted password instead of plain text one. Some might say that the password will go over the wire unencrypted, but here we have IPSec taking care of not letting our password be seeing by others.

This tutorial was done on Debian Lenny and Windows XP SP3 connected to the service successfully. Android 2.2 client also connected successfully.

Windows mobiles would fail to authenticated as PAP is not supported on the client :s !

So let get started with IPSec.


Packages requirements

We are going to use OpenSwan to handle IPSec. On Debian, you can install it with:

# apt-get install openswan

If you are asked questions, just answer the default.

IPSec Configuration

We are going to use the example from /etc/ipsec.d/examples/l2tp-psk.conf and copy the following below # Add connections here in /etc/ipsec.conf.

version 2.0     # conforms to second version of ipsec.conf specification
# basic configuration
config setup
        # plutodebug / klipsdebug = "all", "none" or a combation from below:
        # "raw crypt parsing emitting control klips pfkey natt x509 private"
        # eg: plutodebug="control parsing"
        # ONLY enable plutodebug=all or klipsdebug=all if you are a developer !!
        # NAT-TRAVERSAL support, see README.NAT-Traversal
        # If we consider that we have an internal interface on subnet,
        # we need to had here we had %v4:!
        # enable this if you see "failed to find any available worker"
# Add connections here
  # Configuration for one user with any type of IPsec/L2TP client
  # including the updated Windows 2000/XP (MS KB Q818043), but
  # excluding the non-updated Windows 2000/XP.
  # Use a Preshared Key. Disable Perfect Forward Secrecy.
  # PreSharedSecret needs to be specified in /etc/ipsec.secrets as
  # YourIPAddress  %any: "sharedsecret"
  # we cannot rekey for %any, let client rekey
  # or you can use: left=YourIPAddress
  # leftnexthop=YourGatewayIPAddress
  # For updated Windows 2000/XP clients,
  # to support old clients as well, use leftprotoport=17/%any
  # The remote user.
  # Using the magic port of "0" means "any one single port". This is
  # a work around required for Apple OSX clients that use a randomly
  # high port, but propose "0" instead of their port.
# sample VPN connections, see /etc/ipsec.d/examples/

Now we set our preshared key in /etc/ipsec.secrets with the format given in the configuration:

YourIPAddress  %any: PSK "sharedsecret"

And that should be it for the IPsec part. Now you can restart IPSec:

# /etc/init.d/ipsec restart

You might want to check the output of:

# ipsec auto --status

to troubleshoot potential issues.


If you have a firewall set up, you can use those settings to allow ipsec:

-A INPUT -i eth0 -p udp -m udp --dport 4500 -j ACCEPT
-A INPUT -i eth0 -p udp -m udp --dport 500 -j ACCEPT
-A INPUT -i eth0 -p esp -j ACCEPT

Well, assuming IPsec part is fine, let go to the xl2tp part now.

Tags: , , , ,
Posted in Administration, HowTo, Networking, System | 1 Comment »

How-To: Network-Manager-OpenVPN overwrites default route

Posted by chantra on 2nd March 2010

I was trying network-manager-openvpn plugin today on Lucid, I could import my configuration, DNS was set up correctly upon connection/disconnection, route imported correctly (almost :)).

One issue though is that it was also changing the default route to the VPN tunnel while this should not happen.

Well, the solution was simple enough after some googling (or yahooing should I say).
It appears that there is an option to set. And was as easy as editing your connection and going through:
IPv4 Settings->Routes and checking "Use this connection only for resources on its network".

Tags: ,
Posted in HowTo, Networking | No Comments »