dhcpd usage

1,
boot_k_setup.sh:
alarm () {
   echo $1 > $alarm_file
   exit 1
}


brctl addbr  ks      #ks网桥
brctl addif  ks ka   #ka,b,c交换机物理端口
brctl addif  ks kb
brctl addif  ks kc


ip addr add 192.168.253.9/29 brd + dev ks || alarm "-1"
如果没有上一步设置,将会在dhcpd启动时报错:

toor4nsn@lrc7:~# /usr/sbin/dhcpd -f -cf /tmp/dhcpd.conf --no-pid ks
Internet Systems Consortium DHCP Server 4.3.0
Copyright 2004-2014 Internet Systems Consortium.
All rights reserved.
For info, please visit https://www.isc.org/software/dhcp/
Wrote 0 leases to leases file.


No subnet declaration for ks (no IPv4 addresses).
** Ignoring requests on ks.  If this is not what
   you want, please write a subnet declaration
   in your dhcpd.conf file for the network segment
   to which interface ks is attached. **


Not configured to listen on any interfaces!


If you think you have received this message due to a bug rather
than a configuration issue please read the section on submitting
bugs on either our web page at www.isc.org or in the README file
before submitting a bug.  These pages explain the proper
process and the information we find helpful for debugging..



2,
[xiatian@server yocto]$ vim ./meta/recipes-connectivity/dhcp/files/lrc-lsp-axm/start_dhcpd.sh
#!/bin/sh


touch /var/lib/dhcp/dhcpd.leases  #创建空的leases文件, dhcpd每次都会把所有的租借信息写到/var/lib/dhcpd.leases文件中,上一次的租借文件被改名成dhcpd.leases


exec /usr/sbin/dhcpd   -f   -cf   /etc/dhcp/dhcpd.conf   --no-pid   ks     #-cf:指定配置文件, -f:前台执行. 详见http://manpages.ubuntu.com/manpages/precise/man8/dhcpd.8.html




2.1,
/etc/dhcp/dhcpd.conf:
one-lease-per-client on;          # 每一个客户机对应一个租约信息
subnet 192.168.253.8 netmask 255.255.255.248 {
    range dynamic-bootp 192.168.253.10 192.168.253.14;
    next-server 192.168.253.9; #设定存放初始启动文档的主机地址
    option subnet-mask 255.255.255.248;
    filename "u-boot-eth.bin";   #下载启动文档的文件名
    option root-path "/squash/ks";
    default-lease-time -1;         #无限租约时间
    max-lease-time -1;             #无限租约时间
  }


2.2,
[xiatian@server yocto]$ vim ./meta/recipes-connectivity/dhcp/files/lrc-lsp-axm/dhcpd.service:
[Unit]
Description=DHCPv4 Server Daemon
Documentation=man:dhcpd(8) man:dhcpd.conf(5)
After=network.target
After=time-sync.target
Before=ccs.service


[Service]
ExecStart=/usr/lib/systemd/scripts/start_dhcpd.sh


[Install]
WantedBy=multi-user.target


3,
dhcpd收到IP分配请求:
Jan 01 00:02:17 lrc7 dhcpd[1747]: Internet Systems Consortium DHCP Server 4.3.0
Jan 01 00:02:17 lrc7 dhcpd[1747]: Copyright 2004-2014 Internet Systems Consortium.
Jan 01 00:02:17 lrc7 dhcpd[1747]: All rights reserved.
Jan 01 00:02:17 lrc7 dhcpd[1747]: For info, please visit https://www.isc.org/software/dhcp/
Jan 01 00:02:17 lrc7 dhcpd[1747]: Wrote 0 leases to leases file.
Jan 01 00:02:17 lrc7 dhcpd[1747]: Listening on LPF/ks/02:40:43:77:07:01/192.168.253.8/29
Jan 01 00:02:17 lrc7 dhcpd[1747]: Sending on   LPF/ks/02:40:43:77:07:01/192.168.253.8/29
Jan 01 00:02:17 lrc7 dhcpd[1747]: Sending on   Socket/fallback/fallback-net
Jan 01 00:02:17 lrc7 dhcpd[1747]: Server starting service.
Jan 01 00:02:19 lrc7 dhcpd[1747]: BOOTREQUEST from b4:99:4c:b6:65:f4 via ks
Jan 01 00:02:19 lrc7 dhcpd[1747]: BOOTREPLY on 192.168.253.10 to b4:99:4c:b6:65:f4 via ks
Jan 01 00:02:19 lrc7 dhcpd[1747]: BOOTREQUEST from b4:99:4c:b7:8a:cc via ks
Jan 01 00:02:19 lrc7 dhcpd[1747]: BOOTREPLY on 192.168.253.11 to b4:99:4c:b7:8a:cc via ks
Jan 01 00:02:19 lrc7 dhcpd[1747]: BOOTREQUEST from b4:99:4c:b8:6f:69 via ks
Jan 01 00:02:19 lrc7 dhcpd[1747]: BOOTREPLY on 192.168.253.12 to b4:99:4c:b8:6f:69 via ks
Jan 01 00:02:23 lrc7 dhcpd[1747]: DHCPDISCOVER from b4:99:4c:b8:6f:69 via ks
Jan 01 00:02:23 lrc7 dhcpd[1747]: DHCPOFFER on 192.168.253.12 to b4:99:4c:b8:6f:69 via ks
Jan 01 00:02:23 lrc7 dhcpd[1747]: DHCPREQUEST for 192.168.253.12 (192.168.253.9) from b4:99:4c:b8:6f:69 via ks
Jan 01 00:02:23 lrc7 dhcpd[1747]: DHCPACK on 192.168.253.12 to b4:99:4c:b8:6f:69 via ks
Jan 01 00:02:25 lrc7 dhcpd[1747]: DHCPDISCOVER from b4:99:4c:b7:8a:cc via ks
Jan 01 00:02:25 lrc7 dhcpd[1747]: DHCPOFFER on 192.168.253.11 to b4:99:4c:b7:8a:cc via ks
Jan 01 00:02:25 lrc7 dhcpd[1747]: DHCPREQUEST for 192.168.253.11 (192.168.253.9) from b4:99:4c:b7:8a:cc via ks
Jan 01 00:02:25 lrc7 dhcpd[1747]: DHCPACK on 192.168.253.11 to b4:99:4c:b7:8a:cc via ks
Jan 01 00:02:25 lrc7 dhcpd[1747]: DHCPDISCOVER from b4:99:4c:b6:65:f4 via ks
Jan 01 00:02:25 lrc7 dhcpd[1747]: DHCPOFFER on 192.168.253.10 to b4:99:4c:b6:65:f4 via ks
Jan 01 00:02:25 lrc7 dhcpd[1747]: DHCPREQUEST for 192.168.253.10 (192.168.253.9) from b4:99:4c:b6:65:f4 via ks
Jan 01 00:02:25 lrc7 dhcpd[1747]: DHCPACK on 192.168.253.10 to b4:99:4c:b6:65:f4 via ks


4,
client use BOOTP(u-boot) to request IP






========================================================================================
-cf config-file:
Dhcpd can be made to use an alternate configuration file with the -cf flag, an alternate lease file with the -lf flag, or an alternate
       pid  file  with  the -pf flag.   Because of the importance of using the same lease database at all times when running dhcpd in produc-
       tion, these options should be used only for testing lease files or database files in a non-production environment.
-f:
To run dhcpd as a foreground process, rather than allowing it to run as a daemon in the background, the -f flag should  be  specified.  This is useful when running dhcpd under a debugger, or when running it out of inittab on System V systems


--no-pid
              Option to disable writing pid files.   By  default  the  program will  write  a  pid  file.   If the program is invoked with this option it will not check for an existing server process.


http://manpages.ubuntu.com/manpages/precise/man8/dhcpd.8.html  ==> dhcpd command parameter
http://blog.chinaunix.net/uid-23026336-id-2569990.html
http://linux.chinaunix.net/ebook/doc/2009/02/12/1061904.shtml
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值