当想偷懒,但是却因为实验环境不能不搭建麻烦的DHCP时就可以用到啦!还不赶紧收藏起来
#!/bin/bashyum -y install dhcp &> /dev/nullwhile truedoecho \"请输入IP范围,格式范例(10.0.0.1 10.0.0.200)\"read -p \"---->:\" IP_zoneecho \"请输入IP网段以及子网掩码,格式范例(10.0.0.0 255.255.255.0)\"read -p \"---->:\" IPnetecho \"请输入路由地址,格式范例(10.0.0.1)\"read -p \"---->:\" Gatwayecho \"请输入DNS地址,格式范例(10.0.0.1)\"read -p \"---->:\" DNS1IPadd=`echo $IPnet | awk \'{print $1}\'`Netmask=`echo $IPnet | awk \'{print $2}\'`dhcp_conf() {echo \"subnet $IPadd netmask $Netmask {\"echo \" range $IP_zone;\"echo \" option domain-name-servers $DNS1;\"echo \" option routers $Gatway;\"echo \" }\"}dhcp_conf > /etc/dhcp/dhcpd.confsystemctl restart dhcpd &> /dev/nullif [ $? -eq 0 ]thenecho \"启动成功!\"exit 0elseecho \"启动失败,显示启动失败内容.\"systemctl status dhcpdecho \"-------------------------------------------\"echo \"是否需要重新启动,Y/N?\"read -p \"---->\" decideif [ $decide == \"N\" ]thenecho \"bye!bye!\"exit 0fifidone