Wednesday, 6 November 2013

Setting up Freeradius with Daloradius in Ubuntu 12.04



1. Install freeradius
# apt-get install freeradius
2. Install pre-requisite package for daloradius
# apt-get install php5-common php5-gd php-pear php-db libapache2-mod-php5 php-mail
3. Download latest daloradius from http://sourceforge.net/projects/daloradius/ . Latest version as of now is 0.9.9
4. Uncompress daloradius-0.9-9.tar.gz to your web directory which is /var/www assuming you have installed apache2 prior to that. 
# cd /var/www
# tar xzf /your-directory/daloradius-0.9-9.tar.gz
5. Create a symbolic link for daloradius-0.9-9 for easy access
ln -s daloradius-0.9-9 daloradius
6. Install the freeradius + daloradius database from daloradius package. 
  Note: Use -h option if the mysql server is not installed in the same server
# cd daloradius/contrib/db
mysql -u<database user> -p<password> < fr2-mysql-daloradius-and-freeradius.sql -h <database host> -D <database name>

Configure Database settings in Daloradius

1. Open db config file in Daloradius
# cd /var/www/daloradius/library
# vi daloradius.conf.php
2. Edit the following value according to your mysql setup
$configValues['CONFIG_DB_HOST'] = 'localhost';
$configValues['CONFIG_DB_USER'] = 'root';
$configValues['CONFIG_DB_PASS'] = '';
$configValues['CONFIG_DB_NAME'] = 'radius';
3. Save the file after changes made.

Configure MySQL in Freeradius

1. Open sql config file in freeradius
# cd /etc/freeradius
# vi sql.conf
2. Modify the following value under sql directive
server = “”
login = “”
password = “”
radius_db = “”
3. Uncomment “readclients = yes” for radius client (NAS) to be read from database
4. Save the file after changes made

Enable sql for Radius Authorization and Accounting

1. Install freeradius-mysql driver
# apt-get install freeradius-mysql
2. Uncomment the following line in radiusd.conf
# $INCLUDE sql.conf
3. Uncomment the line with sql” under “authorize” and “accounting” directive in /etc/freeradius/sites-available/default

Enable Max-All-Session attribute for controlling User maximum session time

1. Add the following snippet in /etc/freeradius/sites-available/default under authorize directive
noresetcounter {
    reject = 1
}
if(reject){
   update reply {
       Reply-Message := "You have reached your time limit"
   }
   ok = reject
}
2. Add the following snippet in /etc/freeradius/sql/mysql/counter.conf
sqlcounter noresetcounter {
        counter-name = Max-All-Session-Time
                check-name = Max-All-Session
                sqlmod-inst = sql
                key = User-Name
                reset = never
        Reply-Message = "Your Maximum Never Used time has been reached!"
        query = "SELECT IFNULL(SUM(AcctSessionTime),0) FROM radacct WHERE UserName='%{%k}'"
}

Enable Max-Octets attribute for controlling User maximum usage quota in bytes

1. Add the following snippet in /etc/freeradius/sites-available/default under authorize directive
noresetBytecounter {
    reject = 1
}
if(reject) {
    update reply {
        Reply-Message := "You have reached your bandwidth limit"
    }
    ok = reject
}
2. Add the following snippet in /etc/freeradius/sql/mysql/counter.conf
sqlcounter noresetBytecounter {
        counter-name = Total-Max-Octets
                check-name = Max-Octets
                reply-name = ChilliSpot-Max-Total-Octets
                sqlmod-inst = sql
                key = User-Name
                reset = never
        Reply-Message = "Your Maximum Data Usage Quota has been reached!"
        query = "SELECT (SUM(AcctInputOctets)+SUM(AcctOutputOctets)) FROM radacct WHERE UserName='%{%k}'"
}

Tuesday, 29 October 2013

Configuring Network Interface (IP address) in Ubuntu 12.04

Network interface is the one of the basic setup in a server or workstation to get your machine connected to outside world. This article will guide you configure the network interface in Ubuntu 12.04 in both dynamic and static.

Pre-requisite:
You should know basic operation of vi editor in order to follow this guide

Dynamic IP address:
1. Open network interface file with vi editor
# vi /etc/network/interfaces
2. Look for the line with iface eth0
3. Modify the line with following
iface eth0 inet dhcp
4. The actual configuration for interface eth0 should be this
auto eth0
iface eth0 inet dhcp
5. If you have more than 1 network interface, let’s say eth0 and eth1, and you wish to configure both of them as dynamic IP, the configuration would be as followed.
auto eth0 
iface eth0 inet dhcp
auto eth1
iface eth1 inet dhcp
6. Save the file and close vi editor
7. Type the following command to restart your network settings
# /etc/init.d/networking restart
8. Type the following command to check your newly allocated IP address
# ifconfig eth0
9. You should see an output similar like following
eth0      Link encap:Ethernet  HWaddr 00:0c:29:17:fe:5f
          inet addr:192.168.223.128  Bcast:192.168.223.255  Mask:255.255.255.0
          inet6 addr: fe80::20c:29ff:fe17:fe5f/64 Scope:Link
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
          RX packets:17637 errors:0 dropped:0 overruns:0 frame:0
          TX packets:8875 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1000
          RX bytes:25244876 (25.2 MB)  TX bytes:502639 (502.6 KB)
          Interrupt:19 Base address:0x2000

Static IP address:
1. Open network interface file with vi editor
# vi /etc/network/interfaces
2. Modify the eth0 section with following. (Key in the address, subnet and gateway  values that accordance to your network setup)
auto eth0
iface eth0 inet static
      address 192.168.223.129
      subnet 255.255.255.0
      gateway 192.168.223.1
3. Save the file and close vi editor
4. Restart the network
# /etc/init.d/networking restart
5. Your server IP address will change to the static IP 
6. Be cautious when you configure a static IP. It may cause IP conflict. Check the dhcp pool with your network administrator and use the IP that is not within the dhcp pool range. For example, if your DHCP pool is 192.168.1.100-192.168.1.200, you can set your static IP from 192.168.1.2-192.168.1.99 as well as 192.168.201-192.168.254. But you need to be sure that the IP you will using is not occupied by other servers or workstation.