DHCP服务脚本
在运行脚本之前需要配置GNS3,可以看我之前的博客有详细教程
#!/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服务
原文地址:https://blog.51cto.com/14449524/2441608
时间: 2024-11-09 17:09:03