Kea DHCP配置介绍和基本使用

目录

摘要
配置
启动
管理API
测试
总结
参考文献
附录

摘要

简单介绍Kea DHCP从配置到启动,再到测试的一个流程。使用MySQL作为Kea后台数据库。附录部分会给出一个完整可以用于启动的配置。

配置

Kea使用的是JSON格式。

配置路径:{KEA_HOME}/etc/kea/kea-dhcp4.conf

以下是节选部分重点配置进行说明

{
"Dhcp4": {
    # 向服务器租用地址,借多久,如下是4000秒
    "valid-lifetime": 4000,
    # renew-timer和rebind-timer管理客户端什么时候开始进行重新续借和重绑过程。如果没有指定这两个值将根据RFC 2131进行设置
    # 可选 续借
    "renew-timer": 1000,
    # 可选 重绑
    "rebind-timer": 2000,

    "interfaces-config": {
        # 1. 指定服务器要监听哪张网卡的DHCP消息,可以指定多张网卡。
        # 2.允许使用*,如:"interfaces": ["*"],表示监听所有网卡
        "interfaces": ["eth0"],
        # 默认raw,表示处理所有报文
        # udp:处理udp报文
        "dhcp-socket-type": "udp"# 只有dhcp-socket-type为udp才生效
        # 默认是same-as-inbound:从哪里来滚哪里去
        # use-routing:从哪里来,滚哪里去,得问下kernel的路由表(routing table)       "outbound-interface": "use-routing"
    },

    # 租期数据使用库类型指定,类型不同,对应的配置也有所不同,这里以MySQL为例
    "lease-database": {
        # 目前有memfile", "mysql", "postgresql", "cql"四个选项
        "type": "mysql",
        # 数据所在的主机ip
        "host": "localhost",
        # 数据库端口号
        "port": 3306,        
        # 数据库名称
        "name": "kea",
        # 数据库用户名
        "user": "root",
        # 数据库密码
        "password": "lion",
        # 当type为memfile这里会涉及到一个比较重要的配置,这里不说明,详情请看(http://kea.isc.org/wiki/LFCDesign)
        # 默认3600,0的时候表示禁用lease file cleanup(LFC) lease file cleanup
        # "lfc-interval": 1800
    },

    # 1.下面的配置可选。主机预定数据使用的数据库类型。和租期配置类同,不在赘述
    # 2. 当然你也可以不使用数据库,在数据量不大的情况下推荐使用配置文件。随着数据量的增大可以改用数据库
    # 3. 这个配置允许数据库和配置文件共存使用
    # 4. 同时使用时,先检查配置文件,在检查数据库的数据
    // "hosts-database": {
    //     "type": "mysql",
    //     "host": "localhost",
    //     "port": 3306,
    //     "name": "kea",
    //     "user": "kea",
    //     "password": "kea"
    // },

    "subnet4": [{
        # 子网标识符,没有指定或者为0,则自动分配
        # 建议手动分配,如果有多个子网,某个子网被删除,id可能被自动重新分配,导致租期数据混乱
        "id":"1024"
        # 网段 这里需要注意下网段必须和服务器所在网段一样,不然接收不到客户的请求
        "subnet": "192.0.2.0/24",
        # 可分配地址范围
        "pools": [{"pool": "192.0.2.1 - 192.0.2.200"}]
    }]
}
}

启动

运行

keactrl start

如果报如下类似的错误你需要运行ldconfig,然后重新运行上面命令

INFO/keactrl: Starting /usr/local/sbin/kea-dhcp4 -c /usr/local/etc/kea/kea-dhcp4.conf
/usr/local/sbin/kea-dhcp4: error while loading shared libraries: libkea-dhcpsrv.so.8: cannot open shared object file: No such file or directory
INFO/keactrl: Starting /usr/local/sbin/kea-dhcp6 -c /usr/local/etc/kea/kea-dhcp6.conf
/usr/local/sbin/kea-dhcp6: error while loading shared libraries: libkea-dhcpsrv.so.8: cannot open shared object file: No such file or directory
INFO/keactrl: Starting /usr/local/sbin/kea-ctrl-agent -c /usr/local/etc/kea/kea-ctrl-agent.conf
root@ubt64-106-155:~/install/kea-1.3.0# /usr/local/sbin/kea-ctrl-agent: error while loading shared libraries: libkea-process.so.1: cannot open shared object file: No such file or directory

成功运行界面

管理API

management API允许下发特定的管理命令,例如统计获取,重新配置或者关闭服务等。必须启动Control Agent组件服务

配置路径:{KEA_HOME}/etc/kea/kea-ctrl-agent.conf

# 获取配置信息
curl -X POST -H "Content-Type: application/json" -d '{"command": "config-get", "service": [ "dhcp4" ]}' http://172.18.106.155:8080/

测试

功能测试

dhtest一个DHCP客户端仿真工具。该工具用于测试DHCP服务器。

安装
1. 下载
http://download.csdn.net/download/z475382220/10164483 (有积分的支持下)
https://github.com/saravana815/dhtest/archive/master.zip (没积分的点击这个下载)

2. 解压
root@ubt64-106-10:~/zjh/#unzip dhtest-master.zip

3. 编译
root@ubt64-106-10:~/zjh#cd dhtest-master
root@ubt64-106-10:~/zjh/dhtest-master#make

4. 基本用法
该命令会打印详细的交互过程
root@ubt64-106-10:~/zjh/dhtest-master#./dhtest -m 00:00:11:22:33:44 -V -i eth0
性能测试

perfdhcp一个dchp服务器性能测试工具.
- 目的
1. 查看每秒能处理多少个discover(v4)或者solicit(v6)消息
2. 查看每秒能处理处理4-way packet exchanges(v4 - DORA, v6 - SARR)(即一个完成的请求动态ip的过程)

  • 用法
# 请求分配一个ip
perfdhcp 172.18.106.155 -4

# 模拟1000个客户请求ip,如果R不指定则默认为1
perfdhcp 172.18.106.155 -4 -R 1000

总结

  1. 测试工具介绍比较简单,这里只是引入,详情查看参考文献
  2. 数据的搭建这里不做介绍,自行网上查询。
  3. 数据的kea库的初始化可以查看我上一篇文章Kea DHCP服务器安装教程

参考文献

DHCPv4 Server Configuration

Linux dhcp client simulation tool

DHCP Benchmarking

附录

{
"Dhcp4": {
    "renew-timer": 900,
    "rebind-timer": 1800,
    "valid-lifetime": 3600,

    "interfaces-config": {
        "interfaces": ["eth0"]        
    },

    "control-socket": {
        "socket-type": "unix",
        "socket-name": "/tmp/kea-dhcp4-ctrl.sock"
    },

    "lease-database": {
          "type": "mysql",
          "name": "kea",
          "user": "root",
          "password": "tiger",
          "host": "localhost",
          "port": 3306 
    },

    "expired-leases-processing": {
        "reclaim-timer-wait-time": 10,
        "flush-reclaimed-timer-wait-time": 25,
        "hold-reclaimed-time": 3600,
        "max-reclaim-leases": 100,
        "max-reclaim-time": 250,
        "unwarned-reclaim-cycles": 5
    },

    "option-data": [{
            "name": "domain-name-servers",
            "data": "192.0.2.1, 192.0.2.2"
        },{
            "code": 15,
            "data": "example.org"
        },{
            "name": "domain-search",
            "data": "mydomain.example.com, example.com"
        },{
            "name": "boot-file-name",
            "data": "EST5EDT4\\,M3.2.0/02:00\\,M11.1.0/02:00"
        },{
            "name": "default-ip-ttl",
            "data": "0xf0"
        }],

    "client-classes": [{
            "name": "voip",         
            "test": "substring(option[60].hex,0,6) == 'Aastra'",            
            "next-server": "192.0.2.254",
            "server-hostname": "hal9000",
            "boot-file-name": "/dev/null"
        }],

    "subnet4": [{
            "subnet": "172.18.106.0/24",
            "pools": [{ "pool": "172.18.106.2 - 172.18.106.100" }],
            "option-data": [{
                    "name": "routers",
                    "data": "172.18.106.1"
                }],

    "reservations": [{
            "hw-address": "1a:1b:1c:1d:1e:1f",
            "ip-address": "172.18.106.20"
        },{
            "client-id": "01:11:22:33:44:55:66",
            "ip-address": "192.0.2.202",
            "hostname": "special-snowflake"
        },{
            "duid": "01:02:03:04:05",
            "ip-address": "192.0.2.203",
            "option-data": [ {
                "name": "domain-name-servers",
                "data": "10.1.1.202, 10.1.1.203" }]
        },{
            "client-id": "01:12:23:34:45:56:67",
            "ip-address": "192.0.2.204",
            "option-data": [{
                    "name": "vivso-suboptions",
                    "data": "4491" },{
                    "name": "tftp-servers",
                    "space": "vendor-4491",
                    "data": "10.1.1.202, 10.1.1.203" }]
        },{
            "client-id": "01:0a:0b:0c:0d:0e:0f",
            "ip-address": "192.0.2.205",
            "next-server": "192.0.2.1",
            "server-hostname": "hal9000",
            "boot-file-name": "/dev/null"
        },{
            "flex-id": "'s0mEVaLue'",
            "ip-address": "192.0.2.206"
        }]
    }]
},

"Logging":{
  "loggers": [{
        "name": "kea-dhcp4",
        "output_options": [{
                "output": "/usr/local/var/log/kea-dhcp4.log"
            }],        
        "severity": "INFO",        
        "debuglevel": 0
    }]
}
}

你可能感兴趣的:(DHCP)