Skip to content

Instantly share code, notes, and snippets.

@fernandoaleman
Created March 23, 2012 16:20
Show Gist options
  • Save fernandoaleman/2172388 to your computer and use it in GitHub Desktop.
Save fernandoaleman/2172388 to your computer and use it in GitHub Desktop.
How To Configure Static IP On CentOS 6
## Configure eth0
#
# vi /etc/sysconfig/network-scripts/ifcfg-eth0
DEVICE="eth0"
NM_CONTROLLED="yes"
ONBOOT=yes
HWADDR=A4:BA:DB:37:F1:04
TYPE=Ethernet
BOOTPROTO=static
NAME="System eth0"
UUID=5fb06bd0-0bb0-7ffb-45f1-d6edd65f3e03
IPADDR=192.168.1.44
NETMASK=255.255.255.0
## Configure Default Gateway
#
# vi /etc/sysconfig/network
NETWORKING=yes
HOSTNAME=centos6
GATEWAY=192.168.1.1
## Restart Network Interface
#
/etc/init.d/network restart
## Configure DNS Server
#
# vi /etc/resolv.conf
nameserver 8.8.8.8 # Replace with your nameserver ip
nameserver 192.168.1.1 # Replace with your nameserver ip
@lizmelbin
Copy link

Thank you so much 👍 :D

@jonsbun
Copy link

jonsbun commented Jan 27, 2018

For IP ranges you can also use my scirpt: https://github.com/jonsbun/add-ips-centos

@ben-ba
Copy link

ben-ba commented Feb 28, 2018

@Arinerron: set up your default gateway, no gateway, your systems only knows your local network (192.168.1.x/y). Furthermore you should use ip add sh, instead of ifconfig nowadays.

@MVPicazo
Copy link

OMG THANK YOU! Spent half a day trying to figure out how to create a static IP on CentOS.. this took me 5 mins to do.

@winny-
Copy link

winny- commented Apr 15, 2018

Make sure to refer to /usr/share/doc/initscripts-*/sysconfig.txt (search for /etc/sysconfig/network-scripts/ifcfg) - that's the only built-in documentation for this mechanism.

@NoobAtOpenStack
Copy link

NoobAtOpenStack commented Apr 27, 2018

Okay so dumb question that I probably don't need to worry about, is there a difference when you do ONBOOT=yes versus ONBOOT="yes" with quotes? I get using quotes if there's a space in it like your example of NAME="System eth0" but does it matter for one word entries like yes or no?

@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.

@SimsonTambunan
Copy link

Thank you so much :)

@cjyothi
Copy link

cjyothi commented Jul 19, 2018

its nice thank u

@thetalentedmrpeter
Copy link

thank you :-)

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