{"id":708,"date":"2012-09-26T15:59:00","date_gmt":"2012-09-26T13:59:00","guid":{"rendered":"http:\/\/diablo.craem.net\/wordpress\/?p=708"},"modified":"2012-09-26T15:59:00","modified_gmt":"2012-09-26T13:59:00","slug":"freeradius-mysql-en-debian-squeeze","status":"publish","type":"post","link":"https:\/\/diablo.craem.net\/?p=708","title":{"rendered":"Freeradius + mysql en debian squeeze"},"content":{"rendered":"<p>Hoy toca instalar un freeradius en un cliente, para authenticar los accesos de unos hotspots Mikrotik.<br \/>\nPara la parte gr\u00e1fica, usaremos el DaloRadius&#8230; de esta manera, no tendremos que andar con los ficheros de texto.<br \/>\nSuponemos que tenemos instalado ya nuestro Debian Squeeze y, vamos a instalar unos paquetes:<br \/>\n<code><br \/>\n# aptitude install mysql-server php5 php5-mysql php5-gd php-pear php-db freeradius freeradius-mysql subversion<br \/>\n<\/code><br \/>\nCreamos usuario para mysql y la bbdd para radius:<br \/>\n<code><br \/>\n# mysql -u root -ppassword<br \/>\nmysql> GRANT ALL PRIVILEGES ON *.* TO 'radius'@'%' IDENTIFIED BY 'radius' WITH GRANT OPTION;<br \/>\nFLUSH PRIVILEGES;<br \/>\nmysql> create database radius;<br \/>\n<\/code><br \/>\nAhora bajamos el DaloRadius, en la carpeta \/usr\/src:<br \/>\n<code><br \/>\n# cd \/usr\/src<br \/>\n# svn co httpss:\/\/daloradius.svn.sourceforge.net\/svnroot\/daloradius\/trunk daloradius<br \/>\n<\/code><br \/>\nAhora movemos los directorios:<br \/>\n<code><br \/>\n# cp daloradius\/ \/var\/www -R<br \/>\n# chown www-data:www-data \/var\/www\/daloradius -R<br \/>\n# chmod 644 \/var\/www\/daloradius\/library\/daloradius.conf.php<br \/>\n<\/code><br \/>\nCreamos la estructura de la BBDD de radius:<br \/>\n<code><br \/>\nroot@radius:\/var\/www\/daloradius\/contrib\/db# mysql -u radius -pradius radius < fr2-mysql-daloradius-and-freeradius.sql\n<\/code><br \/>\nEditamos el fichero de configuraci\u00f3n de daloRadius, para que se conecte a mysql:<br \/>\n<code><br \/>\n# nano \/var\/www\/daloradius\/library\/daloradius.conf.php<br \/>\n$configValues['CONFIG_DB_ENGINE'] = 'mysql';<br \/>\n$configValues['CONFIG_DB_HOST'] = 'localhost';<br \/>\n$configValues['CONFIG_DB_PORT'] = '3306';<br \/>\n$configValues['CONFIG_DB_USER'] = 'radius';<br \/>\n$configValues['CONFIG_DB_PASS'] = 'radius';<br \/>\n$configValues['CONFIG_DB_NAME'] = 'radius';<br \/>\n<\/code><br \/>\nAhora vamos modificando los ficheros de freeradius, para que se conecte a mysql.<br \/>\nEn el directorio \/etc\/freeradius, editamos <strong>sql.conf<\/strong> y lo dejamos tal que:<br \/>\n<code><br \/>\nsql {<br \/>\n        #<br \/>\n        #  Set the database to one of:<br \/>\n        #<br \/>\n        #       mysql, mssql, oracle, postgresql<br \/>\n        #<br \/>\n        database = \"mysql\"<br \/>\n        #<br \/>\n        #  Which FreeRADIUS driver to use.<br \/>\n        #<br \/>\n        driver = \"rlm_sql_${database}\"<br \/>\n        # Connection info:<br \/>\n        server = \"localhost\"<br \/>\n        #port = 3306<br \/>\n        login = \"radius\"<br \/>\n        password = \"radius\"<br \/>\n<\/code><br \/>\nEl siguiente paso, es que las consultas de usuarios, en vez de mirar en los ficheros locales, haga las consultas en las tablas de mysql. Para ello, modificaremos el fichero:<br \/>\n<code><br \/>\nroot@radius:\/etc\/freeradius\/sites-enabled# nano default<br \/>\n<\/code><br \/>\nY modificamos:<br \/>\n<code><br \/>\n### authorization Section<br \/>\n        #<br \/>\n        #  Look in an SQL database.  The schema of the database<br \/>\n        #  is meant to mirror the \"users\" file.<br \/>\n        #<br \/>\n        #  See \"Authorization Queries\" in sql.conf<br \/>\n        sql<br \/>\n### accounting section<br \/>\n        #<br \/>\n        #  Log traffic to an SQL database.<br \/>\n        #<br \/>\n        #  See \"Accounting queries\" in sql.conf<br \/>\n        sql<br \/>\n<\/code><br \/>\nY en el fichero <strong>\/etc\/freeradius\/radiusd.conf<\/strong>, habilitamos la parte de sql:<br \/>\n<code><br \/>\n        #  Include another file that has the SQL-related configuration.<br \/>\n        #  This is another file only because it tends to be big.<br \/>\n        #<br \/>\n        $INCLUDE sql.conf<br \/>\n<\/code><br \/>\nPor \u00faltimo, modificamos el fichero clients.conf, con el <strong>NAS<\/strong><em> localhost y una pass para probar ....<em> (nas := network access server \ud83d\ude09 )<\/em> y lo dejamos tal que:<br \/>\n<code><br \/>\n# -*- text -*-<br \/>\n##<br \/>\n## clients.conf -- client configuration directives<br \/>\n##<br \/>\n##      $Id$<br \/>\n#######################################################################<br \/>\n#<br \/>\n#  Define RADIUS clients (usually a NAS, Access Point, etc.).<br \/>\nclient localhost {<br \/>\n        ipaddr = 127.0.0.1<br \/>\n        secret          = testing123<br \/>\n        nastype     = other     # localhost isn't usually a NAS...<br \/>\n}<br \/>\n<\/code><br \/>\nCreamos ahora, desde la interfaz daloRadius, un usuario, para ello, accedemos al daloradius w\u00ed\u00ada web:<br \/>\nhttps:\/\/ip.del.servidor.radius\/daloradius<br \/>\nY nos aparecer\u00e1 algo tal que:<br \/>\n<a href=\"https:\/\/diablo.craem.net\/wp-content\/uploads\/2012\/09\/Pantallazo.png\"><img fetchpriority=\"high\" decoding=\"async\" src=\"https:\/\/diablo.craem.net\/wp-content\/uploads\/2012\/09\/Pantallazo-300x261.png\" alt=\"\" title=\"Entrada daloradius\" width=\"300\" height=\"261\" class=\"aligncenter size-medium wp-image-713\" \/><\/a><br \/>\nUsuario: administrator<br \/>\npass: radius<br \/>\nEn el apartado <strong><em> Management \/ Users<\/em><\/strong> , hacemos click en  <strong><em>New User<\/em><\/strong><br \/>\n<a href=\"https:\/\/diablo.craem.net\/wp-content\/uploads\/2012\/09\/Pantallazo-1.png\"><img decoding=\"async\" src=\"https:\/\/diablo.craem.net\/wp-content\/uploads\/2012\/09\/Pantallazo-1-300x223.png\" alt=\"\" title=\"Crear usuario daloradius\" width=\"300\" height=\"223\" class=\"aligncenter size-medium wp-image-715\" \/><\/a><br \/>\nCreamos un usuario, con su password y lo probaremos en la consola.<br \/>\nParamos el servicio freeradius<br \/>\n<code><br \/>\n# \/etc\/init.d\/freeradius stop<br \/>\n<\/code><br \/>\nLanzamos el servicio en modo debug:<br \/>\n<code><br \/>\n# freeradius -X<br \/>\n............<br \/>\nModule: Checking session {...} for more modules to load<br \/>\n Module: Checking post-proxy {...} for more modules to load<br \/>\n Module: Checking post-auth {...} for more modules to load<br \/>\n } # modules<br \/>\n} # server<br \/>\nradiusd: #### Opening IP addresses and Ports ####<br \/>\nlisten {<br \/>\n\ttype = \"auth\"<br \/>\n\tipaddr = *<br \/>\n\tport = 0<br \/>\n}<br \/>\nlisten {<br \/>\n\ttype = \"acct\"<br \/>\n\tipaddr = *<br \/>\n\tport = 0<br \/>\n}<br \/>\nlisten {<br \/>\n\ttype = \"auth\"<br \/>\n\tipaddr = 127.0.0.1<br \/>\n\tport = 18120<br \/>\n}<br \/>\nListening on authentication address * port 1812<br \/>\nListening on accounting address * port 1813<br \/>\nListening on authentication address 127.0.0.1 port 18120 as server inner-tunnel<br \/>\nListening on proxy address * port 1814<br \/>\nReady to process requests.<br \/>\n<\/code><br \/>\nY ahora desde otra consola, hacemos una prueba con la utilidad <strong>radtest<\/strong><em> :<br \/>\n<code><br \/>\nroot@radius:~# radtest pruebas pruebas01 localhost:1812 0 testing123<br \/>\nSending Access-Request of id 49 to 127.0.0.1 port 1812<br \/>\n\tUser-Name = \"pruebas\"<br \/>\n\tUser-Password = \"pruebas01\"<br \/>\n\tNAS-IP-Address = 127.0.1.1<br \/>\n\tNAS-Port = 0<br \/>\nrad_recv: Access-Accept packet from host 127.0.0.1 port 1812, id=49, length=20<br \/>\nroot@radius:~#<br \/>\n<\/code><br \/>\nNuestros datos:<br \/>\nUsername: pruebas<br \/>\npass:pruebas01<br \/>\nNasKey:testing123 (lo hemos puesto en el apartado nas, anteriormente, en localhost<br \/>\nPuerto Radius: 1812<br \/>\nY el freeradius, nos responde con:<br \/>\n<code><br \/>\nReady to process requests.<br \/>\nrad_recv: Access-Request packet from host 127.0.0.1 port 37927, id=49, length=59<br \/>\n\tUser-Name = \"process\"<br \/>\n\tUser-Password = \"control10\"<br \/>\n\tNAS-IP-Address = 127.0.1.1<br \/>\n\tNAS-Port = 0<br \/>\n# Executing section authorize from file \/etc\/freeradius\/sites-enabled\/default<br \/>\n+- entering group authorize {...}<br \/>\n++[preprocess] returns ok<br \/>\n++[chap] returns noop<br \/>\n++[mschap] returns noop<br \/>\n++[digest] returns noop<br \/>\n[suffix] No '@' in User-Name = \"pruebas\", looking up realm NULL<br \/>\n[suffix] No such realm \"NULL\"<br \/>\n++[suffix] returns noop<br \/>\n[eap] No EAP-Message, not doing EAP<br \/>\n++[eap] returns noop<br \/>\n++[files] returns noop<br \/>\n[sql] \texpand: %{User-Name} -> pruebas<br \/>\n[sql] sql_set_user escaped user --> 'pruebas'<br \/>\nrlm_sql (sql): Reserving sql socket id: 4<br \/>\n[sql] \texpand: SELECT id, username, attribute, value, op           FROM radcheck           WHERE username = '%{SQL-User-Name}'           ORDER BY id -> SELECT id, username, attribute, value, op           FROM radcheck           WHERE username = 'pruebas'           ORDER BY id<br \/>\n[sql] User found in radcheck table<br \/>\n[sql] \texpand: SELECT id, username, attribute, value, op           FROM radreply           WHERE username = '%{SQL-User-Name}'           ORDER BY id -> SELECT id, username, attribute, value, op           FROM radreply           WHERE username = 'pruebas'           ORDER BY id<br \/>\n[sql] \texpand: SELECT groupname           FROM radusergroup           WHERE username = '%{SQL-User-Name}'           ORDER BY priority -> SELECT groupname           FROM radusergroup           WHERE username = 'pruebas'           ORDER BY priority<br \/>\nrlm_sql (sql): Released sql socket id: 4<br \/>\n++[sql] returns ok<br \/>\n++[expiration] returns noop<br \/>\n++[logintime] returns noop<br \/>\n++[pap] returns updated<br \/>\nFound Auth-Type = PAP<br \/>\n# Executing group from file \/etc\/freeradius\/sites-enabled\/default<br \/>\n+- entering group PAP {...}<br \/>\n[pap] login attempt with password \"pruebas01\"<br \/>\n[pap] Using clear text password \"pruebas01\"<br \/>\n[pap] User authenticated successfully<br \/>\n++[pap] returns ok<br \/>\n# Executing section post-auth from file \/etc\/freeradius\/sites-enabled\/default<br \/>\n+- entering group post-auth {...}<br \/>\n++[exec] returns noop<br \/>\nSending Access-Accept of id 49 to 127.0.0.1 port 37927<br \/>\nFinished request 0.<br \/>\nGoing to the next request<br \/>\nWaking up in 4.9 seconds.<br \/>\nCleaning up request 0 ID 49 with timestamp +177<br \/>\nReady to process requests.<br \/>\n<\/code><br \/>\nY vemos como hace la consulta en mysql.<br \/>\nEnjoy your radius \ud83d\ude09<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Hoy toca instalar un freeradius en un cliente, para authenticar los accesos de unos hotspots Mikrotik. Para la parte gr\u00e1fica, usaremos el DaloRadius&#8230; de esta manera, no tendremos que andar con los ficheros de texto. Suponemos que tenemos instalado ya nuestro Debian Squeeze y, vamos a instalar unos paquetes: # aptitude install mysql-server php5 php5-mysql [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[5,8],"tags":[58,80,102],"class_list":["post-708","post","type-post","status-publish","format-standard","hentry","category-linux","category-varios","tag-debian","tag-freeradius","tag-linux-2"],"_links":{"self":[{"href":"https:\/\/diablo.craem.net\/index.php?rest_route=\/wp\/v2\/posts\/708","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/diablo.craem.net\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/diablo.craem.net\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/diablo.craem.net\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/diablo.craem.net\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=708"}],"version-history":[{"count":0,"href":"https:\/\/diablo.craem.net\/index.php?rest_route=\/wp\/v2\/posts\/708\/revisions"}],"wp:attachment":[{"href":"https:\/\/diablo.craem.net\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=708"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/diablo.craem.net\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=708"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/diablo.craem.net\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=708"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}