用一台DHCP服务器给3个网段分配IP.
DHCP服务器IP为:10.1.1.251/24
VLAN1:192.168.10.0/24
VLAN2:192.168.11.0/24
VLAN3:192.168.12.0/24
在交换机上配置DHCP中继,然后在/etc/dhcpd.conf里输入以下内容:
ddns-update-style interim;
ignore client-updates;
subnet 10.1.1.0 netmask 255.255.255.0 { #子网 10.1.1.0,DHCP服务器分发的IP必须包含自己的网段,否则无法启动
range 10.1.1.10 10.1.1.11; #分配范围
}
subnet 192.168.10.0 netmask 255.255.255.0 { #子网 192.168.10.0
default-lease-time 21600
max-lease-time 43200
option domain-name-servers 192.168.0.254;
option routers 192.168.10.254; #网关
option subnet-mask 255.255.255.0;#子网掩码
range 192.168.10.15 192.168.10.200;#分配范围
}
subnet 192.168.11.0 netmask 255.255.255.0 { #子网192.168.11.0
option routers 192.168.11.254;#网关
option subnet-mask 255.255.255.0;#子网掩码
default-lease-time 21600
max-lease-time 43200
option domain-name-servers 192.168.0.254;
range 192.168.11.15 192.168.11.200;#分配范围
}
subnet 192.168.12.0 netmask 255.255.255.0 { #子网192.168.12.0
option routers 192.168.12.254;#网关
option subnet-mask 255.255.255.0;#子网掩码
default-lease-time 21600
max-lease-time 43200
option domain-name-servers 192.168.0.254;
range 192.168.12.20 192.168.12.200;#分配范围
}
还有一些其他的参数:
超级作用域,当IP不够时可以通过它来添加分配IP网段:
shared-network {
subnet 192.168.1.0 netmask 255.255.255.0{
…
}
subnet 192.168.2.0 netmask 255.255.255.0 {
…
}
}
IP与MAC绑定,放在subnet作用域下:
host
{
hardware ethenet 12:34:56:78:AB:CD; #MAC地址
fixed-address 192.168.57.12; #IP地址
}
DHCP配置文件模板存放地址: /usr/share/doc/dhcp-[版本号]/dhcpd.conf.sample
如果主机有多块网卡,请修改/etc/init.d/dhcpd启动脚本。修改如下:
start() {
# Start daemons.
echo -n $"Starting $prog: "
daemon /usr/sbin/dhcpd eth0 eth1 eth3 .... ${DHCPDARGS} 2>/dev/null
RETVAL=$?
echo
if [ $RETVAL -eq 0 ]; then
touch /var/lock/subsys/dhcpd
if [ -x /usr/bin/logger ]; then
/usr/bin/logger -t dhcpd 'dhcpd startup succeeded'
fi;
else
if [ -x /usr/bin/logger ]; then
/usr/bin/logger -t dhcpd 'dhcpd startup failed'
fi;
fi
return $RETVAL
}
.
.
.
.