例说图解TCP/IP协议族--DHCP篇(5)搭建DHCP服务器【Ubuntu 18.04版】

    DHCP服务器可以是专业的硬件设备,也可以允许在操作系统上的一个服务。本文的DHCP服务器就直接采用Ubuntu 18.04上的ISC-DHCP-Server来完成。

    关于ISC-DHCP-Server需要注意下,该软件的进程名、服务名、侦听端口、配置文件如下表所示(方便自动化测试脚本去控制)。

DHCP版本 进程名 服务名 侦听端口 配置文件
DHCPv4 dhcpd isc-dhcp-server 67/udp /etc/dhcp/dhcpd.conf
DHCPv6 dhcpd isc-dhcp-server6 547/udp /etc/dhcp/dhcpd6.conf

 

1 在Ubuntu 18.04上安装DHCP服务器

root@caowen-ubuntu:~# apt update

root@caowen-ubuntu:~# apt install -y isc-dhcp-server

root@caowen-ubuntu:~# apt list -a isc-dhcp-server

2 修改dhcpd进程监听的网卡,无论服务器一张网卡还是多张网卡

root@caowen-ubuntu:~# vim /etc/default/isc-dhcp-server

    修改后内容如下

# Defaults for isc-dhcp-server (sourced by /etc/init.d/isc-dhcp-server)
  
# Path to dhcpd's config file (default: /etc/dhcp/dhcpd.conf).
#DHCPDv4_CONF=/etc/dhcp/dhcpd.conf
#DHCPDv6_CONF=/etc/dhcp/dhcpd6.conf

# Path to dhcpd's PID file (default: /var/run/dhcpd.pid).
#DHCPDv4_PID=/var/run/dhcpd.pid
#DHCPDv6_PID=/var/run/dhcpd6.pid

# Additional options to start dhcpd with.
#       Don't use options -cf or -pf here; use DHCPD_CONF/ DHCPD_PID instead
#OPTIONS=""

# On what interfaces should the DHCP server (dhcpd) serve DHCP requests?
#       Separate multiple interfaces with spaces, e.g. "eth0 eth1".
INTERFACESv4="ens33 ens160"
INTERFACESv6="ens33 ens160"

3 DHCPv4配置

    修改DHCPv4的配置文件,执行以下命令。

root@caowen-ubuntu:~# vim /etc/dhcp/dhcpd.conf

    在文件末尾增加自己的配置,原来的配置不要动。

# RFC didn't define option 150 value type,
# so we need to self-define option 150 value type
option op150 code 150 = array of ip-address;

# Local NIC ipv4 address is not located in the following subnet
# The traffic of the following subnet  is from dhcpv4 relay, not real client
subnet 100.101.0.224 netmask 255.255.255.224 {
        range 100.101.0.226 100.101.0.239;

        option routers 100.101.0.254;

        option domain-name "crdc.cisco.com";
        option domain-name-servers 10.74.97.122, 64.104.123.245;

        option op150 10.74.97.123, 10.74.97.126;
}

# Local NIC ipv4 address is located in the following subnet
subnet 10.74.97.112 netmask 255.255.255.240 {

}

    重启服务isc-dhcp-server使之生效。

root@caowen-ubuntu:~# systemctl enable isc-dhcp-server

root@caowen-ubuntu:~# systemctl restart isc-dhcp-server

root@caowen-ubuntu:~# systemctl status isc-dhcp-server

 4 DHCPv6配置

    修改DHCPv6的配置文件,执行以下命令。

root@caowen-ubuntu:~# vim /etc/dhcp/dhcpd6.conf

    在文件末尾增加自己的配置,原来的配置不要动。

# Local NIC ipv6 address is not located in the following subnet
# The traffic of the following subnet  is from dhcpv6 relay, not real client
subnet6 2001:100:101:0::/64 {
        range6 2001:100:101:0::1001 2001:100:101:0::2000;

        option dhcp6.domain-search "crdc.cisco.com";
        option dhcp6.name-servers 2001:10:74:97::122, 2001:10:74:97::125;

        # If client has option of "vendor opts" (global option code is 16),
        # dhcpv6 will response the following option located in global option 17.
        # Enterprise id (0x0000 0009 means Cisco ),
        # Type and Length of Suboption (0x0001 0010 means Type is 1, Length is 16 Bytes),
        # Value of suboption (2001:10:74:97::123) 
         option dhcp6.vendor-opts
                00:00:00:09:
                00:01:00:10:
                20:01:00:10:00:74:00:63:00:00:00:00:00:00:01:23;
}
    
# Local NIC ipv6 address is located in the following subnet
subnet6 2001:10:74:97::/64 { 
    
}

    重启isc-dhcp-server服务使之生效。

root@caowen-ubuntu:~# systemctl enable isc-dhcp-server6

root@caowen-ubuntu:~# systemctl restart isc-dhcp-server6

root@caowen-ubuntu:~# systemctl status isc-dhcp-server6

 

你可能感兴趣的:(#,应用层协议)