How to Set Static IP on CentOS/RHEL

This article assume that you have installed CentOS or RHEL with minimum packages by unchecked all the software during the installation. Therefore, you will not be able to perform TCP/IP configuration using system-config-network or setup command which provide GUI solution. With minimum packages installed, there is the simple way to change your DHCP IP to prefered static IP address. Just follow below steps that was tested on CentOS/RHEL. Lets say the linux ip address is 192.168.2.5, Netmask is 255.255.255.0 and the default gateway is 192.168.2.1.

READ  How to Modify the Default Webmin's Port Number on CentOS 5.7

The config file for interface “eth0” is located at “/etc/sysconfig/network-scripts/ifcfg-eth0”. If the adapter is configured to use DHCP, the content should be as below :

    cat /etc/sysconfig/network-scripts/ifcfg-eth0
    
    DEVICE=eth0
    BOOTPROTO=dhcp
    HWADDR=00:xx:xx:xx:xx:xx
    ONBOOT=yes
    DHCP_HOSTNAME=[dhcphostname]
    

To change it to static IP address instead, please configure as below :

    vi /etc/sysconfig/network-scripts/ifcfg-eth0
    
    DEVICE=eth0
    BOOTPROTO=none
    HWADDR=00:xx:xx:xx:xx:xx
    ONBOOT=yes
    TYPE=Ethernet
    NETMASK=255.255.255.0
    IPADDR=192.168.2.5
    GATEWAY=192.168.2.1
    

When configuration are done, please run /etc/init.d/network restart to apply the changes

Thats all. Hope this article useful for the beginner.

1 comment
Leave a Reply

Your email address will not be published. Required fields are marked *

SiteGround.com

A world leading hosting company that provides fully-managed innovative and secure solutions, suitable for hosting small to medium-sized websites

Built on the best available technologies combined with Google Cloud for strong redundancy and application availability. Backed by skilled experts to address web security threats, a devops team to create advanced custom security solutions, and 24/7 sysadmins to watch over the platform. This powerful, hands-on approach makes your sites faster, safer, and easier to manage. Starting from only $3.95/mo.

TRY FREE

* up to 30 days money back guarantee