OB2D與DHCP及電腦教室動態分配固定真實IP
- 安裝dhcp3伺服器
apt-get install dhcp3-server
vi /etc/dhcp3/dhcpd.conf
#
# Sample configuration file for ISC dhcpd for Debian
#
# $Id: dhcpd.conf,v 1.4.2.2 2002/07/10 03:50:33 peloy Exp $
# 本例子以大橋國小為例,自動分配虛擬IP,但亦可自動分配固定的真實IP
#全域設定
#option definitions common to all supported networks...
option domain-name "dc2es.tnc.edu.tw";
option domain-name-servers 163.26.174.1,163.26.200.11, 168.95.1.1, 139.174.55.244;
option subnet-mask 255.255.0.0;
default-lease-time 86400;
max-lease-time 86400;
#要分配出去的網段
shared-network network_tag {
#第1個網段域192.168.0.0/255.255.0.0 虛擬IP
subnet 192.168.0.0 netmask 255.255.0.0 {
#DHCP要分配出去的IP範圍
range 192.168.120.1 192.168.120.254;
range 192.168.121.1 192.168.121.254;
range 192.168.122.1 192.168.122.254;
option domain-name-servers 163.26.174.1, 163.26.200.11, 168.95.1.1, 139.175.55.244;
option domain-name "dc2es.tnc.edu.tw";
option broadcast-address 192.168.255.255;
option subnet-mask 255.255.0.0;
option routers 192.168.0.1;
#動態分配固定IP的寫法
# host n5500 {
# hardware ethernet 00:14:FD:13:10:58;
# fixed-address 192.168.1.100;
# }
}
#第2個網段 163.26.174.0/255.255.255.0 真實IP
subnet 163.26.174.0 netmask 255.255.255.0 {
#range加上#號表示不會自動分配非固定ip出去,但仍可以分配固定的真實ip
#range 163.26.174.51 163.26.174.239;
option domain-name-servers 163.26.174.1, 163.26.200.11, 168.95.1.1, 139.175.55.244;
option domain-name "dc2es.tnc.edu.tw";
option broadcast-address 163.26.174.255;
option subnet-mask 255.255.255.0;
option routers 163.26.174.254;
#動態分配固定IP的寫法
# host seednet070 {
# hardware ethernet 00:1e:d8:12:16:d4;
# fixed-address 163.26.174.247;
# }
#INCLUDE 電腦教室動態分配固定IP的設定檔進來
#若需要時請自行解除#
#include "/etc/dhcp3/3f";
#include "/etc/dhcp3/2f";
}
}
- 產生DHCP 自動分配固定IP的設定檔
底下的指令請先安裝大量建帳號shell script(見前一篇文章)
cd /user/dhcp
./mac /var/lib/dhcp3/dhcpd.leases mac.csv
將目前所有的dhcp分配到的ip,mac和電腦名稱存成mac.csv
若mac指令無法執行則請以g++重新編輯一次mac.cpp,會得到a.out,再把a.out改名為mac
g++ mac.cpp
設法以EXCEL編輯mac.csv
刪除掉不要的記錄後,使用EXCEL再存回mac.csv檔
執行
./g fixdhcp mac.csv > 3f
就可以產生DHCP分配固定IP所需的設定檔語法(上例為本校3F電腦教室)
mv 3f /etc/dhcp3
cd /etc/dhcp3
vi dhcpd.conf
要先建立一個subnet,並在其內加上include 指令
subnet 163.26.174.0 netmask 255.255.255.0 {
#range 指令mark起來表示這段subnet不會分配任何動態ip出去
#range 163.26.174.51 163.26.174.239;
option domain-name-servers 163.26.174.1, 163.26.200.11, 168.95.1.1, 139.175.55.244;
option domain-name "dc2es.tnc.edu.tw";
option broadcast-address 163.26.174.255;
option subnet-mask 255.255.255.0;
option routers 163.26.174.254;
include "/etc/dhcp3/3f";
}
最後重新啟動dhcp3
service dhcp3-server restart
留言