#!/bin/bash
yum install dhcp -y //安装DHCP服务
yum install expect -y //安装expect工具
/usr/bin/expect <<-EOF
spawn cp /usr/share/doc/dhcp-4.2.5/dhcpd.conf.example /etc/dhcp/dhcpd.conf
//spawn追踪后面的命令
expect{ //匹配
"cp*" //用“*”代表后面一长串命令
{send "yes\r"} //交互式输入yes '\r’代表回车
}
expect eof
EOF
cat <<-EOF >> /etc/dhcp/dhcpd.conf //在DHCP配置文件中写入命令
subnet 192.168.100.0 netmask 255.255.255.0 { //网段,子网掩码
range 192.168.100.20 192.168.100.200; //网段范围
option routers 192.168.100.1; //网关
EOF
}
EOF
systemctl stop firewalld.service //关闭防火墙
setenforce 0 //关闭增强功能
systemctl start dhcpd //开启DHCP服务
免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。