Thursday, October 18, 2012

DHCP Server某網段的IP range被用完了該怎麼辦?

做實驗時不小心把某個網段的IP scope用完了,距離release時間有一天,影響到新的client拿不到IP了,靈機一動就想把它手動砍掉吧!不過我要對付的是整個IP scope,嘿嘿~派出sed一行指令就結束了。

Steps:
1. dhcpd的lease table是放在/var/lib/dhcpd/dhcpd.leases

2. 檢查一下格式:

lease 10.10.6.125 {
  starts 2 2012/10/16 22:12:53;
  ends 3 2012/10/17 22:12:53;
  tstp 3 2012/10/17 22:12:53;
  binding state active;
  next binding state free;
  hardware ethernet b8:ac:6f:21:53:ec;
  uid "\001\270\254o!S\354";
  client-hostname "D129252S";
}

10.10.6這個range被fake DHCP client用完了,所以我要把它們手動通通砍掉。

3. Sed:

sed -i "/10.10.6/,/}/d" /var/lib/dhcpd/dhcpd.leases

4. 重啟DHCP Server:
# /etc/init.d/dhcpd restart

參考: http://en.kioskea.net/faq/1451-sed-delete-one-or-more-lines-from-a-file

No comments: