Configure static IP on CentOS/Redhat/Fedora

configure static ip centos

I – Introduction

In this short article i will show you how to configure a static ip on Centos and Redhat in cli mode and not via the GUI.

In my side i usually use Debian distribution, but recently i needed to install some Centos production server. And in Centos it’s quite different than Debian OS distribution.

II – Configure eth0 with static IP

All network configuration file are located in directory /etc/sysconfig/network-scripts/, In contrary in Debian, there is two file to modified.

For this example, i will use these parameter :

  • IP address/netmask : 10.254.0.1/24
  • Gateway: 10.254.0.254
  • Nameserver : 8.8.8.8
root@centos:~# vim /etc/sysconfig/network-scripts/ifcfg-eth0
DEVICE="eth0"
BOOTPROTO="static"
HWADDR="66:1A:XX:XX:XX:XX"
NM_CONTROLLED="yes"
ONBOOT="yes"
TYPE="Ethernet"
UUID="generated by the os"
IPADDR=10.254.0.1
NETMASK=255.255.255.0

III – Configure the default gateway

root@centos:~# vim /etc/sysconfig/network
NETWORKING=yes
HOSTNAME=server.ec0.local
GATEWAY=10.254.0.254

IV – Configure the default nameserver


root@centos:~# vim /etc/resolv.conf

search home sysadmin-community.local
nameserver 8.8.8.8

V – And to finish, apply the new configuration

There is two solution :

The first solution :


root@centos:~# ifdown eth0 && ifup eth0

The second solution :


root@centos:~# service network restart

VI – Checking the configuration


root@centos:~# ifconfig eth0 && route -n
# OR
root@centos:~# ip addr show

VII – More informations

https://www.centos.org/docs/5/html/Deployment_Guide-en-US/ch-networkscripts.html

florian

Hi, I'm Florian and I'm 32 years old. I have discover IT at 17, and i had my first internet connection at 23. So i'm not going to say that i was very precocious in this domain... PS : I 'm French, so please, be lenient with my english ;)

Leave a Reply

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

This site uses Akismet to reduce spam. Learn how your comment data is processed.