Phần 1: Cài đặt và cấu hình Kea DHCPv4
- Cài đặt
Installation:
• curl -1sLf 'https://dl.cloudsmith.io/public/isc/kea-1-6/cfg/setup/bash.deb.sh' | sudo -E bash
• apt install kea-dhcp4-server kea-admin
- Cấu hình:
lab@lab:~$ cd /etc/kea/
lab@lab:/etc/kea$ ll
lab@lab:/etc/kea$ /etc/kea$ grep -v // kea-dhcp4.conf (thực hiện loại bỏ dòng ghi chú chứa "//")
{
"Dhcp4": {
"interfaces-config": {
"interfaces": ["ens33"]
},
"control-socket": {
"socket-type": "unix",
"socket-name": "/tmp/kea-dhcp4-ctrl.sock"
},
"lease-database": {
"type": "mysql",
"name": "james_kea",
"host": "",
"port": 3306,
"user": "james",
"password": "james"
},
"hosts-database": {
"type": "mysql",
"name": "james_kea",
"user": "james",
"password": "james",
"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
},
"renew-timer": 900,
"rebind-timer": 1800,
"valid-lifetime": 3600,
"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"
}
],
"hooks-libraries": [
{
"library": "/usr/lib/x86_64-linux-gnu/kea/hooks/libdhcp_lease_cmds.so"
}
],
"subnet4": [
{
"subnet": "192.0.2.0/24",
"pools": [ { "pool": "192.0.2.1 - 192.0.2.200" }],
"option-data": [
{
"name": "routers",
"data": "192.0.2.1"
}
],
"reservations": [
{
"hw-address": "1a:1b:1c:1d:1e:1f",
"ip-address": "192.0.2.201"
},
{
"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"
}
]
},
{
"subnet": "192.0.4.0/24",
"pools": [ { "pool": "192.0.4.1 - 192.0.4.200" }],
"option-data": [
{
"name": "routers",
"data": "192.0.4.1"
}
]
}
],
"loggers": [
{
"name": "kea-dhcp4",
"output_options": [
{
"output": "/var/log/kea/kea-dhcp4.log"
}
],
"severity": "INFO",
"debuglevel": 0
}
]
}
}
Phần 2: Cài đặt và cấu hình Kea DHCPv6
- Cài đặt:
Step 1
sudo apt-get update -y
Step 2
sudo apt-get install -y kea-dhcp6-server
- Cấu hình:
lab@lab:/etc/kea$ grep -v // kea-dhcp6.conf
{
"Dhcp6": {
"interfaces-config": {
"interfaces": ["ens33/2a01:7c8:aab5:4cd::2" ]
},
"control-socket": {
"socket-type": "unix",
"socket-name": "/tmp/kea6-ctrl-socket"
},
"lease-database": {
"type": "mysql",
"name": "james_kea",
"host": "",
"port": 3306,
"user": "james",
"password": "james"
},
"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
},
"renew-timer": 1000,
"rebind-timer": 2000,
"preferred-lifetime": 3000,
"valid-lifetime": 4000,
"option-data": [
{
"name": "dns-servers",
"data": "2001:db8:2::45, 2001:db8:2::100"
},
{
"code": 12,
"data": "2001:db8::1"
},
{
"name": "new-posix-timezone",
"data": "EST5EDT4\\,M3.2.0/02:00\\,M11.1.0/02:00"
},
{
"name": "preference",
"data": "0xf0"
},
{
"space": "s46-cont-mapt-options",
"name": "s46-dmr",
"data": "2001:db8:cafe::/64"
},
{
"name": "bootfile-param",
"data": "root=/dev/sda2, quiet, splash"
}
],
"subnet6": [
{
"subnet": "2001:db8:1::/64",
"rapid-commit": true,
"pools": [ { "pool":"2001:db8:1::200-2001:db8:1::800"} ],
"interface": "ens33",
"pd-pools": [
{
"prefix": "2001:db8:1:8000::",
"prefix-len": 56,
"delegated-len": 64
}
],
"option-data": [
{
"name": "dns-servers",
"data": "2001:db8:2::dead:beef, 2001:db8:2::cafe:babe"
}
],
"reservations": [
{
"hw-address": "AA:BB:CC:01:C0:00",
"ip-addresses": [ "2001:db8:2::2001" ],
"prefixes": [ "2001:db8:1::/64" ]
},
{
"duid": "01:02:03:04:05:0A:0B:0C:0D:0E",
"ip-addresses": [ "2001:db8:1::100" ]
},
{
"hw-address": "00:01:02:03:04:05",
"ip-addresses": [ "2001:db8:1::101" ],
"option-data": [
{
"name": "dns-servers",
"data": "3000:1::234"
},
{
"name": "nis-servers",
"data": "3000:1::234"
}],
"client-classes": [ "special_snowflake", "office" ]
},
{
"duid": "01:02:03:04:05:06:07:08:09:0A",
"ip-addresses": [ "2001:db8:1:0:cafe::1" ],
"prefixes": [ "2001:db8:2:abcd::/64" ],
"hostname": "foo.example.com",
"option-data": [
{
"name": "vendor-opts",
"data": "4491"
},
{
"name": "tftp-servers",
"space": "vendor-4491",
"data": "3000:1::234"
}
]
},
{
"flex-id": "'somevalue'",
"ip-addresses": [ "2001:db8:1:0:cafe::2" ]
}
]
},
{
"subnet": "2001:db8:2::/64",
"pools": [ { "pool":"2001:db8:2::200-2001:db8:2::800"} ],
"interface": "ens33"
}
],
"loggers": [
{
"name": "kea-dhcp6",
"output_options": [
{
"output": "@localstatedir@/log/kea-dhcp6.log"
}
],
"severity": "INFO",
"debuglevel": 0
}
]
}
}
Phần 3: Cài đặt và cấu hình MySQL Server
- Cài đặt
sudo apt update
Then install the mysql-server package:
sudo apt install mysql-server
Ensure that the server is running using the systemctl start command:
sudo systemctl start mysql.service
- Cấu hình
Log into MySQL as “root”:
$ mysql -u root -p
mysql>
Create the MySQL database:
mysql> CREATE DATABASE james_kea;
(database_name is the name chosen for the database.)
mysql> CREATE USER 'james'@'localhost' IDENTIFIED BY 'james';
mysql> GRANT ALL ON james_kea.* TO 'james'@'localhost';
Create the database.
Exit the MySQL client
mysql> quit
Bye
Then use the kea-admin tool to create the database.
$ kea-admin db-init mysql -u database-user -p database-password -n database-name
mysql> set @@global.log_bin_trust_function_creators = 1;
Query OK, 0 rows affected (0.00 sec)
To create the database with MySQL directly, follow these steps:
mysql> CONNECT james_kea;
mysql> SOURCE path-to-kea/share/kea/scripts/mysql/dhcpdb_create.mysql
(where “path-to-kea” is the location where Kea is installed.)
example: SOURCE /usr/share/kea/scripts/mysql/dhcpdb_create.mysql
The database may also be dropped manually as follows:
mysql> CONNECT james_kea;
mysql> SOURCE path-to-kea/share/kea/scripts/mysql/dhcpdb_drop.mysql
(where “path-to-kea” is the location where Kea is installed.)
Warning
Dropping the database results in the unrecoverable loss of any data it contains.
Exit MySQL:
mysql> quit
Bye
Nguồn: https://kea.readthedocs.io/en/kea-2.0.0/arm/admin.html
Phần 4: Bật và kiểm tra trạng thái dịch vụ DHCPv4, DHCPv6
- Bật
systemctl start kea-dhcp4-server.service //dhcpv4
systemctl start kea-dhcp6-server.service //dhcpv6
- Trạng thái
systemctl status kea-dhcp4-server.service //dhcpv4
systemctl status kea-dhcp4-server.service //dhcpv6
- Khởi động lại
systemctl restart kea-dhcp4-server.service //dhcpv4
systemctl restart kea-dhcp4-server.service //dhcpv6
- Kiểm tra log
tail -f /var/log/syslog | grep kea
Phần 5: Kiểm tra danh sách IPv4, IPv6 được cấp phát
mysql> show databases;
+--------------------+
| Database |
+--------------------+
| information_schema |
| james_kea |
| mysql |
| performance_schema |
| sys |
+--------------------+
mysql> use james_kea
mysql> show tables;
mysql> select inet_ntoa(address), hwaddr, valid_lifetime, subnet_id from lease4;
mysql> select hostname,address, hwaddr,prefix_len, valid_lifetime, subnet_id, expire from lease6;
Ghi chú:
- Client sẽ nhận được IPv4 do dhcp4 cấp gồm cả IP và subnet như thiết lập trên DHCP (ví dụ subnet /24)
- Client sẽ nhận được IPv6 với do dhcp6 với prefix /128 (không giống như prefix /64 đã thiết lập). Client sẽ giao tiếp thông qua IPv6 template hoặc ipv6 (stateless khác) ( như client windows 10)
- Đối với các node là interface thiết bị như interface router (giả lập client) để giao tiếp được cần cấu hình nhận IPv6 ở 2 chế độ là autoconfig và dhcp.
Phần 6: Ứng dụng cấp phát trong mô hình sau
Nhận xét
Đăng nhận xét