标签:cat str document out his div ast 获取 systemctl
1 yum -y install dhcp
ipv4 udp67、udp68
ipv6 udp546、udp547
服务名:dhcpd
1 option domain-name #设置所在的DNS域 2 3 option domain-name-servers #设置DNS服务器地址 4 5 default-lease-time #设置默认租约时间,单位为秒 6 7 max-lease-time #设置最大租约时间,单位为秒 8 9 ddns-update-style #设置DNS的更新方式,通常不配 10 11 authoritative #标识权威服务器,多台中生效的标识 12 13 log-facility local7 #日志发送到local7日志服务中
注意:为了配置清晰,可将多余的subnet删除,仅仅保留需要配置的,若无需为特定主机配置dhcp,也可将host相关项删除。
1 option domain-name-servers 61.153.177.198,223.5.5.5; #全局下DNS配置 2 3 default-lease-time 7200; #全局下最小租约时间 4 5 max-lease-time 14400; #全局下最大租约时间 6 7 subnet 192.168.10.0 netmask 255.255.255.0 { #设置网段 8 9 range 192.168.10.11 192.168.10.254; #设置可分配地址池 10 11 option domain-name-servers 61.153.177.198, 223.5.5.5 #可在全局下配置,对全局生效,亦可在subnet下配置,只对特定subnet生效 12 13 option routers 192.168.10.2; #设定网关 14 15 option broadcast-address 192.168.10.255; #广播 16 17 }
1 [root@server dhcp]service dhcpd restart #centos6.*系列命令 2 3 [root@server dhcp]systemctl restart dhcpd #centos7系列命令
1 TYPE=Ethernet 2 3 BOOTPROTO=dhcp 4 5 DEFROUTE=yes 6 7 NAME=eth0 8 9 ONBOOT=yes
1 [root@client ~]systemctl restart network
[root@client ~]# ifconfig
eth0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500
inet 192.168.10.11 netmask 255.255.255.0 broadcast 192.168.10.255
……
1 [root@server dhcp]# cat /var/lib/dhcpd/dhcpd.leases 2 3 # The format of this file is documented in the dhcpd.leases(5) manual page. 4 5 # This lease file was written by isc-dhcp-4.2.5 6 7 server-duid "\000\001\000\001\037S(\244\000\014)\371Xn"; 8 9 lease 192.168.10.11 { 10 11 starts 5 2016/08/26 16:25:24; 12 13 ends 5 2016/08/26 18:25:24; 14 15 cltt 5 2016/08/26 16:25:24; 16 17 binding state active; 18 19 next binding state free; 20 21 rewind binding state free; 22 23 hardware ethernet 00:50:56:36:ad:b9; 24 25 client-hostname "imxhy"; 26 27 }
获取dhcp客户端地址:
1 tail -n +4 /var/lib/dhcpd/dhcpd.leases | less | grep -v ‘server-duid‘ | awk ‘BEGIN{RS=ORS="}"}{print $2,$25,$29"\n"}‘ | sed ‘s/}//g‘ | sed ‘s/;//g‘ | sed ‘s/"//g‘ | sort -n | column -t
标签:cat str document out his div ast 获取 systemctl
原文地址:https://www.cnblogs.com/itzgr/p/9888565.html