Sunday, April 13, 2008

How to Assign An IP Address on a Linux Computer

How to Assign an IP Address on a Linux Computer

Linux is the free, open-source alternative to Microsoft Windows and Mac. The operating system itself can be chopped down entirely to a raw text console, or it can utilize a window manager such as Gnome or KDE. This guide will explain how to assign a static IP address on a Linux system through the use of a text console. Although this can usually be accomplished within the system settings of a window manager, different window managers may differ in this process; therefore, by using a simple step-by-step console guide, someone using almost any distribution of Linux can follow this guide. This guide assumes that you know a little bit about Linux, and you know how networks, IP addresses, and DNS servers work.

Steps
Switching to Root
If you are not already logged in as 'root' (the Linux counterpart of 'Administrator'), open a console program and type 'su' (without quote) and press enter.
Note: *buntu Linux distributions usually have the root password the same as the account created when the operating system was installed.
Enter your root password when prompted, and press enter.

Debian / Ubuntu / Kubuntu
Make a backup of your /etc/network/interfaces file by typing the following in the console: 'cp /etc/network/interfaces /etc/network/interfaces.backup'
Type 'vim /etc/network/interfaces' and press enter. Press 'i' to enter into insert (editing) mode.
Scroll down until you find your network interface card in the file (usually named eth0 for an ethernet connection, or wlan0 or wifi0 for a wifi connection).
Change 'iface eth0 inet dhcp' to 'iface eth0 inet static'
Add the following lines, substituting the IP address numbers with your desired configuration:

address 192.168.0.10
netmask 255.255.255.0
network 192.168.0.0
broadcast 192.168.0.255
gateway 192.168.0.1
dns-nameservers 216.10.119.241
Save and exit by pressing escape, then typing: ':wq' (including the colon)
Type 'ifdown eth0' and press enter.
Type 'ifup eth0' and press enter.

Red Hat or Slackware
The easiest method in Red Hat or Slackware is to type 'netconfig' in a console as the root user. A text-based menu will guide you through its configuration settings.
Use tab to move between fields. Use the spacebar to uncheck or check checkboxes.
When you have input the desired settings, press OK.
To make these settings take effect, type 'service network restart' in the console and press enter (this step is not necessary under Slackware, where the changes are immediate).

Note: There are numerous distributions based on Red Hat Linux (Fedora Core, CentOS, White Box, et cetera); many of them are likely to avail one the same method.

Dynamic IP address (DHCP)

Dynamic addresses are obtained automatically and usually do not any attention from the user. However there are several specific cases:
If the network has not been available all the time while the system was starting, the internet connection may stay disabled even after fixing the network problems. To revive it instantly, run dhclient as root. This will set the dynamic address.
The previous situation may happed if the network is accessed by separate hardware that starts at the same time as your machine. In some cases Linux boots faster than the network router and finds no network at startup. Find dhclient.conf (for instance, /etc/dhcp3/dhclient.cof for Debian) and add/correct the line reboot nn;, where nn is the delay for which the system must wait after booting, for the router to start.

No comments: