Use Linux as a DHCP server

Source: Internet
Author: User
Tags range firewall linux

In most cases Linux acts as a DHCP server and Windows 95/98 is a DHCP client. Linux can also be a DHCP customer, that is, you want to install the DHCPCD RPM software package, Linux as a DHCP server, just install DHCPD rpm package.

A Prerequisites for a DHCP server to work:

In order for the DHCP server to serve the Windows machine, you may need to create a route to address 255.255.255.255, plus this routing command to/etc/rc.d/rc.local so that it runs automatically after each boot.

    #route add -host 255.255.255.255 dev eth0

If you report an error message: 255.255.255.255:unkown host

Try adding the following entry to the/etc/hosts file:

    #route add -host dhcp dev eth0 。

Two The DHCPd daemon always reads the configuration file/etc/dhcpd.conf, and here's an example of a DHCP configuration file:

    #Sample /etc/dhcpd.conf
  
     default-lease-time 1200;
  
     max-lease-time 9200;
  
     option subnet-mask 255.255.255.0;
  
     option broadcast-address 192.168.1.255;
  
     option routers 192.168.1.254;
  
     option domain-name-servers 192.168.1.1,192.168.1.2;
  
     option domain-name "mydomain.org";
  
     subnet 192.168.1.0 netmask 255.255.255.0 {
  
     range 192.168.1.10 192.168.1.100;
  
     range 192.168.1.150 192.168.1.200;
  
     }

This will allow the DHCP server to assign two segments of the address range to the customer 192.168.1.10-100 or 192.168.1.150-200, or the maximum allowable lease time of 9,200 seconds if the client does not continue to request a DHCP address and then releases the IP address after 1200 seconds.

The server sends the following parameter to the DHCP client: Use 255.255.255.0 as the subnet mask, use 192.168.1.255 as the broadcast address, 192.168.1.254 as the default gateway, and 192.168.1.1 and 192.168.1.2 as DNS server if you want to specify a WINS server for Windows clients, you need to include the following options in the dhcpd.conf file: Option Netbios-name-servers 192.168.1.1.

Three. You can also specify a fixed IP address for a certain network card, whenever this card will always obtain a fixed IP address from the DHCP server, add the following statement to the/etc/dhcpd.conf:

   host haagen {
  
     hardware ethernet 08:00:2b:4c:59:23;
  
     fixed-address 192.168.1.222;
  
     }

can also be ligatures to one line:

    host Jephe {hardware ethernet 00:a0:c9:a6:96:33;fixed-address 192.168.1.12;}

You can also specify a different gateway address, name server, etc. for a particular machine:

Host Jephe {Hardware Ethernet 00:a0:c9:a6:96:33;fixed-address 192.168.1.12;option routers 192.168.11.5;}

Four. In most cases, the installation of DHCP does not create a dhcpd.leases file, and before you start the DHCP server, you must create an empty file dhcpd.leases:

  #touch /var/state/dhcp/dhcpd.leases

To start the DHCP server, simply enter the/USR/SBIN/DHCPD or use #ntsysv to automatically start the DHCP service, which will start dhcpd on the eth0 device, and if you want to start dhcpd on the eth1 device, #/usr/sbin/dhc PD eth1; If you are debugging DHCP, use #/usr/sbin/dhcpd-d-F.

Five Two NIC cases:

Sometimes you need to install a DHCP service on a machine that has two network cards installed (as a firewall or gateway), the following example indicates a DHCP setting on a firewall machine because the external network card (Internet) does not require DHCP service.

Therefore, this setting is as follows:

    subnet 192.168.1.0 netmask 255.255.255.0 {
  
     range 192.168.1.2 192.168.1.4;
  
     default-lease-time 86400;
  
     max-lease-time 259200;
  
     option subnet-mask 255.255.255.0;
  
     option broadcast-address 192.168.1.255;
  
     option routers 192.168.1.254;
  
     option domain-name-servers 192.168.1.254;
  
     }
  
     subnet 202.102.34.102 netmask 255.255.255.255 {
  
     }

Six FAQ

A. Fixed IP address for MAC machine?

When you set the Mac computer to obtain IP address with DHCP, if you do not know what address, you can send a message on the Mac, the recipient can check the IP address of the sender through mail header, and then ping the IP address and then use the ARP command to check the ARP cache in the The corresponding physical address of the IP address.

B. If a Windows machine has a DHCP-enabled software, such as Sygate, Wingate, and so on, other Windows clients may prefer to look for Windows DHCP servers rather than Linux DHCP servers.

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.