How to set up DHCPD in Linux

Source: Internet
Author: User
Tags change settings perl script

How to set up DHCP in Linux


It's not complicated to set up DHCP under Linux, all you have to do is just one file:/etc/dhcpd.conf.  

below, I use my own settings file to say how to modify this file:

Default-lease-time 259200;  
Max-lease-time 777600;  
option Domain-name "SIYONGC";  

I put these lines at the beginning of the document. First and second lines I define the default period and the maximum period for the lease,
values are calculated in seconds, i.e. ' three days ' and ' nine days '. Then I specified the domain name used by the network.  

Next is:

Subnet 192.168.0.0 netmask 255.255.255.0 {
range 192.168.0.21 192.168.0.30;  
range 192.168.0.121 192.168.0.230;  
option broadcast-address 192.168.0.255;  
option routers 192.168.0.17;  
option Domain-name-servers 192.168.0.17, 203.56.8.1;  


Subnet 203.30.35.128 netmask 255.255.255.224 {
range 203.30.35.140 203.30.35.157;  
option broadcast-address 203.30.35.159;  
option Routers 203.30.35.134
option Domain-name-servers 203.30.35.134 203.56.8.1;  



here, I have a total of two network cards to provide DHCP services to two networks respectively. Under the first network (192.168.0.0) I specify
out of two scope, that is used to assign DHCP IP ranges:192.168.0.21 to 192.168.0.30 and
192.168.0.121 to 192.168.0.230. In addition, I also specified the ' broadcast address ' ﹑ ' router address ' and ' DNS address '.  
The second network because the netmask, is used for the net ID is:203.30.35.128, and the broadcast address is:
203.30.35.159.  

Finally, I set up a sentence like this:

host pii266 {
Hardware Ethernet 48:54:e8:27:75:77;  
fixed-address 192.168.0.15;  


as we know, a client machine that obtains IP through DHCP, if its lease has expired, may lose its original
of IP. But I want my pii266 again. This host always uses a fixed IP address. The above sentence is to
for this purpose. First, I have to find the interface types and hardware addresses that connect to my network on the pii266 machine .
that's:ethernet 48:54:e8:27:75:77,, and then I'm going to use ' fixed-address ' to 192.168.0.15 this .
the IP within the DHCP scopes is assigned to pii266.  

If you refer to my above file for Setup, be sure to pay attention to every punctuation, some numbers are ', ' to separate ,
Others are separated by the spacebar, and each sentence is terminated with '; ' (as in Perl script), otherwise, the next
The face line will be treated as a continuation of the row, not as a new line.  

When this/etc/dhcpd.conf file is set up, you will also use the following command to create a/etc/dhcp.leases empty
White file:
touch/etc/dhcp.leases
Note: You should not attempt to modify this file yourself, if there is a problem with the file, delete it or rename it, then use Touch
The command is created.  

we already know in the "Network Foundation": At the beginning of the DHCP operation,,client uses the broadcast method to query the DHCP information
the. The problem is I have two NICs here.,dhcp to respond to client queries it is difficult to determine which network to upload to, because
for the first time the client was not assigned an IP address, so I added this line to my/etc/hosts:

255.255.255.255 all-ones all-ones

then I added this narrative to the/etc/rc.d/rc.local:
# Lines added by Netman,
# for enabling DHCP routing on Multi-nics environement:
echo "Adding IP routing for DHCP server ..."
Route add-host 255.255.255.255 Dev eth0
Route add-host 255.255.255.255 Dev eth1

this way, the,DHCP route is set when the machine is activated. However, it seems that the new version of Linux does not have to worry
This problem, if you find that DHCP is not a successful service, then consider using this method.  

The last thing you need to do is reactivate the DHCP service :
/etc/rc.d/init.d/dhcpd Restart
Notice if there are any error messages, make the appropriate changes, and then try activating DHCPD (using start instead of restart).  

set up DHCP for IP Alias

In some cases, we may use IP Alias to connect to the network. At this time, we can also be the alias of the network
to provide DHCP services! However, it is important to note that you can only provide a sub-net service for a single interface, even if the boundary
There are several alias bindings on the side.  

the setting is pretty simple too:

set the network where alias is located.  
then the/etc/dhcpd.conf originally about the original IP where the subnet cancellation.  
just leave the range of the alias's network available.  

in my test,/etc/dhcpd.conf is not the most important, shutdown or to determine the IP alias has been successfully activated, and
routing must be set well.  

here is my initial process of sorting out:


1, activating dhcpd:

If you have any interface already up
&&
and the routing has been set . {

if the original interface sub-net has been declare good {
# # So whether or not you delcare good alias sub-net
DHCPD can be activated successfully.  


otherwise {#如果原有界面 sub-net no declare
If alias is sub-net already declare {
If alias is located sub-net already set routing {
DHCPD can be successfully activated

Otherwise {#如果 alias is located sub-net not set routing
when you activate DHCPD, you should get:
No Subnet declaration for ETHX (Legacy IP Network)
information that failed.  



Otherwise {#如果 alias is located sub-net no declare .
will also get No subnet declaration for ETHX error




------- 
2, operation DHCPD

after your dhcpd has been successfully activated {

If you have declear the original interface is located sub-net {
there is a range setting {
# # Then whether you set the sub-net and range for alias
DHCPD will only offer the sub-net of the original interface.

otherwise {#没有 range settings
# # Then whether you set the sub-net and range for alias
DHCPD received DHCPDISCOVER will respond that:
no free leases on subnet (Sub-net of original interface)


otherwise {#如果您并没有 Declear the original interface is located sub-net
If an alias is located sub-net {#没有的话 DHCPD has failed while activating
there is a range setting {
DHCPD will offer alias location sub-net

otherwise {#没有 range settings
DHCPD received DHCPDISCOVER will respond that:
no free leases on subnet (alias location sub-net)




======== 
If you look at my example, this will be the case:

Default-lease-time 259200;  
Max-lease-time 777600;  
option Domain-name "SIYONGC";  

# # Below I annotate the original interface sub-net .
#subnet 192.168.0.0 netmask 255.255.255.0 {
# Range 192.168.0.21 192.168.0.30;  
# Range 192.168.0.121 192.168.0.230;  
# option Broadcast-address 192.168.0.255;  
# option routers 192.168.0.17;  
# option Domain-name-servers 192.168.0.17, 203.56.8.1;  
#}  

# # This is the setting for alias Sub-net :
Subnet 192.168.1.0 netmask 255.255.255.0 {
range 192.168.1.21 192.168.1.30;  
option broadcast-address 192.168.1.255;  
option routers 192.168.1.17;  
option Domain-name-servers 192.168.1.17, 203.56.8.1;  



# # You can also use the fixed IP method to allocate
# # But for the test, I've been commenting for the moment #
#host pii266 {
# Hardware Ethernet 00:00:21 theA;  
# fixed-address 192.168.0.15;  
#}  


test DHCP

to test whether HDCP is working, find a Linux machine on the same network and turn its interface into use
Just DHCP. For example, modify the/etc/sysconfig/network-scripts/ifcfg-eth0 file to change it
into this:

device= "eth0"
ipaddr= ""
netmask= ""

bootproto= "DHCP"

then perform ifdown eth0 and ifup eth0 to reactivate the interface, then execute ifconfig and you'll know if DHCP
worked out.  

If you're using a Windows system, then: Start-up----Network ----
' TCP/IP--network card '--IP address--automatically obtains an IP address----------to reactivate the machine.  
when logged in, do: Start-up---winipcfg--there is still information. You can verify the DHCP settings.  
If you want to change settings on the DHCP server side, you can click Update all to see if the new settings are in effect.

How to set up DHCPD in Linux

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.