RSS

Configuration DHCP in linux

28 Dec

DHCP is Dynamic Host Configuration Protocol.

DHCP the service to issue the dynamic IP network. Computers that are connected to networks must be configured before communicate with other computer. DHCP allows configured automatically.

DHCP uses two port :

  • Port 67 / UDP for client sending to server
  • Port 68 / UDP for server send data to client

Why do use UDP packets in DHCP? Because, Client will sending broadcast UDP packet DHCP discovery to DHCP server. In the same time, client couldn’t know who is DHCP server. When server get the message, but client doesn’t know he. Server have to send UDP packet in port 68 and waiting for client get it.

DHCP have four step: DHCP discover, DHCP Offer, DHCP request, DHCP acknowledge

image

Today, I’m introduce step by step configuration DHCP in Linux server.

The first, we need to ensured HDCP file installation had been installed. We could checked it by:

$ rpm -qa |grep dhcp

If not have. We do:(with rpm package of CenOs or version Redhat)

$ rpm -ivh dhcp*.rpm

Or ( with tar.gz package of ubuntu version)

$ tar xvfz dhcp*tar.gz

 

Move to the newly directory and type:

./configure

 

make install

 

You can download it in :

http://www.isc.org/software/dhcp

Configure DHCP

Configuration file put in /etc/dhcpd.conf . You can consult in file dhcpd.conf.sample in usr/share/doc/dhcp…/dhcpd.conf.sample

View it:

ddns-update-style interim;

 

ignore client-updates;

 

subnet 192.168.0.0 netmask 255.255.255.0 {

 

# --- default gateway

 

option routers 192.168.0.1;

 

option subnet-mask 255.255.255.0;

 

option nis-domain "domain.org";

 

option domain-name "domain.org";

 

option domain-name-servers 192.168.1.1;

 

option time-offset -18000; # Eastern Standard Time

 

# option ntp-servers 192.168.1.1;

 

# option netbios-name-servers 192.168.1.1;

 

# --- Selects point-to-point node (default is hybrid). Don't change this unless

 

# -- you understand Netbios very well

 

# option netbios-node-type 2;

 

range dynamic-bootp 192.168.0.128 192.168.0.254;

 

default-lease-time 21600;

 

max-lease-time 43200;

 

# we want the nameserver to appear at a fixed address

 

host ns {

 

next-server marvin.redhat.com;

 

hardware ethernet 12:34:56:78:AB:CD;

 

fixed-address 207.175.42.254;

 

}

 

}

 

Some thing need to focus:

In file configuration, it like the code program. Define , { , }, endline (;). Syntax:

Subnet x.x.x.x netmask y.y.y.y {

# option . Endline by ;

}

If we need range IP for company. We focus:

range dynamic-bootp a.a.a.a b.b.b.b ;

With a.a.a.a is range begin of dynamic IP, b.b.b.b is range of end of dynamic IP

If we need some IP for special person(fixed IP). Example: we focus:

host ns {

next-server name_server;

hardware ethernet MAC_address;

fixed-address static_IP;

}

next-server can null.

Step code install:

[root@localhost ~]# mkdir -p /media/mmt

 

[root@localhost ~]# mount /dev/cdrom /media/mmt

 

mount: block device /dev/cdrom is write-protected, mounting read-only

 

[root@localhost ~]# rpm -ivh /media/mmt/CentOS/dhcp

 

dhcp-3.0.5-23.el5.i386.rpm dhcpv6-1.0.10-18.el5.i386.rpm

 

dhcp-devel-3.0.5-23.el5.i386.rpm dhcpv6-client-1.0.10-18.el5.i386.rpm

 

[root@localhost ~]# rpm -ivh /media/mmt/CentOS/dhcp-*

 

[root@localhost ~]# cp /usr/share/doc/dhcp-3.0.5/dhcpd.conf.sample /etc/dhcpd.conf

 

cp: overwrite `/etc/dhcpd.conf'? y

 

[root@localhost ~]# vi /etc/dhcpd.conf

 

Type in dhcpd.conf:

ddns-update-style interim;

ignore client-updates;

# Don't allow client update dhcp server

subnet 192.168.188.0 netmask 255.255.255.0 {

    # Zone subnet and net mask define

    # --- default gateway

 

    option routers 192.168.188.1;

    option subnet-mask 255.255.255.0;

 

    # define NIS domain DNS server

    option nis-domain "commitflame.wordpress.com";

    option domain-name "commitflame.wordpress.com";

    option domain-name-servers 192.168.1.1;

 

    option time-offset -18000; # Eastern Standard Time

    # option ntp-servers 192.168.1.1;

    # option netbios-name-servers 192.168.1.1;

    # --- Selects point-to-point node (default is hybrid). Don't change this unless

    # -- you understand Netbios very well

    # option netbios-node-type 2;

 

    # range dynamic IP

    range dynamic-bootp 192.168.188.0 192.168.188.254;

 

    default-lease-time 21600;

    max-lease-time 43200;

 

    # define fixed IP for some one. Example : the boss

    host ns {

        next-server marvin.redhat.com;

        hardware ethernet 12:34:56:78:AB:CD;

        fixed-address 192.168.188.188;

    }

}

 
Leave a comment

Posted by on December 28, 2010 in DHCP, Knowledge, Linux, zZ_IT_Define_Zz

 

Tags: , ,

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s