【DHCP Server】ubuntu18.4安装DHCP server服务

参考连接:Ubuntu LTS 18.04 配置DHCP Server

 

1.安装dhcp服务

root@liuting:~# apt install isc-dhcp-server

 

2.修改网卡配置

root@liuting:~# vim /etc/netplan/50-cloud-init.yaml

network:

    ethernets:

        ens160:

            addresses:

            - 172.20.80.183/16

            gateway4: 172.20.0.1

            nameservers:

                addresses:

                - 8.8.8.8

        ens192:

            dhcp4: false

            addresses:

            - 22.22.22.1/24

version: 2

root@liuting:~# netplan apply

 

3.修改 /etc/default/isc-dhcp-serve

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

修改如下值:

INTERFACESv4="ens192"

 

4.配置DHCP Server

root@liuting:~# vim /etc/dhcp/dhcpd.conf

配置域名和域名服务器:

option domain-name "www.baidu.com";

option domain-name-servers 8.8.8.8,114.114.114.114;

# 配置租期:

default-lease-time 6000;

max-lease-time 7200;

# 取消如下注释:

authoritative;

# 配置子网配置,可直接粘贴到文档末尾:

subnet 22.22.22.0 netmask 255.255.255.0 {

   range 22.22.22.100 22.22.22.200;

   option routers 22.22.22.1;

   option subnet-mask 255.255.255.0;

}

 

5.重启服务

root@liuting:~# systemctl enable isc-dhcp-server    #开机自启动

root@liuting:~# systemctl restart isc-dhcp-server    # 重启服务

查看服务进程是否启动:

root@liuting:~# netstat -aunp | grep dhcpd

udp        0      0 0.0.0.0:63202           0.0.0.0:*                           11509/dhcpd        

udp        0      0 0.0.0.0:67              0.0.0.0:*                           11509/dhcpd        

udp6       0      0 :::30033                :::*                               11509/dhcpd        

 

6.验证

拓扑:DHCP Server(Linux虚拟机网卡ens192)-----直连-------DHCP Client(交换机48口)

 

交换机直连接口配置:

interface eth-0-48

  no switchport

  ip address dhcp

 

在虚拟机抓包查看dhcp报文:

root@liuting:~# tcpdump -nei ens192

08:38:38.610235 66:66:66:66:66:66 > ff:ff:ff:ff:ff:ff, ethertype IPv4 (0x0800), length 356: 0.0.0.0.68 > 255.255.255.255.67: BOOTP/DHCP, Request from 66:66:66:66:66:66, length 314

08:38:38.610733 00:50:56:b2:0e:c8 > 66:66:66:66:66:66, ethertype IPv4 (0x0800), length 62: 22.22.22.1 > 22.22.22.100: ICMP echo request, id 41823, seq 0, length 28

08:38:39.612730 00:50:56:b2:0e:c8 > ff:ff:ff:ff:ff:ff, ethertype IPv4 (0x0800), length 342: 22.22.22.1.67 > 255.255.255.255.68: BOOTP/DHCP, Reply, length 300

08:38:39.613618 66:66:66:66:66:66 > ff:ff:ff:ff:ff:ff, ethertype IPv4 (0x0800), length 368: 0.0.0.0.68 > 255.255.255.255.67: BOOTP/DHCP, Request from 66:66:66:66:66:66, length 326

08:38:39.620899 00:50:56:b2:0e:c8 > ff:ff:ff:ff:ff:ff, ethertype IPv4 (0x0800), length 342: 22.22.22.1.67 > 255.255.255.255.68: BOOTP/DHCP, Reply, length 300

08:38:39.644349 66:66:66:66:66:66 > ff:ff:ff:ff:ff:ff, ethertype ARP (0x0806), length 60: Request who-has 22.22.22.100 (ff:ff:ff:ff:ff:ff) tell 22.22.22.100, length 46

08:38:39.644391 66:66:66:66:66:66 > ff:ff:ff:ff:ff:ff, ethertype ARP (0x0806), length 60: Request who-has 22.22.22.1 tell 22.22.22.100, length 46

08:38:39.644403 00:50:56:b2:0e:c8 > 66:66:66:66:66:66, ethertype ARP (0x0806), length 42: Reply 22.22.22.1 is-at 00:50:56:b2:0e:c8, length 28

08:38:43.645098 00:50:56:b2:0e:c8 > 66:66:66:66:66:66, ethertype ARP (0x0806), length 42: Request who-has 22.22.22.100 tell 22.22.22.1, length 28

08:38:43.645769 66:66:66:66:66:66 > 00:50:56:b2:0e:c8, ethertype ARP (0x0806), length 60: Reply 22.22.22.100 is-at 66:66:66:66:66:66, length 46

 

在虚拟机查看已经分配的地址:

root@liuting:~# dhcp-lease-list

Reading leases from /var/lib/dhcp/dhcpd.leases

MAC                IP              hostname       valid until         manufacturer       

============================================================================================

66:66:66:66:66:66  22.22.22.100    ting13     2020-07-16 08:58:39      -NA-               

 

交换机上查看分配到的地址:

switch# show dhcp client verbose

DHCP client informations:

============================================================

eth-0-48 DHCP client information:

  Current state: BOUND

  Allocated IP: 22.22.22.100 255.255.255.0

  Lease/renewal/rebinding: 1188/461/1038 seconds

  Lease from 2020-07-16 08:55:43 to 2020-07-16 09:15:43

  Will Renewal in 0 days 0 hours 7 minutes 41 seconds

  DHCP server: 22.22.22.1

  Transaction ID: 0x58953f43

  Default router: 22.22.22.1

  Client ID: switch-6666.6666.6666-eth-0-48

 

你可能感兴趣的:(CCNA)