码迷,mamicode.com
首页 > 其他好文 > 详细

自定义DHCP配置文件

时间:2017-08-29 18:57:37      阅读:127      评论:0      收藏:0      [点我收藏+]

标签:bash   dhcp   

备份

IP-MAC-Plan.csv


RACK_IDHost_IDHost_NameHost_IP
161Host1192.168.16.1
162Host2192.168.16.2
163Host3192.168.16.3
164Host4192.168.16.4
165Host5192.168.16.5
171Host6192.168.17.1



#!/bin/bash

sut_conf=/etc/dhcp/host_list/sut.conf
list=IP-MAC-Plan.csv
RowNum=$(wc -l $list | awk ‘{printf $1}‘)
NicPortNum=10

echo "
#option domain-name-servers 192.168.1.98,192.168.1.99;
default-lease-time 21600;
max-lease-time 43200;
subnet 192.168.0.0 netmask 255.255.0.0 {
#option routers 192.168.1.1;
    pool{
        failover peer \"dhcp\";
        range 192.168.1.1 192.168.200.200;
    }
}

" > $sut_conf

for ((i=2; i<=$RowNum;i++)) do
    HostIP=$(sed -n "$i"p $list |awk -F "," ‘{printf $4}‘)
    third=$(echo $HostIP | awk -F "." ‘{printf $3}‘)
    forth=$(echo $HostIP | awk -F "." ‘{printf $4}‘)
    echo $HostIP
    #echo $third
    #echo $forth
    for ((j=1; j<=$NicPortNum; j++)) do
        ip3=$third
        ip4=$(($forth*10+10+$j-1))
        SUTIP=192.168.$ip3.$ip4
        #echo $ip
        mac5=$(echo "obase=16;$ip3"|bc)
        mac6=$(echo "obase=16;$ip4"|bc)
        SUTMAC=00:00:00:00:$mac5:$mac6
        #echo $mac
        echo "
        host ${HostIP}_${j} {
        hardware ethernet $SUTMAC;
        fixed-address $SUTIP;
        }" >> $sut_conf
    done

done



生成文件:
#option domain-name-servers 192.168.1.98,192.168.1.99;
default-lease-time 21600;
max-lease-time 43200;
subnet 192.168.0.0 netmask 255.255.0.0 {
#option routers 192.168.1.1;
    pool{
        failover peer "dhcp";
        range 192.168.1.1 192.168.200.200;
    }
}


        host 192.168.16.1_1 {
        hardware ethernet 00:00:00:00:10:14;
        fixed-address 192.168.16.20;
        }

        host 192.168.16.1_2 {
        hardware ethernet 00:00:00:00:10:15;
        fixed-address 192.168.16.21;
        }

        host 192.168.16.1_3 {
        hardware ethernet 00:00:00:00:10:16;
        fixed-address 192.168.16.22;
        }

        host 192.168.16.1_4 {
        hardware ethernet 00:00:00:00:10:17;
        fixed-address 192.168.16.23;
        }


本文出自 “wu” 博客,谢绝转载!

自定义DHCP配置文件

标签:bash   dhcp   

原文地址:http://548260.blog.51cto.com/538260/1960783

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!