vlambda博客
学习文章列表

U004-【Ubuntu】局域网地址动态分配案例

学习目标

  • 了解案例任务要求

  • 掌握任务的配置步骤和方法

一、任务要求

    • 服务端(双网卡)操作系统选用Linux,客户端中有50台是Windows系统,还有50台是Linux系统。

二、确认和调整实验环境

1、确认添加新网卡

(1)增加网卡

(2)连接vmnet10

U004-【Ubuntu】局域网地址动态分配案例

(3)确认添加成功

 root@dhcpserver:~# ip address show
 1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN group default qlen 1000
    link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
    inet 127.0.0.1/8 scope host lo
        valid_lft forever preferred_lft forever
    inet6 ::1/128 scope host
        valid_lft forever preferred_lft forever
 2: ens32: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc fq_codel state UP group default qlen 1000
    link/ether 00:0c:29:b9:63:e6 brd ff:ff:ff:ff:ff:ff
    inet 10.0.0.100/24 brd 10.0.0.255 scope global ens32
        valid_lft forever preferred_lft forever
    inet6 fe80::20c:29ff:feb9:63e6/64 scope link
        valid_lft forever preferred_lft forever
 3: ens35: <BROADCAST,MULTICAST> mtu 1500 qdisc noop state DOWN group default qlen 1000
    link/ether 00:0c:29:b9:63:f0 brd ff:ff:ff:ff:ff:ff

2、确认IP地址配置

(1)IP地址配置

 root@dhcpserver:~# vim /etc/netplan/00-installer-config.yaml
 network:
  ethernets:
    ens32:
      addresses:
      - 10.0.0.100/24
      gateway4: 10.0.0.2
      nameservers:
        addresses:
        - 114.114.114.114
        search: []
    ens35:
      addresses:
      - 192.168.10.11/24
      gateway4: 192.168.10.254
      nameservers:
        addresses:
        - 114.114.114.114
        search: []
  version: 2
 


(2)确认地址生效

 root@dhcpserver:~# netplan apply
 
 root@dhcpserver:~# ip address show
 1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN group default qlen 1000
    link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
    inet 127.0.0.1/8 scope host lo
        valid_lft forever preferred_lft forever
    inet6 ::1/128 scope host
        valid_lft forever preferred_lft forever
 2: ens32: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc fq_codel state UP group default qlen 1000
    link/ether 00:0c:29:b9:63:e6 brd ff:ff:ff:ff:ff:ff
    inet 10.0.0.100/24 brd 10.0.0.255 scope global ens32
        valid_lft forever preferred_lft forever
    inet6 fe80::20c:29ff:feb9:63e6/64 scope link
        valid_lft forever preferred_lft forever
 3: ens35: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc fq_codel state UP group default qlen 1000
    link/ether 00:0c:29:b9:63:f0 brd ff:ff:ff:ff:ff:ff
    inet 192.168.10.11/24 brd 192.168.10.255 scope global ens35
        valid_lft forever preferred_lft forever
    inet6 fe80::20c:29ff:feb9:63f0/64 scope link
        valid_lft forever preferred_lft forever

3、确认服务器软件包已安装

 root@dhcpserver:~# dpkg-query --list | grep -o isc-dhcp-server
 isc-dhcp-server

三、服务配置

1、修改配置文件

 root@dhcpserver:~# vim /etc/dhcp/dhcpd.conf 
 option domain-name "example.org";
 option domain-name-servers ns1.example.org, ns2.example.org;
 default-lease-time 600;
 max-lease-time 7200;
 ddns-update-style none;
 subnet 192.168.10.0 netmask 255.255.255.0 {
  range 192.168.10.51 192.168.10.150;
  option domain-name-servers 114.114.114.114,8.8.8.8;
  option domain-name "haoge.com";
  option routers 192.168.10.254;
  default-lease-time 86400;
  max-lease-time 259200;
 }
 host BOSS { ##绑定地址的主机
  hardware ethernet 00:0C:29:D3:98:5C; ##主机MAC地址
  fixed-address 192.168.10.188; ##绑定IP地址
 }

四、服务启动

1、服务启动

 root@dhcpserver:~# systemctl restart isc-dhcp-server.service

2、服务状态

 root@dhcpserver:~# systemctl status isc-dhcp-server.service 
 ● isc-dhcp-server.service - ISC DHCP IPv4 server
    Loaded: loaded (/lib/systemd/system/isc-dhcp-server.service; enabled; vendor preset: enabled)
    Active: active (running) since Wed 2021-12-15 11:51:15 CST; 4s ago
      Docs: man:dhcpd(8)
  Main PID: 15235 (dhcpd)
    Tasks: 1 (limit: 4629)
    CGroup: /system.slice/isc-dhcp-server.service
            └─15235 dhcpd -user dhcpd -group dhcpd -f -4 -pf /run/dhcp-server/dhcpd.pid -cf /etc/dhcp/dhcpd.conf

3、服务监听端口

 root@dhcpserver:~# netstat -tunlp | grep 67
 udp       0     0 0.0.0.0:67             0.0.0.0:*                           15235/dhcpd

4、服务进程

 root@dhcpserver:~# ps -ef | grep dhcpd | grep -v grep
 dhcpd     15235     1 0 11:51 ?       00:00:00 dhcpd -user dhcpd -group dhcpd -f -4 -pf /run/dhcp-server/dhcpd.pid -cf /etc/dhcp/dhcpd.conf

五、服务验证

1、Windows客户端

(1)客户端网络连接

U004-【Ubuntu】局域网地址动态分配案例

(2)获取地址

2、Linux客户端

(1)客户端网络连接

(2)获取地址

 root@client:~# cat /etc/netplan/01-network-manager-all.yaml 
 # Let NetworkManager manage all devices on this system
 network:
  ethernets:
    ens32:
      dhcp4: yes
  version: 2
  • 确认地址
 root@client:~# ip address show
 1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN group default qlen 1000
    link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
    inet 127.0.0.1/8 scope host lo
        valid_lft forever preferred_lft forever
    inet6 ::1/128 scope host
        valid_lft forever preferred_lft forever
 2: ens32: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc fq_codel state UP group default qlen 1000
    link/ether 00:0c:29:7c:87:4c brd ff:ff:ff:ff:ff:ff
    inet 192.168.10.53/24 brd 192.168.10.255 scope global dynamic ens32
        valid_lft 86311sec preferred_lft 86311sec
    inet6 fe80::cb06:effd:e165:c673/64 scope link noprefixroute
        valid_lft forever preferred_lft forever
  • 确认网关
 root@client:~# route -n
 Kernel IP routing table
 Destination     Gateway         Genmask         Flags Metric Ref   Use Iface
 0.0.0.0         192.168.10.254 0.0.0.0         UG   100   0       0 ens32
 192.168.10.0   0.0.0.0         255.255.255.0   U     0     0       0 ens32
 192.168.10.0   0.0.0.0         255.255.255.0   U     100   0       0 ens32
 192.168.10.254 0.0.0.0         255.255.255.255 UH   100   0       0 ens32
  • 确认DNS
 root@client:~# systemd-resolve --status
 Global
          DNS Servers: 114.114.114.114
                      8.8.8.8
          DNS Domain: haoge.com
 
 Link 2 (ens32)
      Current Scopes: DNS
        LLMNR setting: yes
 MulticastDNS setting: no
      DNSSEC setting: no
    DNSSEC supported: no
          DNS Servers: 114.114.114.114
                      8.8.8.8
          DNS Domain: haoge.com