shell之DHCP服務腳本

shell之DHCP服務腳本

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服務
相關文章
相關標籤/搜索