Skip to content

Instantly share code, notes, and snippets.

@darconeous
Last active June 23, 2023 11:09
Show Gist options
  • Star 15 You must be signed in to star a gist
  • Fork 5 You must be signed in to fork a gist
  • Save darconeous/96d1b95ca56d6dd4033b to your computer and use it in GitHub Desktop.
Save darconeous/96d1b95ca56d6dd4033b to your computer and use it in GitHub Desktop.
Getting FreeRadius set up on EdgeRouter
-----BEGIN DH PARAMETERS-----
MIIBCAKCAQEAq5/y4YW0hozeF0bQw86uDaDO0o+68DjAch61bc3nwyVC77e6JYUT
5F9x+mn9j25KhbcNGBcZvO/TFHsPf4bx4fojNKD2T5nZATJRtGuepnyjz5XEpPe2
ojAsjYpPg/0HZou/tyPM1OGTi5qlVUHa+GHrpX5419NDdOCU5IRr1kkIOMaT7+co
OFAlGCr8fiLTArGWbZDed3N0EvXE1JaIlOmQmVxLP8EycZsbjnCWB9b7DfQW2TeB
9Qp3PjfpAH/VPc3xrMqrXLlGR3h6PA5FfanN2e1XWISOYQe9N/K5uN6lze+HoAk6
Kusp+bLFxWX5EDxK1XXW+4L5JwNwUDMZCwIBAg==
-----END DH PARAMETERS-----

Getting FreeRadius set up on EdgeRouter

In some cases it is useful to have a RADIUS server set up on the router. This is particularly useful for 802.1x authentication. In this case we aren't setting up anything too fancy: just a flat-file with username and password combinations. I imagine this setup could be extended to apply to a more complicated setup that would use an LDAP back end, but that is out of scope for this article.

Note that I'm new to setting up FreeRadius, and I can make no claims about the security of setting up and using FreeRadius in the fashion described below. As I become aware of any security issues I'll update this file.

The first few steps are from the article "Add other Debian packages to EdgeOS".

Step 1: Add debian repo and the security repo

configure
set system package repository wheezy components 'main contrib non-free'
set system package repository wheezy distribution wheezy 
set system package repository wheezy url http://http.us.debian.org/debian
set system package repository wheezy-security components main
set system package repository wheezy-security distribution wheezy/updates
set system package repository wheezy-security url http://security.debian.org
commit
save
exit

Step 2: Update the local cache.

sudo apt-get update

Step 3: Install FreeRadius

sudo apt-get -y install freeradius

Step 4: Move /etc/freeradius/ to /config/freeradius

sudo mv /etc/freeradius /config/freeradius
sudo ln -s /config/freeradius /etc/freeradius

Step 5: Set up the certificates

You may want to use a different server certificate/key here. We are aiming for a flat-file configuration, so this is only really important if you want to do TLS.

TODO: Check to make sure that doing the following yields a secure setup.

sudo cp /etc/ssl/private/ssl-cert-snakeoil.key /config/freeradius/certs/server.key
sudo cp /etc/ssl/certs/ssl-cert-snakeoil.pem /config/freeradius/certs/server.pem
sudo cp /etc/ssl/certs/ssl-cert-snakeoil.pem /config/freeradius/certs/ca.pem

Step 6: Set up the DH parameters

sudo openssl dhparam -out /config/freeradius/certs/dh 2048

This will take a very long time. If you don't want to wait, feel free to generate the parameters on a faster local computer and copy the file over. Or you can use the dh.pem file attached to this gist.

Step 7: Update /config/freeradius/radiusd.conf

This is optional, but you may want to change the address that the radius server is listening on. This is around line 270 and 313.

Step 8: Update /config/freeradius/clients.conf

First, you will need to pick a new client secret. This should be a strong password. Don't skimp on this, add as much entropy as you can. Use something like this tool to generate a strong password for you.

You should then open up /config/freeradius/clients.conf in vi. Around line 98 will be where you set the shared secret for clients connecting from localhost. Go ahead and change this secret to the secret you generated above.

Then add something like this to the end of the file:

client 192.168.0.0/24 {
       secret          = JK9Y-KYNH-HCPX-4MWQ-QXQ7
       shortname       = local-private-network
}

Set the network to be where your WAPs will connect from.

Step 9: Update /config/freeradius/users

This file is where you can add individual users. Simply add lines like this to the file to add new users:

bob     Cleartext-Password := "hello"

This adds a new user, bob, who has the password hello.

Step 10: Start the server

sudo /etc/init.d/freeradius start

Step 11: Test the server

radtest bob hello localhost 0 JK9Y-KYNH-HCPX-4MWQ-QXQ7

Step 12: Make sure FreeRADIUS gets reinstalled after an update

This is all great, but if you install a router firmware update then freeradius will stop working. The following trick helps re-establish freeradius after an update.

Create a file named /config/scripts/post-config.d/freeradius.sh and set the contents to the following:

#!/bin/bash

die() {
	exit 1
}

[ -e /etc/freeradius ] || {
	apt-get update || die
	apt-get install -y freeradius
        
        rm -r /etc/freeradius || die
        ln -s /config/freeradius /etc/freeradius || die

	chown -R freerad:freerad /config/freeradius || die        
        
        sudo /etc/init.d/freeradius start
}

[ -d /var/log/freeradius ] || {
	mkdir -p /var/log/freeradius || die
	chown -R freerad:freerad /var/log/freeradius || die        
}

[ -d /var/run/freeradius ] || {
	mkdir -p /var/run/freeradius || die
	chown -R freerad:freerad /var/run/freeradius || die        
}

Don't forget to mark it as executable with chmod +x /config/scripts/post-config.d/freeradius.sh.

Additional Reading

@kathampy
Copy link

kathampy commented Feb 8, 2017

You can get recently generated DH params from 2 Ton Digital: "curl -o DH https://2ton.com.au/dhparam/2048"

@JunShine
Copy link

JunShine commented Sep 2, 2018

The freeradius installed in this way, the version is too old is 2.x。How to install a new version?

@kathampy
Copy link

kathampy commented Apr 12, 2019

@JunShine The new EdgeOS 2.x is based on Debian Stretch which has FreeRADIUS 3.0. You must update the package repository commands for Stretch and use apt install freeradius --no-install-recommends.

@yzlai
Copy link

yzlai commented May 12, 2019

For those with EdgeOS 1.x, since wheezy passed EOL, so they removed it from the main repos.
Change the urls to point to the archive site.
set system package repository wheezy url http://archive.debian.org/debian

[reference]

@billdenney
Copy link

FYI, I found your gist after I did something similar to get 2-factor authentication working for VPN (https://gist.github.com/billdenney/5c2e7284f57d92ef5a9b1e14b684733c). Yours is better for several items-- including the fact that yours works after an upgrade. Mine works for some different uses.

@ast3150
Copy link

ast3150 commented Jun 23, 2023

2023 Update: Some parts of the stretch package repository could not be reached for the normal mirrors. I had to use the debian archive as package source. That means:

set system package repository stretch components 'main contrib non-free'
set system package repository stretch distribution stretch
set system package repository stretch url http://archive.debian.org/debian

(You can omit the rest of the lines referring to wheezy-security)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment