How to set DHCPD in Linux

Source: Internet
Author: User

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 change 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 common two NICs 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 due to the use of the netmask,, Net ID is:203.30.35.128, and the broadcast address is:
203.30.35.159.  

Finally, I set up this sentence:

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


as we know, the client machine that obtains the IP via DHCP, assuming its lease has expired, may well lose its original
of IP. Just, 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 take a look at my above file for Setup, be sure to pay attention to each punctuation mark, some numbers are separated by ', ' ,
And some 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 need to create an empty /etc/dhcp.leases with the following command
White file:
touch/etc/dhcp.leases
Note: You should not attempt to change 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 it is very difficult to infer which network to upload to in response to a client query , because
I added this line to my/etc/hosts when the client side was not assigned an IP address at the beginning of the start:

255.255.255.255 all-ones all-ones

then I added this narrative in/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 today's new version of Linux does not seem 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 activate the DHCP service again :
/etc/rc.d/init.d/dhcpd Restart
Notice if there is an error message, 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. This is where we can also
To provide DHCP services! Just be aware 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 that the IP alias has been successfully activated, and
Routing must be set well.



Here are some of the processes I've initially sorted out:


1, activating dhcpd:

Let's say you have whatever interface is up.
&&
And the routing has been set . {

Assuming that the original interface sub-net has been declare good {
# # So whether or not you delcare the good alias location sub-net
DHCPD can activate successfully.

 


otherwise {#假设原有界面 sub-net no declare
Assuming that alias is sub-net already declare {
assume that alias is located sub-net already set routing {
DHCPD can successfully activate

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 {

Suppose you have declear the original interface is located sub-net {
there is a range setting {
# # Then no matter if you set the Sub-net and range of alias
DHCPD will only offer the sub-net of the original interface.

otherwise {#没有 range settings
# # Then no matter if you set the Sub-net and range of 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
Assuming that alias is in 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)




======== 
Suppose to look at my example, it would be this:

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;  



# # Here also can be used fixed IP method to allocate
# # Just to test it, I'm on a temporary note #
#host pii266 {
# Hardware Ethernet 00:00:21 theA;  
# fixed-address 192.168.0.15;  
#}  


test DHCP

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

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

bootproto= "DHCP"

then run Ifdown eth0 and ifup eth0 to activate the interface again, then run ifconfig and you'll know if DHCP
worked out.



Let's say you're using a Windows system, then: Start-up----Network --and
' TCP/IP--network card '--and IP address--Take your own active IP address---OK--and activate the machine again.  
When logged in, run: Start-up-run-to-winipcfg information. You will be able to verify the DHCP settings.  
assuming you want to modify the settings on the DHCP server side, you can press "all updates" to see if the new settings are in effect.

How to set 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.