CentOS6 and DHCP server with vlan

โจทย์ไม่ยาก ไม่ง่าย … แค่ไม่เคยทำ

ความต้องการ

1. dhcp server บน CentOS6
2. แจก ip-address บน subnet ตามต้องการ
3. มี switch layer 2 เป็นตัวแยก vlan

ิวิธีทำ

1. สร้าง vlan id ใน switch ก่อน
ตัวอย่าง

2. ติดตั้ง dhcp server , vconfig

# yum install dhcp vconfig -y

3. load module 802.1q

# modprobe 8021q

check :

# lsmod | grep 8021q
8021q                  19587  0 
garp                    5901  1 8021q

4. สร้าง vlan interfaces

# cat /etc/sysconfig/network-scripts/ifcfg-eth0.2
DEVICE="eth0.2"
ONBOOT="yes"
BOOTPROTO=none
VLAN="yes"
IPADDR=10.156.3.2
NETMASK=255.255.255.0

# cat /etc/sysconfig/network-scripts/ifcfg-eth0.3
DEVICE="eth0.3"
ONBOOT="yes"
BOOTPROTO=none
VLAN="yes"
IPADDR=10.156.4.2
NETMASK=255.255.255.0

# cat /etc/sysconfig/network-scripts/ifcfg-eth0.4
DEVICE="eth0.4"
ONBOOT="yes"
BOOTPROTO=none
VLAN="yes"
IPADDR=10.156.5.2
NETMASK=255.255.255.0

# cat /etc/sysconfig/network-scripts/ifcfg-eth0.5
DEVICE="eth0.5"
ONBOOT="yes"
BOOTPROTO=none
VLAN="yes"
IPADDR=10.156.6.2
NETMASK=255.255.255.0

# cat /etc/sysconfig/network-scripts/ifcfg-eth0.6
DEVICE="eth0.6"
ONBOOT="yes"
BOOTPROTO=none
VLAN="yes"
IPADDR=10.156.7.2
NETMASK=255.255.255.0

# cat /etc/sysconfig/network-scripts/ifcfg-eth0.7
DEVICE="eth0.7"
ONBOOT="yes"
BOOTPROTO=none
VLAN="yes"
IPADDR=10.156.9.2
NETMASK=255.255.255.0

# cat /etc/sysconfig/network-scripts/ifcfg-eth0.8
DEVICE="eth0.8"
ONBOOT="yes"
BOOTPROTO=none
VLAN="yes"
IPADDR=10.156.11.2
NETMASK=255.255.255.0

# cat /etc/sysconfig/network-scripts/ifcfg-eth0.9
DEVICE="eth0.9"
ONBOOT="yes"
BOOTPROTO=none
VLAN="yes"
IPADDR=10.156.13.2
NETMASK=255.255.255.0

5. สร้าง /etc/dhcp/dhcpd.conf

ddns-update-style interim;
ignore client-updates;

authoritative;

subnet 10.156.3.0 netmask 255.255.255.0 {
 option routers      10.156.3.1;                                
 option subnet-mask  255.255.255.0;
 option domain-name-servers 208.67.222.222,8.8.8.8;
 option time-offset  -18000; # Eastern Standard Time
 range dynamic-bootp 10.156.3.21 10.156.3.200;                  
 default-lease-time 21600;
 max-lease-time 43200;
}
subnet 10.156.4.0 netmask 255.255.255.0 {
 option routers      10.156.4.1;                                
 option subnet-mask  255.255.255.0;
 option domain-name-servers 208.67.222.222,8.8.8.8;
 option time-offset  -18000; # Eastern Standard Time
 range dynamic-bootp 10.156.4.21 10.156.4.200;                  
 default-lease-time 21600;
 max-lease-time 43200;
}
subnet 10.156.5.0 netmask 255.255.255.0 {
 option routers      10.156.5.1;                                
 option subnet-mask  255.255.255.0;
 option domain-name-servers 208.67.222.222,8.8.8.8;
 option time-offset  -18000; # Eastern Standard Time
 range dynamic-bootp 10.156.5.21 10.156.5.200;                  
 default-lease-time 21600;
 max-lease-time 43200;
}
subnet 10.156.6.0 netmask 255.255.255.0 {
 option routers      10.156.6.1;                                
 option subnet-mask  255.255.255.0;
 option domain-name-servers 208.67.222.222,8.8.8.8;
 option time-offset  -18000; # Eastern Standard Time
 range dynamic-bootp 10.156.6.21 10.156.6.200;                  
 default-lease-time 21600;
 max-lease-time 43200;
}
subnet 10.156.7.0 netmask 255.255.255.0 {
 option routers      10.156.7.1;                                
 option subnet-mask  255.255.255.0;
 option domain-name-servers 208.67.222.222,8.8.8.8;
 option time-offset  -18000; # Eastern Standard Time
 range dynamic-bootp 10.156.7.21 10.156.7.200;                  
 default-lease-time 21600;
 max-lease-time 43200;
}
subnet 10.156.9.0 netmask 255.255.255.0 {
 option routers      10.156.9.1;                                
 option subnet-mask  255.255.255.0;
 option domain-name-servers 208.67.222.222,8.8.8.8;
 option time-offset  -18000; # Eastern Standard Time
 range dynamic-bootp 10.156.9.21 10.156.9.200;                  
 default-lease-time 21600;
 max-lease-time 43200;
}
subnet 10.156.11.0 netmask 255.255.255.0 {
 option routers      10.156.11.1;                               
 option subnet-mask  255.255.255.0;
 option domain-name-servers 208.67.222.222,8.8.8.8;
 option time-offset  -18000; # Eastern Standard Time
 range dynamic-bootp 10.156.11.21 10.156.11.200;                
 default-lease-time 21600;
 max-lease-time 43200;
}
subnet 10.156.13.0 netmask 255.255.255.0 {
 option routers      10.156.13.1;                               
 option subnet-mask  255.255.255.0;
 option domain-name-servers 208.67.222.222,8.8.8.8;
 option time-offset  -18000; # Eastern Standard Time
 range dynamic-bootp 10.156.13.21 10.156.13.200;                
 default-lease-time 21600;
 max-lease-time 43200;
}

ปล. ปรับได้ตามความเหมาะสม

6. แก้ไข /etc/sysconfig/dhcpd

DHCPDARGS=eth0.2
DHCPDARGS=eth0.3
DHCPDARGS=eth0.4
DHCPDARGS=eth0.5
DHCPDARGS=eth0.6
DHCPDARGS=eth0.7
DHCPDARGS=eth0.8
DHCPDARGS=eth0.9

ปล. ปรับได้ตามความเหมาะสม

7. start ซะ!

# service dhcpd start