Static Linux IP Address Using the Command Line

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 [code lang=”bash”]/lib/modules/2.2.14-5.0/net[/code] where [code lang=”bash”]2.2.14-5.0[/code] is your kernel version. The source code for these drivers are usually located at [code lang=”bash”]/usr/src/linux-2.2.14/drivers/net[/code] 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 [code lang=”bash”]/etc/modules.conf[/code] or [code lang=”bash”]/etc/conf.modules[/code]depending on your distribution. If you see a line that looks similar to [code lang=”bash”]alias eth0 ne2k-pci[/code]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 [code lang=”bash”]/sbin/lsmod[/code].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:

  • Make sure the network is stopped by issuing [code lang=”bash”]/etc/rc.d/init.d/network stop[/code]
  • Manually load the module by issuing [code lang=”bash”]/sbin/insmod ne2k-pci[/code] replacing ne2k-pci with whatever your module is. This module must be present in the [code lang=”bash”]/lib/modules/2.2.14-5.0/net[/code]directory for lsmod to find it.
  • Verify it loaded successfully by issuing [code lang=”bash”]/sbin/lsmod[/code]
  • Activate the eth0 device by issuing [code lang=”bash”]/etc/rc.d/init.d/network start[/code]
  • Configure your network settings with steps 2-6. You must still be root to perform these steps.
  • Set the IP address and network mask: [code lang=”bash”]/sbin/ifconfig -a eth0 192.168.1.5 netmask 255.255.255.0[/code] This example gives the machine the IP address 192.168.1.5, but you can use any combination of IP/netmask that will work with your network.
  • Verify the settings with [code lang=”bash”]/sbin/ifconfig eth0[/code].
  • Add the default gatway: [code lang=”bash”]/sbin/route add default gw 192.168.1.254[/code] replacing 192.168.1.254 with your gateway.
  • Verify the gateway setting: [code lang=”bash”]/sbin/route[/code]The line beginning with [code lang=”bash”]default[/code] should have your gateway under the gateway column.
  • Alternately, you can edit the file [code lang=”bash”]/etc/sysconfig/network-scripts/ifcfg-eth0[/code] to look like (replace with your network numbers)[code lang=”bash”] DEVICE=eth0
    USERCTL=no
    ONBOOT=yes
    BOOTPROTO=none
    BROADCAST=192.168.1.255
    NETWORK=192.168.1.0
    NETMASK=255.255.255.0
    IPADDR=192.168.1.5
    [/code]and the file [code lang=”bash”]/etc/sysconfig/network[/code] to look like (replace with your network numbers and hostname) [code lang=”bash”] NETWORKING=yes
    HOSTNAME=name.host.net
    FORWARD_IPV4=yes
    GATEWAYDEV=
    GATEWAY=192.168.1.254[/code]
  • Ping the gateway and a few other computers on the network to verify your settings are correct.
  • Leave a Reply