由于公司安全策略要求,需要绑定了MAC地址的机器才能联网,每次新增主机都要手动绑定IP和MAC地址,
非常麻烦,所以自动绑定脚本应运而生,这是根据我们公司编写的shell脚本,大婶们见笑了,请多多指教
#!/bin/bash
list=(`sed -rn '/\(([0-9|a-z|A-Z]+:){5}[0-9|a-z|A-Z]+\)/p' tail2000.log | \
awk '{print $8" "$9}'|sed -e 's/[(|)]/ /g'|sort -rn|uniq`)
count=${#list[@]}
path=/home/dhcpd.conf
string_133="range 10.34.133.44 10.34.133.44;"
string_134="range 10.34.134.21 10.34.135.240;"
string_135="range 10.34.135.21 10.34.135.240;"
string_129="range 10.34.129.21 10.34.135.240;"
i=0
while [ $i -lt $count ]
do
num=`echo ${list[$i]:6:3}`
grep -Ewq "${list[$i]}|${list[$i+1]}" $path
if [ $? -ne 0 ];then
case $num in
129)
NO=`date +%N`
hosts=`echo "host CN${NO:1:5}{hardware ethernet ${list[$i]}; fixed-address ${list[$i+1]};}"`
sed -i "/$string_129/a '\t'$hosts" $path
sed -ir "s/'.'/\t/g" $path;;
133)
NO=`date +%N`
hosts=`echo "host CN${NO:1:5}{hardware ethernet ${list[$i]}; fixed-address ${l

为满足公司安全策略,该博客分享了一种解决方法:使用shell脚本自动化绑定DHCP服务器上的IP地址和MAC地址,从而简化新增主机时的手动配置过程。
最低0.47元/天 解锁文章
8456

被折叠的 条评论
为什么被折叠?



