DHCP中继Shell脚本

DHCP中继Shell脚本

安装dhcp服务

yum install dhcp -y

安装完成后吧网卡改为仅主机模式
然后执行脚本

#!/bin/bash
#配置静态网卡
sed -i '4s/dhcp/static/' /etc/sysconfig/network-scripts/ifcfg-ens33
cat >> /etc/sysconfig/network-scripts/ifcfg-ens33 <<-EOF
IPADDR=192.168.2.101
NETMASK=255.255.255.0
GATEWAY=192.168.2.10
EOF
#重启网络服务
service network restart
#复制dhcp配置文件
spawn cp /usr/share/doc/dhcp-4.2.5/dhcpd.conf.example /etc/dhcp/dhcpd.conf
expect {
            "cp*"
            {send "yes\r"}
}
interact
cat >>/etc/dhcp/dhcpd.conf <<-EOF
subnet 192.168.1.0 netmask 255.255.255.0 {
     range 192.168.1.11 192.168.1.100;
     option routers 192.168.1.10;
}
EOF
#启动DHCP服务
systemctl start dhcp

你可能感兴趣的:(Shell脚本)