How to assign a static IP in Linux



Assigning  a static IP on your Linux system is light. Few Tools in Linux like system-config-network and netconfig provides to you a simple to do this in GUI.

CLI ( Command Line Interface) is better GUI (Graphical User interface) , as per my cognition.

Here we go with CLI,

Navigate to  /etc/sysconfig/network-scripts/

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

In Linux, every network interface will have its 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 shown below…

[root@thiyag]# vi ifcfg-eth0.

# Realtek Semiconductor Co., Ltd. RTL8101E/RTL8102E PCI Express Fast Ethernet controller
DEVICE=eth0
HWADDR=00:24:21:52:DB:85
ONBOOT=yes
TYPE=Ethernet
BOOTPROTO=none
IPADDR=192.168.1.14
PREFIX=24
GATEWAY=192.168.1.1
DNS1=  ( Give your ISP’s DNS)
DEFROUTE=yes
IPV4_FAILURE_FATAL=yes
IPV6INIT=no
NAME=”System eth0″
UUID=5fb06bd0-0bb0-7ffb-45f1-d6edd65f3e03
NETMASK=255.255.255.0
DNS2=202.56.250.5
NM_CONTROLLED=yes
USERCTL=yes
MTU=1500

If you wish to switch back to DHCP, you can just repeat the steps above and replace the contents of the ifcfg-eth0 file with the parameters shown below…

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

Restart your interface to get apply the changes.

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

To update your DNS Server settings, modify the /etc/resolv.conf.

[root@thiyag]# 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 ( Give your ISP’s First DNS)
nameserver ( Give your ISP’s Secondary DNS)

Thats it.you have made it work.

Post to Twitter

Tags:

Subscribe to RSS via Email:

Subscribe with Updated Linux and get updates frequently in your inbox

One Response to How to assign a static IP in Linux

  1. Jack says:

    sounds good

Leave a Reply

Your email address will not be published.

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>