Linux DHCP Using the Command Line

  1. Load the proper module(driver) for your ethernet card:
    The list of compiled ethernet card drivers that come with your system are usually located under
    /lib/modules/2.2.14-5.0/net

    where

    2.2.14-5.0

    is your kernel version. The source code for these drivers are usually located at

    /usr/src/linux-2.2.14/drivers/net

    again where 2.2.14 is the kernel version you are running. Sometimes the comments at the beginning of the source code file will tell you which ethernet cards the driver is for. Some distributions will find it during installation and automatically load the driver for you. To see if this is the case, view the file

    /etc/modules.conf

    or

    /etc/conf.modules

    depending on your distribution. If you see a line that looks similar to

    alias eth0 ne2k-pci

    then the third item on the line is the module being used for your ethernet card. In this example, ne2k-pci, the NE2000 driver is being used. To verify the module has been loaded successfully, issue the command

    /sbin/lsmod
  2. This will display all modules successfully loaded in the system. Once your module is loaded, you are ready to move to the next step. If the module is not loaded, but you know what module your network card uses, issue the following steps as root:
  3. Make sure the network is stopped by issuing
    /etc/rc.d/init.d/network stop

    Manually load the module by issuing

    /sbin/insmod ne2k-pci

    replacing ne2k-pci with whatever your module is. This module must be present in the

    /lib/modules/2.2.14-5.0/net

    directory for

    lsmod

    to find it.

  4. Verify it loaded successfully by issuing
    /sbin/lsmod

    . Activate the eth0 device by issuing

    /etc/rc.d/init.d/network start

Configure your network settings with steps 2-4. You must still be root to perform these steps.

Edit/create the file

/etc/sysconfig/network-scripts/ifcfg-eth0

to use DHCP.

Sample

ifcfg-eth0

file:

DEVICE=eth0
USERCTL=no
ONBOOT=yes
BOOTPROTO=dhcp
BROADCAST=
NETWORK=
NETMASK=
IPADDR=

Replace eth0 above with eth1 if it is the second network card in your system.

Edit/create the file

/etc/sysconfig/network

to use DHCP.

NETWORKING=yes
HOSTNAME=
FORWARD_IPV4=yes
GATEWAYDEV=
GATEWAY=

Restart the network to probe the DHCP server for your network settings with the command

/etc/rc.d/init.d/network restart

Verify your network settings with the command

/sbin/ifconfig

to make sure you have received an IP address from the DHCP server.

Ping the gateway and a few other computers on the network to verify your connection.

About billy

Senior IT Technician working in Edinburgh, Scotland.
This entry was posted in Linux and tagged , . Bookmark the permalink.

Leave a Reply

Your email address will not be published. Required fields are marked *

*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>