| Notices |
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
Are you new to LinuxQuestions.org? Visit the following links:
Site Howto |
Site FAQ |
Sitemap |
Register Now
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
 |
GNU/Linux Basic Guide
This 255-page guide will provide you with the keys to understand the philosophy of free software, teach you how to use and handle it, and give you the tools required to move easily in the world of GNU/Linux. Many users and administrators will be taking their first steps with this GNU/Linux Basic guide and it will show you how to approach and solve the problems you encounter.
Click Here to receive this Complete Guide absolutely free. |
|
|
By SiegeX at 2004-09-13 14:01
|
|
The Dynamic Host Configuration Protocol (DHCP) allows you to specify network parameters on a server and have client computers query the server for their information such as IP, netmask, gateway, DNS, etc. In addition to not having to statically assign network information to numerous clients, you also do not need to specify the IP of the DHCP server as this discovery is done via broadcast packets; the caveat to this is that you must have one DHCP server per broadcast domain. In case it's not blatantly obvious, the power of DHCP is that if anything changes on your network such as the IP of a DNS server, you only need to edit one configuration file even if you have hundreds of clients.
The DHCP server I am using is called 'dhcpd' (oddly enough) and my current version is dhcp-3.0pl2-i386-1. This howto is not meant to be in-depth but rather just a general overview of some of the common features for the dhcpd server. If you need to do more esoteric configurations please man dhcpd.conf for detailed information.
The following is a common dhcpd.conf file. Below I will dissect this file and explain what each line does. Keeping with the convention of my other Linux Answers, all computer-specific information will be highlighted in blue and will most likely need to be changed.
Code:
ddns-update-style none;
subnet 192.168.1.0 netmask 255.255.255.0
{
range 192.168.1.100 192.168.1.200;
option subnet-mask 255.255.255.0;
option broadcast-address 192.168.1.255;
option domain-name-servers 123.123.123.10, 123.123.123.20;
option routers 192.168.1.1;
host slackbox
{
hardware ethernet 00:50:AB:AB:AB:AB;
fixed-address 192.168.1.7;
}
host winbox
{
hardware ethernet 00:06:CD:CD:CD:CD;
fixed-address 192.168.1.8;
}
}
The first thing we need to do is set a Dynamic DNS update style. Since DynDNS is beyond the scope of this howto, I am going to set the style to none but if this is something you want to do, then the man pages have tons of info on it.
Code:
ddns-update-style none;
Next we must specify what subnet and netmask we will be working on. Note that you can have many subnet configurations within the single dhcpd.conf file. Each subnet group is bound together by curly braces { }
Code:
subnet 192.168.1.0 netmask 255.255.255.0
Note that every command from here on will only pertain to the subnet specified above. This will be true until we reach the closing curly brace } as noted above.
Now we will specify what range of IP addresses we want to be made available for clients using DHCP. This option is very handy when used in conjunction with a firewall because you know exactly what IP addresses came from a client using DHCP and you can exercise restrictions upon them as necessary.
Code:
range 192.168.1.100 192.168.1.200;
This next line is going to look a bit redundant because we are setting the netmask again even though we set it in the subnet declaration above, but it's recommended in the man pages so we are going to do it.
Code:
option subnet-mask 255.255.255.0;
Next we specify the broadcast address for our subnet. This address always ends in 255
Code:
option broadcast-address 192.168.1.255;
We will definitely want to tell our clients what servers to use for DNS in order to resolve hostnames to IP addresses
Code:
option domain-name-servers 123.123.123.10, 123.123.123.20;
The next option tells our clients what IP address to use for their gateway. This IP address generally ends in .1 but does not have to. The box with this IP should be configured as a router and be able to forward packets accordingly.
Code:
option routers 192.168.1.1;
If you wanted you could stop here but I thought I would show you a cool little feature that I like to use. Even though DHCP gives out IP address dynamically, it also has the ability to reserve an IP address for a certain computer. In this sense it's almost as if the client computer has a static IP even though it uses DHCP to get it. This is useful if you want to be able to put entries in your /etc/hosts file and not have to worry about the entry becoming invalid over time.
The first thing we must do is to specify a name for the computer as a helpful identifier
Note that similarly to the subnet grouping, we are now starting a sub-group as seen by the addition of the curly braces. This allows us to have multiple host definitions within one subnet group.
This next line is what allows us to uniquely identify one computer from another. The hardware ethernet address is the same as the MAC address. This information can be found by running the command ifconfig <interface> | grep HWaddr on a client computer for linux and ipconfig /all for a client computer running windows.
Code:
hardware ethernet 00:50:AB:AB:AB:AB;
And finally this next line tells the dhcpd server what IP address you always want to be assigned to this computer. Note that I intentionally make all IP's assigned this way outside of the DHCP range we specified earlier. This is not a must as the dhcp server is smart enough to not give out two IP's simultaneously but it helps in being able to quickly recognize which clients used this feature.
Code:
fixed-address 192.168.1.7;
This concludes this DHCP howto. As an added bonus I have included the init script I made for my Slackware box, however this script should work on many other distros. Please make sure you edit the 4 configuration options between the hashmark lines accordingly.
Code:
#!/bin/sh
#
# /etc/rc.d/rc.dhcpd
#
# Start/stop/restart the DHCP daemon.
#
# To make dhcpd start automatically at boot, make this
# file executable: chmod 755 /etc/rc.d/rc.dhcpd
#
#############################################
CONFIGFILE="/etc/dhcpd.conf"
LEASEFILE="/var/state/dhcp/dhcpd.leases"
INTERFACES="eth1"
OPTIONS="-q"
#############################################
dhcpd_start() {
if [ -x /usr/sbin/dhcpd -a -r $CONFIGFILE ]; then
echo "Starting DHCPD..."
/usr/sbin/dhcpd -cf $CONFIGFILE -lf $LEASEFILE $OPTIONS $INTERFACES
# /usr/sbin/dhcpd -q $INTERFACES
fi
}
dhcpd_stop() {
killall dhcpd
}
dhcpd_restart() {
dhcpd_stop
sleep 2
dhcpd_start
}
case "$1" in
'start')
dhcpd_start
;;
'stop')
dhcpd_stop
;;
'restart')
dhcpd_restart
;;
*)
# Default is "start", for backwards compatibility with previous
# Slackware versions. This may change to a 'usage' error someday.
dhcpd_start
esac
To start up your brand new dhcpd server simply run the command
Code:
/etc/rc.d/rc.dhcpd start
As always, questions and comments are welcome. Enjoy!
|
|
|
|
All times are GMT -5. The time now is 01:42 PM.
|
|
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.
|
Latest Threads
LQ News
|
|
-Akshat
I am setting up a DHCP server that will assign all of its IP address via MAC address and your post will come in very handy for this.
I do have one question though.
If I have the subnet 192.168.0.0/24, with all IPs served out as static from the DHCP server, how do I stop someone from just plugging in and entering in there own static IP address and getting on to the network. I am setting up the server for a small office and I want to be able to restrict what gets plugged in and gets an IP address and also to stop people from hooking up devices that have not been approved for use in the office.
Thanks for any points you may have to offer
mdkelly
thank you for the great "howto", ( very clear ! ) i've set up my own dhcp-server. only one thing kept me busy
for more then 14 days: you need a #$%%@! CROSSOVER-cable to connect 2 pc's nic to nic.
i found out late at night, so with a little cutting-and -soldering i made it from a patch-cable.
now all works fine...
egag
so that only a pool of addresses
having mac address say 00-11--XX-XX-XX
are assigned IP addresses as we have all ethernet cards with 1 starting address
and plan to have same in future..
so i have seen hardware-address option
but that doesnt help if a new machine comes in..
any solution.???
it would help..
AP1 (D-Link DWL-900AP+):
IP:10.107.100.200
IP range: 10.107.100.201---254
Netmask: 255.255.0.0
Gateway: 10.107.1.1
AP2(D-Link DWL-714P+):
IP: 192.168.0.1
Range: 192.168.0.100---199
Netmask: 255.255.255.0
AP3(D-Link DWL-900AP+)
IP:10.107.100.100
Range: 10.107.101---151
Netmask: 255.255.0.0
Gateway: 10.107.1.1
My access point is configured to
IP:10.107.200.1
Range: 10.107.200.11---19 (for testing purpose only)
Subnet:10.107.200.0
Netmask:255.255.0.0
Gateway:10.107.1.1
For your information, AP1 and AP3 is the default DHCP server for the wired pcs in school. And my access point is also a wired desktop with an extra wireless interface.
so after I configured the dhcpd.conf following the how-to, the host that access thru my AP still getting the IP from AP1 or AP3. However, I'm pretty sure that my dhcp server is running, coz when i try it with the method assigning the host MAC address with IP, it works.
some said it is the netmask of AP1 or AP3 that is too wide in the range. What say you?
you could block dhcp relay's requests that are passed through from
your "localised network" to the othr DHCP server's
that way only your DHCP server can assign Dynamic IP's
as per your criteria..
Ideally
you could block dhcp relay's requests that are passed through from
your "localised network" to the othr DHCP server's
that way only your DHCP server can assign Dynamic IP's
as per your criteria..