Ubuntu搭建dhcpv6服务器来分配IP给路由器/电脑,比较常用的就是isc-dhcp(Internet Systems Consortium)
1. 安装isc-dhcp服务器
isc的官网:http://www.isc.org/software/dhcp/
上去找到最新的版本,如dhcp-4.2.1.tar.gz,下载后在 Ubuntu上编译安装。
命令如下:
先解压dhcp-4.2.1.tar.gz ,命令tar -xzf dhcp-4.2.1.tar.gz
然后进到该目录下,执行下列的命令:
# ./configure
# make
# sudo make install
2. 配置isc-dhcp服务器参数
安装完后,建一个文件/etc/dhcp/dhcpd6.conf,添加配置内容
default-lease-time 600;
max-lease-time 7200;
log-facility local7;
subnet6 2001:db8:0:1::/64 {
# Range for clients
range6 2001:db8:0:1::129 2001:db8:0:1::254;
# Range for clients requesting a temporary address
range6 2001:db8:0:1::/64 temporary;
# Additional options
option dhcp6.name-servers fec0:0:0:1::1;
option dhcp6.domain-search "domain.example";
# Prefix range for delegation to sub-routers
prefix6 2001:db8:0:100:: 2001:db8:0:f00:: /56;
# Example for a fixed host address
host specialclient {
host-identifier option dhcp6.client-id 00:01:00:01:4a:1f:ba:e3:60:b9:1f:01:23:45;
fixed-address6 2001:db8:0:1::127;
}
}
配置里面的参数都有各自的含义
然后在 /var/db下添加一个空文件dhcpd6.leases
sudo touch /var/db/dhcpd6.leases
查看网卡的信息为eth0
linye@ubuntu:/$ ifconfig
eth0 Link encap:Ethernet HWaddr 00:0c:29:75:a2:91
inet addr:192.168.62.128 Bcast:192.168.62.255 Mask:255.255.255.0
inet6 addr: fe80::20c:29ff:fe75:a291/64 Scope:Link
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
RX packets:23242 errors:0 dropped:0 overruns:0 frame:0
TX packets:22975 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:1847101 (1.8 MB) TX bytes:51394431 (51.3 MB)
3. 启动、停止
在运行 ISC-DHCP之前,你需要把eth0接口地址设置成上面subnet6网段2001:db8:0:1::/64
的信息,这样才可以分配地址给下面的设备,如下:
sudo ifconfig eth0 add 2001:db8:0:1::1/64
linye@ubuntu:/$ ifconfig
eth0 Link encap:Ethernet HWaddr 00:0c:29:75:a2:91
inet addr:192.168.62.128 Bcast:192.168.62.255 Mask:255.255.255.0
inet6 addr: fe80::20c:29ff:fe75:a291/64 Scope:Link
inet6 addr: 2001:db8:0:1::1/64 Scope:Global
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
RX packets:23347 errors:0 dropped:0 overruns:0 frame:0
TX packets:23004 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:1854962 (1.8 MB) TX bytes:51398868 (51.3 MB)
然后启动dhcpv6服务器:
linye@ubuntu:/$ sudo dhcpd -6 -cf /etc/dhcp/dhcpd6.conf eth0
Internet Systems Consortium DHCP Server 4.4.2
Copyright 2004-2020 Internet Systems Consortium.
All rights reserved.
For info, please visit https://www.isc.org/software/dhcp/
WARNING: Host declarations are global. They are not limited to the scope you declared them in.
Config file: /etc/dhcp/dhcpd6.conf
Database file: /var/db/dhcpd6.leases
PID file: /var/run/dhcpd6.pid
Wrote 0 deleted host decls to leases file.
Wrote 0 new dynamic host decls to leases file.
Wrote 1 NA, 0 TA, 0 PD leases to lease file.
Bound to *:547
Listening on Socket/6/eth0/2001:db8:0:1::/64
Sending on Socket/6/eth0/2001:db8:0:1::/64
linye@ubuntu:/$ ps -aux| grep dhcp
root 4649 0.4 0.1 12540 4504 ? Ss 17:54 0:00 dhcpd -6 -cf /etc/dhcp/dhcpd6.conf eth0
linye 4651 0.0 0.0 15944 932 pts/0 S+ 17:54 0:00 grep --color=auto dhcp
停止的话需要手动kill这个进程
killall dhcpd
将ubuntu服务器的eth0网口接到另一台电脑,查看是否获取到正常的IPv6地址
如果不行看下防火墙的状态,如果是开启的则关闭下:
linye@ubuntu:/$ sudo ufw disable
linye@ubuntu:/$ sudo ufw status
Status: inactive
当有设备从服务器获取到ipv6地址后,可以在/var/db/dhcpd6.leases下查看到设备信息
网友评论