DYNAMIC OR STATIC IP SETUP IN LINUX

Posted by Mehroz Ashraf | Posted in , , , , , , , , , , , , , , , | Posted on 8:20 AM

LINUX NETWORK SETUP


In Linux network setup can be done in two ways. In the first phase of our discussion we will discuss Dynamic IP, and in the second phase we will discuss static IP.


  • Dynamic IP


If your router is set to enable DHCP mode, your router will itself assign an IP to your linux machine . Always ensure that your Network cable is plugged into your network port.


STEP 1


log in your system and type the following command in CLI:

[root@localhost ~]# ifconfig          // similar to ipconfig in windows

ifconfig command will display all the network interfaces in your system with their current status.

STEP 2


Ensure that IP is assigned to your machine. If not follow this step. In CLI type:

[root@localhost ~]#ifup eth0  // eth0 is the  interface card 0, eth1, eth2
OR
[root@localhost ~]# service network restart
OR
[root@localhost ~]# /etc/init.d/network stop
[root@localhost ~]# /etc/init/d/network start



  • Static IP:

STEP 1


To assign static ip, open the configuration file. Configuration file is located usually on the following path:
/etc/sysconfig/network-scripts/

OR
If you are unable to locate the configuration file, you may search for the file by using the following command:

[root@localhost ~]# find / -name ifcfg-eth0


STEP 2

Now let us assume that the default path,mentioned in violet, is the actual path of the configuration file.
Open your configuration file:
[root@localhost ~]# vi /etc/sysconfig/network-scripts/ifcfg-eth0


STEP 3


Append/Replace the following information/ or as required:

IPADDR= X.X.X.X                       // e.g 192.168.1.10 (remember to replace the ip with the X)
NETMASK=255.255.255.0          //your netmask according to your IP. This is your subnet mask
GATEWAY=192.168.1.1              // or your gateway address
BOOTPRO=STATIC                   //  BOOTPRO=dhcp as default


STEP 4


Save the file and exit. To specify DNS open the following file:
/etc/resolve.conf
OR
find resolve.conf
[root@localhost ~]# find / -name resolve.conf
[root@localhost ~]# vi /etc/resolve.conf

write in file
nameserver X.X.X.X  //your 1st DNS address
nameserver X.X.X.X  //your 2nd DNS address

Save the file and exit


STEP 5

This is the last step. Here we need to use the command for restarting the network.

[root@localhost ~]# service network restart
OR
[root@localhost ~]# /etc/init.d/network restart

Verify that you can access internet using the below commands:
[root@localhost ~]# nslookup www.google.com

This command will return the IP address of google.com

THERE YOU GO, YOUV"E CONFIGURED YOUR OWN NETWORK!!!!
ANY QUESTIONS, DON'T HESITATE TO ASK....

Comments (0)

Post a Comment