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下查看到設備信息