dhcp为大量pc设置固定ip脚本【转自《鸟哥的linux私房菜》】

#如果有100台计算机要管理,可以在开机之后,利用手动方法来设置好每部主机的ip后,再根据下面的脚本处理dhcpd.conf

#! /bin/bash
read -p "Do you finished the IP's settings in every client (y/n)? " yn
read -p "How many PC's in this class (ex> 60)? "
if [ "$yn" = "y" ];then
        for site in $(seq 1 ${num})
        do
                siteip="192.168.100.${site}"
                allip="$allip $siteip"
                ping -c 1 -w 1 $siteip > /dev/null 2>&1
                if [ "$?" == "0" ];then
                        okip="$okip &siteip"
                else
                        errorip="$errorip $siteip"
                        echo "siteip is DOWN"
                fi
        done
        [ -f dhcp.conf ] && rm dhcpd.conf
        for
        do
                pcname=pc$(echo $site | cut -d '.' -f 4)
                mac=$(arp -n | grep "$site " | awk '{print $3}')
                echo " host $pcname {"
                echo "          hardware ethernet ${mac};"
                echo "          fixed-address     ${site};"
                echo "  }"
                echo " host $pcname {"                                  >> dhcpd.conf
                echo "          hardware ethernet ${mac};"              >> dhcpd.conf
                echo "          fixed-address     ${site};"             >> dhcpd.conf
                echo "  }"                                              >> dhcpd.conf
        done
fi
echo    "You can use dhcpd.conf (this directory) to modified your /etc/dhcp/dhcpd.conf"
echo    "Finisher."


#如果管理的都是Linux,开机设置好ip后再将上面的脚本运行一次,每台计算机的mac与ip对应就顺利写入dhcpd.conf了,然后再将它黏贴到/etc/dhcp/dhcpd.conf文件中即可。如#果管理的是windows的话,那使用命令行界面下的netsh interface ip set address xxx之类的命令来修改吧

#注:此脚本未经过自己测试


你可能感兴趣的:(dhcp为大量pc设置固定ip脚本【转自《鸟哥的linux私房菜》】)