How to Set dhcpd in linux

Source: Internet
Author: User
Tags perl script

How to Set dhcpd in linux
How to Set DHCP in linux


Setting DHCP in linux is not complicated at all. All you have to do is to set up one file:/etc/dhcpd. conf.

Next, I will use my own settings file to explain 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 file. The first and second rows define the default term and maximum term of the lease contract ﹐
The value is calculated in seconds, that is, 'three days' and 'Nine days '. Then I specified the domain name used by the network.

Next ﹕

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 has been created successfully {
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 two NICs that provide DHCP services to both networks. Under the first network (192.168.0.0 ),
The IP address range for DHCP allocation is 192.168.0.21 to 192.168.0.30 and
192.168.0.121 to 192.168.0.230. In addition, I have also specified 'broadcast address', 'router address', and 'dns address '.
Because the second network uses a 27-bit netmask, the Net ID is 203.30.35.128, and the broadcast address is ﹕
203.30.35.159.

Finally, I set the following sentence ﹕

Host pii266 {
Hardware ethernet 48: 54: E8: 27: 75: 77;
Fixed-address 192.168.0.15;
}

As we know, if the client machine used DHCP to obtain the IP address has expired, the original lease may be lost.
. However, I think my pii266 host will always use a fixed IP address. The above sentence is
This goal is set. First, I need to find the interface type and hardware address connecting to my network on the pii266 machine ﹐
That is, ethernet 48: 54: E8: 27: 75: 77. Then I use 'Fixed-address' to remove 192.168.0.15 from
IP addresses in DHCP scopes are allocated to pii266.

If you want to configure it by referring to the above file, be sure to pay attention to every punctuation mark. Some numbers are separated by commas ﹐
While some use space keys to separate tokens, and each sentence must end with 'distinct' (the same as perl script). Otherwise
A row is considered as a continuation of the row, rather than a new row.

After setting the/etc/dhcpd. conf file, you must use the following command to create an empty/etc/dhcp. leases file:
White file ﹕
Touch/etc/dhcp. leases
Note: do not modify the file by yourself. If there is a problem with the file, delete or rename it, and then use touch.
The command is created.

We already know in "Network basics" that in the early stage of DHCP operation, the client queries DHCP information through broadcast.
. The problem is that I have two NICs. It is difficult for DHCP to determine which network to transfer to in response to the client query.
At the beginning, the client has not been assigned an IP address, so I added this line to my/etc/hosts ﹕

2017100000000255 all-ones

Then, I added this description in/etc/rc. d/rc. local ﹕
# Lines added by netman,
# For enabling DHCP routing on multi-nodes environement:
Echo "Adding IP routing for DHCP server ..."
Route add-host route 255.255.255 dev eth0
Route add-host route 255.255.255 dev eth1

In this way, when the machine is activated, the DHCP route is set. However, it seems that there is no need to worry about the new linux version.
This problem occurs. If you find that DHCP fails to provide services, consider using this method.

Finally, you need to re-activate the DHCP service ﹕
/Etc/rc. d/init. d/dhcpd restart
Check whether there is any error message. If yes, make appropriate changes and try to activate dhcpd (use start instead of restart ).

Set DHCP for IP Alias

In some scenarios, we may use IP Alias to connect to the network. At this time, we can also
DHCP service is provided. However, you must note that you can only provide a sub-net service for one interface, even if
The same is true for several alias packages.

The setting is quite simple ﹕

Set the network where alias is located.
Then, cancel the subnet of the original IP address in/etc/dhcpd. conf.
Only the range of the network where alias is located can be left.

In my tests,/etc/dhcpd. conf is not the most important thing. to shut down the server, make sure that the ip address alias has been successfully activated.
You must set the routing.

The following is a preliminary process ﹕


1. Activate dhcpd:

If you have any interfaces up
&&
And the routing has been set {

If the original interface sub-net has already been declare {
# Whether or not you delcare the sub-net in which alias is located
Dhcpd can be activated successfully.
}

Otherwise {# If the original interface sub-net does not have declare
If the sub-net in which alias is located already declare {
If the alias sub-net has set the routing {
Dhcpd can be activated successfully
}
Otherwise {# If the alias sub-net is not configured with routing
When you activate dhcpd, you will get ﹕
No subnet declaration for ethx (original IP Network)
.
}
}

Otherwise {# If the sub-net in which alias is located does not have declare
The error "No subnet declaration for ethx" is returned.
}
}
}

-------
2. Operate dhcpd

After your dhcpd is successfully activated {

If you have the sub-net {
Range settings {
# Whether or not you have set the sub-net and range of alias
Dhcpd only offer sub-net of the original Interface
}
Otherwise {# No range settings
# Whether or not you have set the sub-net and range of alias
After receiving DHCPDISCOVER, dhcpd will respond and say ﹕
No free leases on subnet (sub-net on the original Interface)
}

Otherwise {# If you do not declear the sub-net where the original interface is located
If the sub-net {# where alias is located does not exist, dhcpd activation fails.
Range settings {
Dhcpd will offer alias sub-net
}
Otherwise {# No range settings
After receiving DHCPDISCOVER, dhcpd will respond and say ﹕
No free leases on subnet (sub-net of alias)
}
}
}

==========
If I look at my example, it will look like this ﹕

Default-lease-time 259200;
Max-lease-time 777600;
Option domain-name "siyongc ";

# I will annotate the sub-net interface below
# 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 sub-net setting of alias ﹕
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;
}


# The fixed IP Address can also be used for allocation.
# I have annotated it for testing.
# Host pii266 {
# Hardware ethernet 00: 00: 212: 30A;
# Fixed-address 192.168.0.15;
#}


Test DHCP

It is not easy to test whether HDCP works. Find a linux machine on the same network and convert its interface to use.
DHCP. For example, modify the/etc/sysconfig/network-scripts/ifcfg-eth0 file
As follows ﹕

DEVICE = "eth0"
IPADDR = ""
NETMASK = ""

BOOTPROTO = "dhcp"

Run ifdown eth0 and ifup eth0 to reactivate the interface, and then run ifconfig to check whether DHCP is enabled.
It works.

If you are using a Windows system, start --> set --> console --> network -->
'Tcp/ip-> NICs '--> IP address --> automatically obtain IP Address --> OK --> reactivate the machine.
After logging on, run start --> Run --> winipcfg -->. You can verify DHCP settings.
If you want to change the settings on the DHCP server, click "update all" to check whether the new settings take effect.

Related Article

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.