How to Set up DHCP

Source: Internet
Author: User
Tags perl script
How to Set up DHCP-Linux Enterprise Application-Linux server application information. Set DHCP

Don't think that I am talking so complicated in "Network basics? But isn't it complicated to set DHCP in Linux? All of you
Only one file is required? /Etc/dhcpd. conf.

Below? I used 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 measured in seconds.
? That is, three days and nine days '.
Then I specified the domain name used by the network.

What is 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 ),
Out two scopes? That is, the IP range used to allocate DHCP? 192.168.0.21 to 192.168.0.30 and
192.168.0.121 to 192.168.0.230. What's more? I also specified the 'broadcast address '? 'Router address' and 'dns address '.
Why does the second network use a 27-bit netmask? So what is the Net ID? 203.30.35.128? What is the broadcast address?
203.30.35.159.

Last? Have I set such a sentence?

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

As we know? What is the client machine that obtains an IP address through DHCP? What if the lease has expired? So it may lose the original
. But? I also want my pii266 host to always use a fixed IP address. The above sentence is
This goal is set. First? I have to find the interface type and hardware address connecting to my network on pii266?
That is? Ethernet 48: 54: E8: 27: 75: 77? Then I use 'Fixed-address' to disable 192.168.0.15.
IP addresses in DHCP scopes are allocated to pii266.

If you want to configure it by referring to the above file? Always pay attention to every punctuation mark? Some numbers use '? 'To separate?
While some are separated by space keys? And every sentence? Use '? 'Do the end (like perl script )? Otherwise? Lower
What is the continuation of a row? Instead of looking at it as a new line.

After the/etc/dhcpd. conf file is set? You also need to use the following command to create an empty/etc/dhcp. leases
White file?
Touch/etc/dhcp. leases
Note? Do you want to modify this file on your own? What if there is a problem with this file? Delete or rename it? And then use touch.
The command is created.

What do we know in "Network basics? In the early stage of DHCP operation? The client queries DHCP information in broadcast mode.
. The problem is that I have two NICs? When DHCP responds to client queries, it is difficult to determine which network to transfer? Because
Why didn't the client allocate an IP address at the beginning? So I added this line in my/etc/hosts?

2017100000000255 all-ones

Then? I also 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

So? 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.
What's the problem? What if DHCP fails to provide services? Consider using this method.

What do you do last? Reactivate the DHCP service?
/Etc/rc. d/init. d/dhcpd restart
Are there any error messages? If yes, make appropriate changes? Then 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
What about DHCP service? But? What should I pay attention? Can you provide only one sub-net service for one interface? Even
The same is true for several alias packages.

Setting is also 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? Shutdown or are you sure the ip address alias has been successfully activated? And
You must set the routing.

Below is my 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? What do you 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 examples? Will that happen?

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;
#}

# What 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.
# But for testing? I have annotated it for now.
# Host pii266 {
# Hardware ethernet 00: 00: 21: D2: 30: DA;
# Fixed-address 192.168.0.15;
#}


Test DHCP

Is HDCP easy to work? Find a Linux machine on the same network? Convert its interface to use
DHCP. For example? Modify this file in/etc/sysconfig/network-scripts/ifcfg-eth0? Change it
?

DEVICE = "eth0"
IPADDR = ""
NETMASK = ""
ONBOOT = "yes"
BOOTPROTO = "dhcp"

Then execute ifdown eth0 and ifup eth0 to reactivate the interface? Run ifconfig to check whether DHCP works.
It works.

If you are using a Windows system? So? Start --> set --> console --> network -->
'Tcp/ip-> NICs '--> IP address --> automatically obtain IP Address --> OK --> reactivate the machine.
After login? Run? Start --> Run --> winipcfg --> there is still information. You can verify DHCP settings.
If you want to change the settings on the DHCP server? You can press "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.