linux dhcp 服务器配置(经历)

!原意只是想用hostapd开个热点而已 居然还要配dhcp……

一  安装dhcp

1.yum list dhcp* 没有


2.原装光盘 (u盘)
mount Fedora17.iso mnt/cdrom
cd rdrom/packet/d
rpm -ivh dhcp*
然后dhcpd 没有

3.unix公社 

下载 dhcp-4.2.4-P2.tar.gz

tar

 ./config 

make 

make install 装上

二 配置/etc/dhcpd.conf

##=========================dhcpd.conf内容==========================##
ddns-update-style interim;
ignore client-updates;

subnet 192.168.0.0 netmask 255.255.255.0 
{

# --- default gateway设置客户端的相关选项
        option routers                  192.168.0.1;#路由
        option subnet-mask              255.255.255.0;

#       option nis-domain               "domain.org";
#       option domain-name              "domain.org";
        option domain-name-servers      8.8.8.8;#域名服务器

        option time-offset              -18000; # Eastern Standard Time
#       option ntp-servers              192.168.0.1;
#       option netbios-name-servers     192.168.0.1;
# --- Selects point-to-point node (default is hybrid). Don't change this unless
# -- you understand Netbios very well
#       option netbios-node-type 2;

        range dynamic-bootp 192.168.0.128 192.168.0.254;
        default-lease-time 21600;
        max-lease-time 43200;

        # we want the nameserver to appear at a fixed address
#       host ns {
#               next-server marvin.redhat.com;
#               hardware ethernet 12:34:56:78:AB:CD;
#               fixed-address 207.175.42.254;
#       }
}
##=========================dhcpd.conf内容==========================##

三  dhcpd脚本 

创建dhcpd运行脚本(vi or touch)
/etc/init.d/dhcpd

运行要dhcpd脚本有执行权限
chmod +x dhcpd
##=========================dhcpd内容==========================##
#!/bin/sh
#
# dhcpd		Init Script to start/stop dhcpd.
#
# chkconfig:	- 61 39
# description:	If you dont know you shouldnt be here
#
# processname: dhcpd
config_file=/etc/dhcpd.conf
pidfile=/var/run/dhcpd.pid
lease_file=/var/db/dhcpd.leases


# Source function library
. /etc/rc.d/init.d/functions

# Get network config
. /etc/sysconfig/network

  if [ ! -e $config_file ]; then
    echo " No config file at $config_file"
    exit 0
  fi

RETVAL=0

start() {
  if [ ! -e $lease_file ]; then
        echo "  Creating $lease_file"
        touch $lease_file

  elif [ -f $pidfile ]; then
        PID=`cat $pidfile`
        echo "    ISC-DHCPD already running: $PID"
        exit 2;
  else
	echo -n $"Starting ISC-DHCPD: "
	daemon /usr/local/sbin/dhcpd wlan0 
	RETVAL=$?
	echo
	[ $RETVAL -eq 0 ] && touch /var/lock/subsys/dhcpd		
	return $RETVAL
  fi
}

stop() {
	echo -n $"Stopping ISC-DHCPD: "
	killproc dhcpd
	RETVAL=$?
	echo
[ $RETVAL -eq 0 ] && rm -f /var/run/dhcpd.pid /var/lock/subsys/dhcpd
	return $RETVAL
}

restart() {
	stop
	start
}

reload() {
        echo -n $"Reloading dhcpd: "
        killproc dhcpd -USR2
        RETVAL=$?
        echo
        return $RETVAL
}


case "$1" in
  start)
	start
	;;
  stop)
	stop
	;;
  status)
	status dhcpd
	;;
  restart)
	restart
	;;
  condrestart)
	[ -f /var/lock/subsys/dhcpd ] && restart || :
	;;
  reload)
	reload
	;;
  *)
	echo $"Usage: $0 {start|stop|status|restart|condrestart|reload}"
	exit 1
esac

exit $?
##=========================dhcpd内容==========================##
39行是要看网卡而定的
daemon /usr/local/sbin/dhcpd wlan0

四  改网卡地址

查看无线网卡 
ifconfig -a (wlan0 eth0)
设置ip:
ifconfig wlan0 192.168.0.1 netmask 255.255.255.0

一开始看不到网卡 还以为不用改了 

五  其他

启动: sudo service dhcpd start

问题

No subnet declaration for wlan0 (no IPv4 addresses).
** Ignoring requests on wlan0.  If this is not what
   you want, please write a subnet declaration
   in your dhcpd.conf file for the network segment
   to which interface wlan0 is attached. **

Not configured to listen on any interfaces!

这是我最常见的一个问题
导致原因有很多

原因  一

直接运行dhcpd


运行dhcpd 要指定网卡 
比如dhcpd wlan0
还有很多不确定因素  要自己创建
/var/db/dhcpd.leases (数据库文件)

原因二

没有设置网卡地址

网卡地址设置要跟

/etc/dhcpd.conf一致

原因三

要联上网……
没开hostapd是开启服务会失败

原因  四

几个配置文件的地址不一致



其他解决方法


建立 /etc/sysconfig/dhcpd
##=========================dhcpd======================================##
DHCPDARGS=wlan0
#DEVICE=wlan0
#BOOTPROTO=static
#TYPE=ether
#HWADDR=68:a3:c4:53:80:1f
#IPADDR=192.168.1.1
#NETMASK=255.255.255.0
#BROADCAST=192.168.1.255
#NETWORK=192.168.1.0
#ONBOOT=yes
#DHCPDARGS=wlan0
##=========================dhcpd======================================##

你可能感兴趣的:(linux dhcp 服务器配置(经历))