Skip to content

Instantly share code, notes, and snippets.

@keshara
Last active April 24, 2021 02:08
Show Gist options
  • Save keshara/2f50045430ab193006af to your computer and use it in GitHub Desktop.
Save keshara/2f50045430ab193006af to your computer and use it in GitHub Desktop.
Static IP Configuration on CentOS 6.5
The reason I wanted to share this post is configuring static IP on CentOS seems to trouble many centos users. Probably, when you configure static IP, network may not work as you expected, sometimes no internet access, sometimes no IP address on eth0 etc..
First, "watch-out whether it is a CentOS Desktop version or Server version".? because they are runs at different run-levels, where;
- Desktop ver runs on run-level 5
- Server ver runs on run-level 3
Second, watch-out the configuration on
$ vi /etc/sysconfig/network-scripts/ifcfg-eth0
DEVICE=eth0
HWADDR=00:AA:BB:CC:DD
NM_CONTROLLED=no ------------------------------------ specify not to controlled by "NetworkManager"
ONBOOT=yes ------------------------------------------ specify to bring up the interface(eth0) at boot
IPADDR=192.168.1.10
NETMASK=255.255.255.0
NOTE By default, "NetworkManager" service is run at run-level 5
As you can see, we explicitly tell the system not to control the network interfaces by "NetworkManager" service. Due to this, when you set this configuration on CentOS Desktop, network will not starts as there is no services to control network interfaces.
Now you may think that, Ok, lets change the configuration as NM_CONTROLLED=yes. Of course, this will make NetworkManager to bring the interface(eth0) up and to have an IP address assigned on it. But the problem is that the system still doesn't know the gateway IP address, which could be locates at $ vi /etc/sysconfig/network.
I think now you already scene, "well if the NetworkManager cannot bring up the network right with all the configuration, we need another service that will do the job right"
Yes, there is and that service is "network". But what happened behind the seen is that this service, by default, is not started at run-level 5(as you are in Desktop version).
Lets tell the system to start the "network" service at run-level 5.
$ sudo chkconfig --level 5 network on
Apart from that, make sure
GATEWAY IP address in set at
$ vi /etc/sysconfig/network
NETWORKING=yes
HOSTNAME=localhost.localdomain
GATEWAY=192.168.1.1
DNS server address in set at
$ vi /etc/resolv.conf
nameserver 8.8.8.8
!!!!! - that's all. reboot the system and check your system - !!!!!
@ikt
Copy link

ikt commented Sep 28, 2014

ty

@aditi6622
Copy link

I have done all the things as guided but still internet is not working, on using ping command it says unknown hosts: . I did exactly same as asked.please do help me.i tried almost everything.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment