码迷,mamicode.com
首页 > 其他好文 > 详细

脚本实现方便配置DHCP-server

时间:2014-11-28 06:34:03      阅读:169      评论:0      收藏:0      [点我收藏+]

标签:linux   dhcp   

#!/bin/bash

echo ‘the script is install dhcpd server‘

read -p "please insert rhel5-cd to cdrom and enter to next:"aa

mount /dev/cdrom /media/ &>/dev/null

rpm -Uvh /media/Server/dhcp-*  &>/dev/null

echo "请为本机配置IP地址"

read -p "请输入IP地址:" ip

read -p "请输入掩码:" ip_mask

MACADDR=$(ifconfig eth0 |grep eth0|awk ‘{print $5}‘)

cat >/etc/sysconfig/network-scripts/ifcfg-eth0 <<EOF

DEVICE=eth0

ONBOOT=yes

BOOTPROTO=static

IPADDR=$ip

NETMASK=$ip_mask

HWADDR=$MACADDR

EOF

echo "正在为你启用新配置的IP地址"

ifdown eth0;ifup eth0

echo "IP地址已经生效"

read -p "请为DHCP配置网段:" dhcp_net

read -p "请为DHCP配置掩码:" dhcp_mask

read -p "请为DHCP配置网关:" dhcp_gw

read -p "请为DHCP配置分配的开始IP:" dhcp_bigin

read -p "请为DHCP配置结束IP:" dhcp_over

cat >/etc/dhcpd.conf <<EOF   //dhcp3的配置文件默认安装在/etc下,dhcp4则会安装在/etc/dhcp下,注意自己的路径

ddns-update-style interim;

ignore client-updates;

subnet $dhcp_net netmask $dhcp_mask {

        option routers                  $dhcp_gw;

        option subnet-mask              $dhcp_mask;

        range $dhcp_bigin $dhcp_over;

        default-lease-time 21600;

        max-lease-time 43200;

}

EOF

service dhcpd start &>/dev/null

netstat -anpl |grep :67


本文出自 “龙爱雪琪” 博客,请务必保留此出处http://dragon123.blog.51cto.com/9152073/1583486

脚本实现方便配置DHCP-server

标签:linux   dhcp   

原文地址:http://dragon123.blog.51cto.com/9152073/1583486

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!