自定义DHCP配置文件

前端之家收集整理的这篇文章主要介绍了自定义DHCP配置文件前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。

备份

IP-MAC-Plan.csv


RACK_ID Host_ID Host_Name Host_IP
16 1 Host1 192.168.16.1
16 2 Host2 192.168.16.2
16 3 Host3 192.168.16.3
16 4 Host4 192.168.16.4
16 5 Host5 192.168.16.5
17 1 Host6 192.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; }

原文链接:https://www.f2er.com/bash/391119.html

猜你在找的Bash相关文章