问题

学习 openstack 和 openvswitch 过程中, 遇到dhclient 卡死,而且也分配不了地址,于是只能先学习 dhcp 服务器和 dhclient

还使用之前 Ubuntu 20.04 手动安装OpenStack 搭建的一个假的网关 (203.0.113.1),之前是 2 个网卡,现在增加一个eth2 ,用于直接在本机先测试

环境

Ubuntu 20.04 虚拟机
eth0 : 192.168.0.109 (用于远程管理)
eth1 : 203.0.113.1 (网关)
eth2 : 用于dhclient 测试

搭建DHCP 服务器

Ubuntu 官方文档 Networking

这是服务端安装
Dynamic Host Configuration Protocol (DHCP)

这是网卡配置 (客户端)
Network Configuration

ISC DHCP 官网

抄录并整理一下步骤

  1. sudo apt install isc-dhcp-server

  2. 修改配置

    root@gate-109:/etc/dhcp# vim /etc/dhcp/dhcpd.conf

     ......
     # wzh 20221212
     subnet 203.0.113.0 netmask 255.255.255.0 {
        range  203.0.113.10   203.0.113.100;
        option routers                  203.0.113.1;
        option subnet-mask              255.255.255.0;
        # option domain-search            "local.tecadmin.net";
        # option domain-name-servers      n1.local.tecadmin.net;
        option domain-search            "";
        option domain-name-servers      203.0.113.1;
     
        option time-offset              -18000;
        option broadcast-address 203.0.113.255;
        default-lease-time 600;
        max-lease-time 7200;
     }
     ......
    

    卡死的原因在于 : local.tecadmin.net 找不到!
    后面错误处理再叙述

  3. dhcp 服务网卡指定 (ubuntu 文档中没有)

    root@gate-109:/etc/netplan# vim /etc/default/isc-dhcp-server
    修改最后两行

     # wzh 20221212
     INTERFACESv4="eth1"
     INTERFACESv6="eth1"
    
  4. 重启生效
    sudo systemctl restart isc-dhcp-server.service

  5. 确认
    root@gate-109:/etc/netplan# netstat -tulnp | grep dhcp

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

dhclient 客户端

  1. 最终效果
    root@gate-109:/etc/dhcp# ip addr show eth2

     4: eth2: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc mq state UP group default qlen 1000
         link/ether 00:15:5d:5a:a6:95 brd ff:ff:ff:ff:ff:ff
         inet 203.0.113.12/24 brd 203.0.113.255 scope global dynamic eth2
            valid_lft 308sec preferred_lft 308sec
         inet6 fe80::215:5dff:fe5a:a695/64 scope link 
            valid_lft forever preferred_lft forever
    
  2. 不管 dhclient 是否卡死,好像一直在执行

    root@gate-109:/etc/dhcp# ps -ef |grep dhc

     dhcpd        818       1  0 09:12 ?        00:00:00 dhcpd -user dhcpd -group dhcpd -f -4 -pf /run/dhcp-server/dhcpd.pid -cf /etc/dhcp/dhcpd.conf eth1
     root        1662       1  0 10:21 ?        00:00:00 dhclient eth2
     root        1823       1  0 10:43 ?        00:00:00 dhclient eth2
     root        1850       1  0 10:43 ?        00:00:00 dhclient eth2
     root        1885    1499  0 10:47 pts/1    00:00:00 grep --color=auto dhc
    
  3. 执行到 3 次以后,就不再分配了,继续执行就会这样
    root@gate-109:/etc/netplan# dhclient eth2

     RTNETLINK answers: File exists
    

    所以,他从 203.0.113.10/24 开始,执行了 3 次,就变成 203.0.113.12/24

错误处理

  1. Not configured to listen on any interfaces!

    root@ubuntu2004-121:/home/dhbm# systemctl status isc-dhcp-server

     ● isc-dhcp-server.service - ISC DHCP IPv4 server
          Loaded: loaded (/lib/systemd/system/isc-dhcp-server.service; enabled; vendor preset: enabled)
          Active: failed (Result: exit-code) since Mon 2022-12-12 14:12:25 CST; 2min 20s ago
            Docs: man:dhcpd(8)
         Process: 26013 ExecStart=/bin/sh -ec      CONFIG_FILE=/etc/dhcp/dhcpd.conf;      if [ -f /etc/ltsp/dhcpd.conf ]; then CONFIG_FILE=/etc/ltsp/dhcpd.conf; fi;      [ -e /var/lib/dhcp/dhcpd.leases ] ||>
        Main PID: 26013 (code=exited, status=1/FAILURE)
     
     Dec 12 14:12:25 gate-109 dhcpd[26013]: 
     Dec 12 14:12:25 gate-109 dhcpd[26013]: Not configured to listen on any interfaces!
     Dec 12 14:12:25 gate-109 dhcpd[26013]: 
     Dec 12 14:12:25 gate-109 dhcpd[26013]: If you think you have received this message due to a bug rather
     Dec 12 14:12:25 gate-109 dhcpd[26013]: than a configuration issue please read the section on submitting
     Dec 12 14:12:25 gate-109 dhcpd[26013]: bugs on either our web page at www.isc.org or in the README file
     Dec 12 14:12:25 gate-109 dhcpd[26013]: before submitting a bug.  These pages explain the proper
     Dec 12 14:12:25 gate-109 dhcpd[26013]: process and the information we find helpful for debugging.
     Dec 12 14:12:25 gate-109 dhcpd[26013]: 
     Dec 12 14:12:25 gate-109 dhcpd[26013]: exiting.
     ......
    

    处理:
    记不太清楚了!大概是修改正确的 IP 地址网段,开始时我好像是设置的 10.0.0.0/24 ,但是 DHCP 服务在 203.0.113.0/24

  2. Not configured to listen on any interfaces!

    root@ubuntu2004-121:/home/dhbm# systemctl status isc-dhcp-server

     Dec 12 14:12:25 gate-109 dhcpd[26027]: 
     Dec 12 14:12:25 gate-109 dhcpd[26027]: Not configured to listen on any interfaces!
     Dec 12 14:12:25 gate-109 dhcpd[26027]: 
     Dec 12 14:12:25 gate-109 dhcpd[26027]: If you think you have received this message due to a bug rather
     Dec 12 14:12:25 gate-109 dhcpd[26027]: than a configuration issue please read the section on submitting
     Dec 12 14:12:25 gate-109 dhcpd[26027]: bugs on either our web page at www.isc.org or in the README file
     Dec 12 14:12:25 gate-109 dhcpd[26027]: before submitting a bug.  These pages explain the proper
     Dec 12 14:12:25 gate-109 dhcpd[26027]: process and the information we find helpful for debugging.
     Dec 12 14:12:25 gate-109 dhcpd[26027]: 
     Dec 12 14:12:25 gate-109 dhcpd[26027]: exiting.
    

    处理:
    dhcp 服务网卡指定

    root@gate-109:/etc/netplan# vim /etc/default/isc-dhcp-server
    修改最后两行

     # wzh 20221212
     INTERFACESv4="eth1"
     INTERFACESv6="eth1"
    
  3. dhclient 卡死
    开始时总想找到 dhclient 的 error 日志,所以就 grep

    root@gate-109:/var/log# grep -nr dhc * 
    
    root@gate-109:/var/log# grep -nr "n1.local.tecadmin.net" * 
    

    也找到了问题出在 n1.local.tecadmin.ne

    其实,最简单还是 journalctl -xe ,也看到了 问题出在 n1.local.tecadmin.ne

    root@gate-109:/var/log# journalctl -xe

    	Dec 13 09:32:47 gate-109 dhcpd[818]: DHCPREQUEST for 203.0.113.10 from 00:15:5d:5a:a6:91 (ubuntu2004-101) via eth1
    	Dec 13 09:32:48 gate-109 systemd-resolved[721]: Using degraded feature set (UDP) for DNS server 223.5.5.5.
    	Dec 13 09:32:52 gate-109 systemd-resolved[721]: Using degraded feature set (TCP) for DNS server 114.114.114.114.
    	Dec 13 09:32:55 gate-109 systemd-resolved[721]: Using degraded feature set (TCP) for DNS server 223.5.5.5.
    	Dec 13 09:32:57 gate-109 dhcpd[818]: n1.local.tecadmin.net: temporary name server failure
    	Dec 13 09:32:57 gate-109 dhcpd[818]: DHCPACK on 203.0.113.10 to 00:15:5d:5a:a6:91 (ubuntu2004-101) via eth1
    	Dec 13 09:33:01 gate-109 systemd-resolved[721]: Using degraded feature set (TCP) for DNS server 114.114.114.114.
    	Dec 13 09:33:04 gate-109 systemd-resolved[721]: Using degraded feature set (UDP) for DNS server 114.114.114.114.
    	Dec 13 09:33:04 gate-109 systemd-resolved[721]: Using degraded feature set (UDP) for DNS server 223.5.5.5.
    	Dec 13 09:33:07 gate-109 systemd-resolved[721]: Using degraded feature set (TCP) for DNS server 223.5.5.5.
    	Dec 13 09:33:10 gate-109 systemd-resolved[721]: Using degraded feature set (UDP) for DNS server 114.114.114.114.
    	Dec 13 09:33:19 gate-109 systemd-resolved[721]: Using degraded feature set (TCP) for DNS server 223.5.5.5.
    	Dec 13 09:33:22 gate-109 systemd-resolved[721]: Using degraded feature set (TCP) for DNS server 114.114.114.114.
    	Dec 13 09:33:25 gate-109 systemd-resolved[721]: Using degraded feature set (UDP) for DNS server 223.5.5.5.
    	Dec 13 09:33:28 gate-109 systemd-resolved[721]: Using degraded feature set (TCP) for DNS server 114.114.114.114.
    	Dec 13 09:33:38 gate-109 systemd-resolved[721]: Using degraded feature set (UDP) for DNS server 223.5.5.5.
    	Dec 13 09:33:41 gate-109 systemd-resolved[721]: Using degraded feature set (UDP) for DNS server 114.114.114.114.
    	Dec 13 09:33:44 gate-109 systemd-resolved[721]: Using degraded feature set (TCP) for DNS server 223.5.5.5.
    	Dec 13 09:33:47 gate-109 systemd-resolved[721]: Using degraded feature set (UDP) for DNS server 114.114.114.114.
    

分析 :
过去配置静态 ip 时,最后总是 search: [],从来没有想过为什么
既然 search: [] 可以,那么干脆配置文件中也空,不用 n1.local.tecadmin.net

处理:

修改配置

root@gate-109:/etc/dhcp# vim /etc/dhcp/dhcpd.conf
		
	......
	# wzh 20221212
	subnet 203.0.113.0 netmask 255.255.255.0 {
	   range  203.0.113.10   203.0.113.100;
	   option routers                  203.0.0.1;
	   option subnet-mask              255.255.255.0;
	   # option domain-search            "local.tecadmin.net";
	   # option domain-name-servers      n1.local.tecadmin.net;
	   option domain-search            "";
	   option domain-name-servers      203.0.113.1;
	
	   option time-offset              -18000;
	   option broadcast-address 203.0.113.255;
	   default-lease-time 600;
	   max-lease-time 7200;
	}
	......

再来 dhclient eth2 ,立马 OK !哈哈哈哈!

后续

以上使用了第三块卡 eth2 ,并且在本机进行
如果在其他服务器呢?
如果是虚拟机呢?
待继续…

Logo

有“AI”的1024 = 2048,欢迎大家加入2048 AI社区

更多推荐