实验环境:给本机IP设为192.168.100.100,脚本代码如下:
可复制代码如下:
#!/bin/bash
yum install dhcp -y
network="/etc/sysconfig/network-scripts/ifcfg-ens33"
dhcp="/etc/dhcp/dhcpd.conf"
[ ! -e $network.bak ] && cp -p $network $network.bak
sed -i -e "4s/dhcp/static/" -e '$aIPADDR=192.168.100.100\nNETMASK=255.255.255.0\nGATEWAY=192.168.100.1' $network
systemctl restart network
cp -p /usr/share/doc/dhcp-4.2.5/dhcpd.conf.example $dhcp
[ ! -e $dhcp.bak ] && cp -p $dhcp $dhcp.bak
sed -i -e "29asubnet 192.168.100.0 netmask 255.255.255.0 {\n range 192.168.100.10 192.168.100.50;\n option routers 192.168.100.1;\n} " $dhcp
systemctl start dhcpd
首先进行变量赋值,赋值给network和dhcp变量名
1、``[ ! -e $network.bak ] && cp -p $network $network.bak
2、sed -i -e "4s/dhcp/static/" -e '$aIPADDR=192.168.100.100\nNETMASK=255.255.255.0\nGATEWAY=192.168.100.1' $network
systemctl restart network
3、systemctl restart network
4、cp -p /usr/share/doc/dhcp-4.2.5/dhcpd.conf.example $dhcp
5、[ ! -e $dhcp.bak ] && cp -p $dhcp $dhcp.bak
6、sed -i -e "29asubnet 192.168.100.0 netmask 255.255.255.0 {\n range 192.168.100.10 192.168.100.50;
7、ssystemctl start dhcpd
另外有需要云服务器可以了解下创新互联cdcxhl.cn,海内外云服务器15元起步,三天无理由+7*72小时售后在线,公司持有idc许可证,提供“云服务器、裸金属服务器、高防服务器、香港服务器、美国服务器、虚拟主机、免备案服务器”等云主机租用服务以及企业上云的综合解决方案,具有“安全稳定、简单易用、服务可用性高、性价比高”等特点与优势,专为企业上云打造定制,能够满足用户丰富、多元化的应用场景需求。