| Grabber Softwares : Enhance Your Computing |
Configuring DHCP And DNS Services Set up Linux to allocate IP address and act as a name server Setting up DHCP on Red Hat If your network has a large number of clients, manually configuring every machine with a static IP address is a tough job. The Dynamic Host Configuration Protocol (DHCP) lets you automatically assign an IP address to a machine on the network from a pool or range of IP addresses it has. To configure a DHCP server on your Linux machine, you need to create a file called dhcpd.conf in the /etc directory. This file contains all the information that the daemon needs while starting up. This file is in the following format (the line numbers are not part of the file, theyre for the explanation that follows):
Lets look at these lines a bit more closely. The first line specifies the (sub)network that the DHCP server is to manage or maintain. Within this network, we have to configure different parameters (written within the curly braces). The next line contains the range from which the server picks up IP addresses to allocate. The starting and ending IP addresses are entered here. Line 3 contains the default lease time. A lease is the amount of time that a particular machine can hold an IP address before having to renew the lease with the server. The value is given in number of seconds, so 86400 stands for one day. The next line, max-lease-time, specifies the maximum amount of time that a machine can hold on to a specific IP address. Then come other options that will also be transmitted to the machine. These include the subnet mask, the router, the domain name server, and the domain name. Once this is done, you need to create a file called dhcpd.leases, also in the /etc/ directory, which will contain information about which IP address has been allocated to which machine. Since all this will be done by the server, all you need to do is create a 0 byte file with the command, touch /etc/dhcpd.leases. The next step requires you to add a broadcast route. Do this by appending the line /sbin/route add host 255.255.255.255 dev eth0 to /etc/rc.d/rc.local. Finally, make sure DHCP is started at bootup. You can do this by running Setup, choosing ntsysv, and enabling dhcpd. Restart the machine, by giving the command sync, followed by reboot. Your DHCP server will be up and running after the machine starts up. Any machine that logs on the network will receive an IP address and all other parameters automatically. If its a Win 95 client, you can check all the settings by running winipcfg in the Run dialog box. There may be cases when you need to assign a particular machine the same IP address always. You can either hardwire the information in the computer or add the following lines to the dhcpd.conf file.
This specifies the ethernet address, which will be unique, the IP address that will always be allocated to that machine, and a host name. With DHCP, the network administrators nightmare of correctly setting up IP addresses on machines simply vanishes. Youll never need to manually configure another machine ever again. Domain Name server on Linux Before starting on the actual procedure for setting up a Domain Name Server (DNS) on Linux, let us first understand what DNS is, and how it works. The Domain Name Server, DNS in short, is the service that lets you use name like www.yahoo.com instead of a complex IP address like 203.45.224.55. Domain Name Servers map IP addresses to host names and vice-versa. You set a particular server to be your DNS which has some mappings already done for you. When you request a particular host name, say, via your Web browser, your DNS first checks whether it has an entry for the host name you asked. If it has, it passes on the IP address; otherwise, it sends the request to its DNS. The same procedure happens for DNS and so on, till the name is found, or it reaches the root domain name servers maintained by the InterNIC. If the name is not found even there, an error is cascaded down all the way to your client. If found, all the DNSs on the way update their database of mappings. Most of this is done automatically, so you dont have to worry too much. There are two types of mappings possible: forward and reverse. Forward stores the host name to IP mappings and Reverse stores the opposite, that is, IP to host name mappings. Linux stores all the mappings and other information in simple ASCII format in four different files. Before you set these files up, you need to create or modify a file called named.boot in the /etc directory. This file contains information required to start the DNS. The structure of the file is like this:
Here the directory specifies the full path to the files that store the mappings (for example, /var/named), the cache specifies the name of the cache file that stores the list of the root DNS server on the Net. The dns_type is usually set to primary and the domain to your domain name. You need three entries, one each for the local database, a forward mapping and a reverse mapping file. A typical named.boot file would look like the following:
Youll notice that the IP addresses are given in reverse order, with the last octet removed. This is to mimic the way that domain naming works, which is the reverse of the way that IP works. The IN-ADDR.ARPA domain contains all the reverse mappings possible. Now youre all set to create the files named above. Remember to replace cmil.com with your domain name. For your convenience we have a script on the PCQ CD-ROM, called makensfiles, which creates these files. You may need to update the files with information pertaining to your domain. The named.ca stores the names of all the root servers on the Internet. This file can be just downloaded from ftp://rs.internic.net/domain/named.root and saved here. You can even add the names of your ISP (VSNL) to this, right at the top. Just follow the structure already existing in the file. The named.cmil.com.forward file stores the host name to IP address mappings for your domain. That is if your domain is abc.com, each line specifies hosts in this domain. Each line takes the form: name IN A IP_address. By default, all the hosts in the file are numbered from ws1 to ws254 and corresponding IP addresses in your network. For example, ws13 would map to, say, 192.168.1.13. You can then access it by ws13.abc.com. If you need to map different host names, just change the name for that particular address. You can also add other address which may not be part of your network. For example, if you have a mail server in the US called mail.abc.com with an IP address as 202.34.56.12, just add the line mail IN A 202.34.56.12. You can test your forward DNS setup by pinging any host name. For example, ping ws13.abc.com should receive a response from 192.168.1.13. The named.cmil.com.reverse stores just the opposite of the above. It stores the last octet of your network with the complete host name for the IP address. For the same machine in the example above, there will be an entry like 13 IN PTR ws13.abc.com. All you need to do in this file is to change the host names (that too only if you need to) for machines that have a different entry in the forward file. You do not need to add mappings for addresses outside your domain. For setting up the defaults, run the pcqupdt script from the PCQUPDT directory on the CD-ROM, if you havent already done so. One of the steps asks you whether you wish to set up DNS on your server. Select yes here, and the script automatically creates default files and places them in the correct directories. All you need to do is edit the required files for customizing your server. You must remember to restart the name server daemon after all the changes are done by using the command: /etc/rc.d/init.d/named restart. Your Domain Name Server should be up and running if youve done everything correctly. |