الجمعة، 28 مايو 2010

Linux Networking Configuring IP address

Configure IP address:


- Are you using Fedora linux or newer Redhat versions of Linux ??


Then it is very easy to configure IP address for your interface in linux. In fedora and newer redhat versions of linux, you may have noticed a directory named /etc/sysconfig/network-scripts. Some small modifications on the files of this directory will do the tricks :-)


If you want to configure an IP address for the interface eth0, you just need to create a file named ifcfg-eth0 under the directory /etc/sysconfig/network-scripts. The contents of the file should be as follows.


-------------
DEVICE= Interface_name
IPADDR=IP address
NETMASK=Netmask Value (Eg: 255.255.255.0)
BOOTPROTO=static
ONBOOT=yes
-------------

I have configured an IP address 192.168.1.100 to my interface eth0 using the following settings.

-------------
root@Basil15099/~#cd /etc/sysconfig/network-scripts
root@Basil15099//etc/sysconfig/network-scripts#cat ifcfg-eth0
#
# File: ifcfg-eth0
#
DEVICE=eth0
IPADDR=192.168.1.100
NETMASK=255.255.255.0
BOOTPROTO=static
ONBOOT=yes
#
# The following settings are optional
#
BROADCAST=192.168.1.255
NETWORK=192.168.1.0
root@Basil15099/~#
-------------

Please note that the above steps will only work with fedora linux and redhat versions.

Once the file is modified, you need to active the newly configured interface using the following commands.

-------------
root@Basil15099/~# ifdown interface_name
root@Basil15099/~# ifup interface_name
-------------

Eg:

-------------
root@Basil15099/~# ifdown eth0
root@Basil15099/~# ifup eth0
-------------

- Are you NOT USING Fedora Linux ? No worries....



As I have already told, the above method will only work with fedora and redhat versions of Linux. Here I am going to discuss some general tips to configure IP address by the use of a single command. This will work around all versions of linux so far :-)

Here is the command that assign an IP address to an interface.

-------------
root@Basil15099/~# ifconfig Interface_name IP_address netmask NET_MASK up
-------------


The "up" at the end of the command activates the interface.

Similar way, I have used the following command to configure an IP address 192.168.1.100 to my interface eth0.

-------------
root@Basil15099/~# ifconfig eth0 10.0.0.1 netmask 255.255.255.0 up
-------------


That's all!

NOTE: Once the IP address is configures using this method, what will happen when you reboot your machine ?


Of coarse, all configurations will be reset. So in order to make the configuration permanent, you need to put the above command in /etc/rc.local file. As you know, the script /etc/rc.local will be executed at the end of every reboot. So, if you add the command in the specified file, eth0 will automatically be configured with the given IP address in every reboot!!

ليست هناك تعليقات:

إرسال تعليق