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
@ranjith520
Copy link

Thanks

@dotnop
Copy link

dotnop commented Feb 27, 2016

Great!
it's work confirm!!!!

@zhaihotmail
Copy link

thanks

@DougSr
Copy link

DougSr commented Apr 4, 2016

Wow you don't know how much I did battle with a broken set-up because of bad advice.
Because of this write-up it now works beautifully.
Thank you!

@skumar12001
Copy link

Thanks..

@ObeliskNet
Copy link

I must say when I started configuring static IP's on Cent OS 7 via CLI it was pretty confusing, but then i understood it - it became much easier. Without need to disable Network Manager, just type this command “nmtui” to open Network manager and edit any connection. This is super easy and no VI , NANO are needed. Plus can reset adapter too. Hope this will help others as well. Regards!

@dbaranidharan
Copy link

Thanks, It's helpful to me.

@ameyaagashe
Copy link

How about /etc/hosts file which has reference to server along with alias?

@Darksaint08
Copy link

@Azhung I had the same issue but fixed it by adding the line GATEWAY=10.0.1.1 (Replacing with your correct gateway, of course) to /etc/sysconfig/network-scripts/ifcfg-eth0

@Arinerron
Copy link

@fernandoaleman @Azhung

Can't figure it out. Seems to have a problem setting the IP. I'm trying to set it to 192.168.1.223

$ ping 8.8.8.8
connect: Network is unreachable

$ ifconfig
eth0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500
        ether [snipped] txqueuelen 1000 (Ethernet)
        RX packets 23993 bytes 1768614 (1.6MiB)
        RX errors 0 dropped 0 overruns 0 frame 0
        TX packets 2243 bytes 634063 (619.2 KiB)
        TX errors 0 dropped 0 overrun 0 carrier 0 collisions 0
        device interrupt 20 memory 0xf7c00000-f7c20000
lo: [snipped: irrelevant]

@wellington1993
Copy link

wellington1993 commented Sep 5, 2016

Thanks! Lower is better!

@the-great-abby
Copy link

Thank you

@calmamani
Copy link

Thank you. :-)

@Ganisherjon
Copy link

Thanks!!!!

@anteracorp
Copy link

Muchas gracias - been using this for a long time as reference for static IP. Rock on!

@LuckyX182
Copy link

Thank you very much!

@arunm8489
Copy link

thank you..

@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