Page tree
Skip to end of metadata
Go to start of metadata

Установка FreeRADIUS

Если FreeRADIUS уже установлен на сервере, создайте дополнительный экземпляр freeradius-dhcp, используя соответствующее руководство: Создание дополнительного экземпляра сервера FreeRADIUS

Установка пакета производится из репозитория компании Латера (deb.hydra-billing.com). Данный репозиторий подключается сотрудниками компании Латера в рамках технической поддержки. Отличие от штатного пакета freeradius в том, что он собран со всеми необходимыми для работы модулями. Рекомедуется также установить пакет freeradius-utils, содержащий программы-клиенты и утилиты для работы с сервером.

user@server:~$ sudo aptitude update && \
               sudo aptitude install freeradius freeradius-utils

Настройка FreeRADIUS для работы в качестве DHCP-сервера

Изменение основной конфигурации

В файле конфигурации /etc/freeradius-dhcp/sites-available/dhcp-hydra необходимо указать в специально отмеченных строках IP-адрес внешнего интерфейса сервера, на котором установлена данная копия FreeRADIUS. Пример готовой конфигурации представлен ниже:

/etc/freeradius-dhcp/sites-available/dhcp-hydra
server dhcp {
listen {
    ipaddr = 123.123.123.123
#    interface = em0
    port = 67
    type = dhcp
    broadcast = yes
}
dhcp DHCP-Discover {
    # Log the request
    linelog-dhcp
    update reply {
        DHCP-DHCP-Server-Identifier = 123.123.123.123
        DHCP-Flags = 0
        }
    perl
    if (ok) {
        if (DHCP-Vendor-Class-Identifier =~ /^MSFT/i) {
            update reply {
                DHCP-Vendor = '0x010400000002'
#                DHCP-MS-WPAD = '0xfc'
            }
        }
        update reply {
            DHCP-Message-Type = DHCP-Offer
        }
    }
    else {
        update reply {
            DHCP-Message-Type = 0
        }
    }
    # Log the response
    linelog-dhcp
    ok
}
dhcp DHCP-Request {
    # Log the request
    linelog-dhcp
    update reply {
        DHCP-DHCP-Server-Identifier = 123.123.123.123
        DHCP-Flags = 0
    }
    perl
    if (ok) {
        if (DHCP-Vendor-Class-Identifier =~ /^MSFT/i) {
            update reply {
                DHCP-Vendor = '0x010400000002'
#                DHCP-MS-WPAD = '0xfc'
            }
        }
        update reply {
            DHCP-Message-Type = DHCP-Ack
        }
    }
    elsif (notfound) {
        update reply {
            DHCP-Message-Type = DHCP-NAK
        }
    }
    elsif (updated) {
        update reply {
            DHCP-Message-Type = DHCP-NAK
        }
    }
    else {
        update reply {
            DHCP-Message-Type = 0
        }
    }
    # Log the response
    linelog-dhcp
    ok
}
dhcp DHCP-Release {
    handled
}
dhcp DHCP-Inform {
    handled
}
dhcp {
    handled
}
post-auth {
}
}

После изменения файла конфигурации необходимо отключить все остальные конфигурации и включить нужную:

user@server:~$ sudo rm /etc/freeradius-dhcp/sites-enabled/default      && \
               sudo rm /etc/freeradius-dhcp/sites-enabled/inner-tunnel && \
			   cd /etc/freeradius-dhcp/sites-enabled                   && \
               sudo ln -s ../sites-available/dhcp-hydra .

В файле /etc/freeradius-dhcp/radiusd.conf следует полностью закомментировать или удалить все (по умолчанию их две) секции listen, а также изменить значение параметра proxy_request:

/etc/freeradius-dhcp/radiusd.conf
...
 
#listen {
        #  Type of packets to listen for.
        #  Allowed values are:
        #       auth    listen for authentication packets
        #       acct    listen for accounting packets
        #       proxy   IP to use for sending proxied packets
        #       detail  Read from the detail file.  For examples, see
        #               raddb/sites-available/copy-acct-to-home-server
        #       status  listen for Status-Server packets.  For examples,
        #               see raddb/sites-available/status
        #       coa     listen for CoA-Request and Disconnect-Request		
        #               packets.  For examples, see the file
        #               raddb/sites-available/coa-server
        #
#       type = auth
        #  Note: "type = proxy" lets you control the source IP used for
        #        proxying packets, with some limitations:
        #
        #    * A proxy listener CANNOT be used in a virtual server section.
        #    * You should probably set "port = 0".
        #    * Any "clients" configuration will be ignored.
        #
        #  See also proxy.conf, and the "src_ipaddr" configuration entry
        #  in the sample "home_server" section.  When you specify the
        #  source IP address for packets sent to a home server, the
        #  proxy listeners are automatically created.
        #  IP address on which to listen.
        #  Allowed values are:
        #       dotted quad (1.2.3.4)
        #       hostname    (radius.example.com)
        #       wildcard    (*)
#       ipaddr = *
        #  OR, you can use an IPv6 address, but not both
        #  at the same time.
#       ipv6addr = ::   # any.  ::1 == localhost
        #  Port on which to listen.
        #  Allowed values are:
        #       integer port number (1812)
        #       0 means "use /etc/services for the proper port"
#       port = 0
        #  Some systems support binding to an interface, in addition
        #  to the IP address.  This feature isn't strictly necessary,
        #  but for sites with many IP addresses on one interface,
        #  it's useful to say "listen on all addresses for eth0".
        #
        #  If your system does not support this feature, you will
        #  get an error if you try to use it.
        #
#       interface = eth0
        #  Per-socket lists of clients.  This is a very useful feature.
        #
        #  The name here is a reference to a section elsewhere in
        #  radiusd.conf, or clients.conf.  Having the name as
        #  a reference allows multiple sockets to use the same
        #  set of clients.
        #
        #  If this configuration is used, then the global list of clients
        #  is IGNORED for this "listen" section.  Take care configuring
        #  this feature, to ensure you don't accidentally disable a
        #  client you need.
        #
        #  See clients.conf for the configuration of "per_socket_clients".
        #
#       clients = per_socket_clients
#}
#  This second "listen" section is for listening on the accounting
#  port, too.
#
#listen {
#       ipaddr = *
#       ipv6addr = ::
#       port = 0
#       type = acct
#       interface = eth0
#       clients = per_socket_clients
#}
...
 
proxy_requests  = no
#$INCLUDE proxy.conf

... 

Подключение модуля hard-dhcp

В модуле /etc/freeradius-dhcp/modules/perl необходимо включить использование модуля  hard-dhcp.pm:

/etc/freeradius-dhcp/modules/perl
perl {
        #
        #  The Perl script to execute on authorize, authenticate,
        #  accounting, xlat, etc.  This is very similar to using
        #  'rlm_exec' module, but it is persistent, and therefore
        #  faster.
        #
        module = ${confdir}/hard-dhcp.pm

...
}

 

Настройка логирования

Для логирования DHCP-запросов необходимо в конец файла /etc/freeradius-dhcp/modules/linelog добавить следующее:

/etc/freeradius-dhcp/modules/linelog
linelog linelog-dhcp {
    filename = ${logdir}/linelog-dhcp.log
    format = ""
    reference = "%{%{reply:DHCP-Message-Type}:-%{request:DHCP-Message-Type}}"
    DHCP-Discover = "%S --> Transaction-ID: %{DHCP-Transaction-Id} DISCOVER: [%{DHCP-Client-Hardware-Address}] via (%{DHCP-Gateway-IP-Address}), hop count = %{DHCP-Hop-Count}, Relay = %{DHCP-Relay-Remote-Id}, Hostname =  %{DHCP-Hostname}"
    DHCP-Offer = "%S <-- Transaction-ID: %{DHCP-Transaction-Id} OFFER: %{reply:DHCP-Your-IP-Address} to [%{DHCP-Client-Hardware-Address}] ..."
    DHCP-Request = "%S --> Transaction-ID: %{DHCP-Transaction-Id} REQUEST: [%{DHCP-Client-Hardware-Address}] via (%{DHCP-Gateway-IP-Address}), hop count = %{DHCP-Hop-Count}, Relay = %{DHCP-Relay-Remote-Id} ..."
    DHCP-Ack = "%S <-- Transaction-ID: %{DHCP-Transaction-Id} ACK: %{reply:DHCP-Your-IP-Address} to [%{DHCP-Client-Hardware-Address}] ..."
    DHCP-NAK = "%S <-- Transaction-ID: %{DHCP-Transaction-Id} NAK: [%{DHCP-Client-Hardware-Address}] for %{request:DHCP-Client-IP-Address}; ..."
    0 = "%S -/- Transaction-ID: %{DHCP-Transaction-Id} %{request:DHCP-Message-Type} DROPPED: ..."
}

Настройка параметров подключения к агенту HARD

Параметры подключения необходимо указать в файле /etc/freeradius-dhcp/hard-dhcp.pm следующим образом:

/etc/freeradius-dhcp/hard-dhcp.pm
...
# Параметры для связи с HARD
use constant HARD_API_URL       => "http://<hard_ip_addr>:<hard_port>/<plugin_name>/<plugin_object>"; # API URL
use constant HARD_AUTH_USER     => "<hard_login>";                                                    # Логин
use constant HARD_AUTH_PASSWORD => "<hard_password>";                                                 # Пароль
...
  • <hard_ip_addr> — IP-адрес, на котором агент HARD принимает запросы;

  • <hard_port> — номер порта, на котором агент HARD принимает запросы;

  • <plugin_name> — название используемого плагина агента HARD;
  • <plugin_object> — название объекта указанного плагина, которому будут передаваться запросы;
  • <hard_login> — логин для подключения к агенту HARD;
  • <hard_pasword> — пароль для подключения к агенту HARD.

Пример:

/etc/freeradius-dhcp/hard-dhcp.pm
...
# Параметры для связи с HARD
use constant HARD_API_URL       => "http://localhost:11080/dhcp/main"; # API URL
use constant HARD_AUTH_USER     => "hydra";                            # Логин
use constant HARD_AUTH_PASSWORD => "q123";                             # Пароль
...

Настройка используемой RADIUS-службы

В файле /etc/freeradius-dhcp/hard-dhcp.pm также необходимо указать сетевую RADIUS-службу, которая будет использоваться с данным сервером:

/etc/freeradius-dhcp/hard-dhcp.pm
# Код сетевой службы RADIUS в АСР
use constant HYDRA_AAA_SERV     => "<radius_serivce_code>";
  • <radius_serivce_code> — код сетевой RADIUS-службы.

Пример:

/etc/freeradius-dhcp/hard-dhcp.pm
# Код сетевой службы RADIUS в АСР
use constant HYDRA_AAA_SERV     => "RADIUS-DHCP";

Запуск

Управлять состоянием сервера вручную можно с помощью инициализационного скрипта /etc/init.d/freeradius-dhcp:

user@server:~$ sudo /etc/init.d/freeradius-dhcp <command>

Вместо <command> следует использовать одну из команд:

  • start — запуск сервера,
  • stop — остановка сервера ,
  • restart — проверка конфигурации и перезапуск сервера,
  • reload — проверка конфигурации и отправка серверу сигнала о необходимости перезагрузки конфигурации,
  • configtest — проверка конфигурации,
  • debug — запуск в режиме отладки (наиболее подходящий для настройки сервера режим работы).
  • No labels