Wednesday, April 4, 2012

Change IP in LINUX Static

just my reference only.


      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 'vi /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 from the file by pressing Escape (to enter vi command mode), then ":wq" and Enter

      Type 'ifdown eth0' and press enter.

      Type 'ifup eth0' and press enter.


Source : http://www.wikihow.com/Assign-an-IP-Address-on-a-Linux-Computer

------

Configuring your Linux machine to run on a static IP is easy. Tools like system-config-network and netconfig provide you simple GUIs to do this.

For today, I’ll show you how to do this from the command line instead.

Navigate to /etc/sysconfig/network-scripts/

[root@baboo]# cd /etc/sysconfig/network-scripts/

Every network interface will have it’s own interface script file. eth0,eth1,eth2 and so on. Vi the ifcfg-eth0 interface script file for interface eth0. Replace the contents of the ifcfg-eth0 file with the parameters below.

[root@baboo]# vi ifcfg-eth0.

DEVICE=eth0
TYPE=Ethernet
ONBOOT=yes
BOOTPROTO=none
IPADDR=192.168.0.100
NETMASK=255.255.255.0
GATEWAY=192.168.0.1
HWADDR=00:0F:22:71:0A:53
USERCTL=no
USERCTL=no

If you want to switch back to DHCP, repeat the steps above and replace the contents of the ifcfg-eth0 file with the parameters below.

DEVICE=eth0
BOOTPROTO=dhcp
HWADDR=00:0F:20:71:0A:50
ONBOOT=yes
TYPE=Ethernet
DHCP_HOSTNAME=klmdrpdr01p.klm1.netcel360.com

Restart your interface to apply the changes.

[root@baboo]#ifdown eth0
[root@baboo]#ifup eth0

To update your dns server settings, modify the /etc/resolv.conf.

[root@baboo]# vi /etc/resolv.conf

Replace the contents of the resolv.conf file with the parameters below. The first parameter “search” is your search path followed the nameserver parameters which hold the IPs for your primary and secondary DNS servers.

search example.com
nameserver 192.168.0.5
nameserver 192.168.0.6

source : http://thedaneshproject.com/posts/how-to-configure-a-static-ip-in-linux/