Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
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
@mbadran

This comment has been minimized.

Show comment Hide comment
@mbadran

mbadran Mar 2, 2013

Nice overview.

You can also run dhclient (once off) to automatically update the /etc/resolv.conf file.

mbadran commented Mar 2, 2013

Nice overview.

You can also run dhclient (once off) to automatically update the /etc/resolv.conf file.

@vikramkamath

This comment has been minimized.

Show comment Hide comment
@vikramkamath

vikramkamath Mar 12, 2013

excellent! thanks this was helpful :)

excellent! thanks this was helpful :)

@ezhuravlev

This comment has been minimized.

Show comment Hide comment
@ezhuravlev

ezhuravlev May 7, 2013

thx

thx

@ghost

This comment has been minimized.

Show comment Hide comment
@ghost

ghost Jun 27, 2013

Just downloaded centos 6.4 and was stunned that it does not detect my onboard nic. Thank you so much :)

ghost commented Jun 27, 2013

Just downloaded centos 6.4 and was stunned that it does not detect my onboard nic. Thank you so much :)

@aklesky

This comment has been minimized.

Show comment Hide comment
@aklesky

aklesky Jul 21, 2013

Thank you!

aklesky commented Jul 21, 2013

Thank you!

@deffjay

This comment has been minimized.

Show comment Hide comment
@deffjay

deffjay Aug 7, 2013

Great, thanks!

deffjay commented Aug 7, 2013

Great, thanks!

@ropaolle

This comment has been minimized.

Show comment Hide comment
@ropaolle

ropaolle Oct 1, 2013

Nice!

ropaolle commented Oct 1, 2013

Nice!

@hsiaoting

This comment has been minimized.

Show comment Hide comment
@hsiaoting

hsiaoting Oct 11, 2013

good reference. :)

good reference. :)

@Yinette

This comment has been minimized.

Show comment Hide comment
@Yinette

Yinette Oct 21, 2013

"NETWORKING=yes" Never fails to make me giggle.

Yinette commented Oct 21, 2013

"NETWORKING=yes" Never fails to make me giggle.

@bib4311

This comment has been minimized.

Show comment Hide comment
@bib4311

bib4311 Oct 23, 2013

what is this uuid and how can i find it i am new linux user

thanks in advance for reply

bib4311 commented Oct 23, 2013

what is this uuid and how can i find it i am new linux user

thanks in advance for reply

@aghasoroush

This comment has been minimized.

Show comment Hide comment
@aghasoroush

aghasoroush Nov 28, 2013

Thanks you very much!

Thanks you very much!

@aghasoroush

This comment has been minimized.

Show comment Hide comment
@aghasoroush

aghasoroush Nov 28, 2013

Thanks you very much!

Thanks you very much!

@aghasoroush

This comment has been minimized.

Show comment Hide comment
@aghasoroush

aghasoroush Nov 28, 2013

Thanks you very much!

Thanks you very much!

@chipsfingrar

This comment has been minimized.

Show comment Hide comment
@chipsfingrar

chipsfingrar Dec 16, 2013

Great stuff, saved me a lot of time!

Great stuff, saved me a lot of time!

@jgdev

This comment has been minimized.

Show comment Hide comment
@jgdev

jgdev Dec 30, 2013

Hey, thanks, really ;)

jgdev commented Dec 30, 2013

Hey, thanks, really ;)

@thomasong

This comment has been minimized.

Show comment Hide comment
@thomasong

thomasong Jan 9, 2014

thanks, really

thanks, really

@thomasong

This comment has been minimized.

Show comment Hide comment
@thomasong

thomasong Jan 9, 2014

thanks, really

thanks, really

@palamrit

This comment has been minimized.

Show comment Hide comment
@palamrit

palamrit Jan 9, 2014

I don't have eth0 in folder, please suggest I am pasting directory dump

ifcfg-lo ifdown-ppp ifup-ippp ifup-sit
ifdown ifdown-routes ifup-ipv6 ifup-tunnel
ifdown-bnep ifdown-sit ifup-isdn ifup-wireless
ifdown-eth ifdown-tunnel ifup-plip init.ipv6-global
ifdown-ippp ifup ifup-plusb net.hotplug
ifdown-ipv6 ifup-aliases ifup-post network-functions
ifdown-isdn ifup-bnep ifup-ppp network-functions-ipv6
ifdown-post ifup-eth ifup-routes

Please suggest

palamrit commented Jan 9, 2014

I don't have eth0 in folder, please suggest I am pasting directory dump

ifcfg-lo ifdown-ppp ifup-ippp ifup-sit
ifdown ifdown-routes ifup-ipv6 ifup-tunnel
ifdown-bnep ifdown-sit ifup-isdn ifup-wireless
ifdown-eth ifdown-tunnel ifup-plip init.ipv6-global
ifdown-ippp ifup ifup-plusb net.hotplug
ifdown-ipv6 ifup-aliases ifup-post network-functions
ifdown-isdn ifup-bnep ifup-ppp network-functions-ipv6
ifdown-post ifup-eth ifup-routes

Please suggest

@piousbox

This comment has been minimized.

Show comment Hide comment
@piousbox

piousbox Jan 17, 2014

@palamrit, you should try ifup-eth and ifup-wireless

@palamrit, you should try ifup-eth and ifup-wireless

@modevans

This comment has been minimized.

Show comment Hide comment
@modevans

modevans Jan 20, 2014

Awesome!@@!

Awesome!@@!

@anubratakoley

This comment has been minimized.

Show comment Hide comment
@anubratakoley

anubratakoley Feb 19, 2014

Great stuff, saved me a lot of time!

Great stuff, saved me a lot of time!

@anubratakoley

This comment has been minimized.

Show comment Hide comment
@anubratakoley

anubratakoley Feb 19, 2014

Thanks you very much!

Thanks you very much!

@abhipurohi

This comment has been minimized.

Show comment Hide comment
@abhipurohi

abhipurohi Mar 3, 2014

Thanks for this stuff

but when i tried to "/etc/sysconfig/network-scripts/ifcfg-eth0" its showing file directory not available.
after that i tried to edit "vi /etc/sysconfig/network/ifcfg-eth0" then its showing access denied but i login from "root".

Thanks for this stuff

but when i tried to "/etc/sysconfig/network-scripts/ifcfg-eth0" its showing file directory not available.
after that i tried to edit "vi /etc/sysconfig/network/ifcfg-eth0" then its showing access denied but i login from "root".

@J-4-DEGS

This comment has been minimized.

Show comment Hide comment
@J-4-DEGS

J-4-DEGS Mar 3, 2014

Thank you very much, quite helpful!

J-4-DEGS commented Mar 3, 2014

Thank you very much, quite helpful!

@bigdatasunil

This comment has been minimized.

Show comment Hide comment
@bigdatasunil

bigdatasunil Mar 21, 2014

I had followed the instructions mentioned but still it's not working, what would be the name server ip address if i m using wireless network(home), i am using wireless network, i tried with both Bridge network and NAT, but no luck, could you please help me...

I had followed the instructions mentioned but still it's not working, what would be the name server ip address if i m using wireless network(home), i am using wireless network, i tried with both Bridge network and NAT, but no luck, could you please help me...

@ralexx

This comment has been minimized.

Show comment Hide comment
@ralexx

ralexx Mar 23, 2014

Sweet! Thanks

ralexx commented Mar 23, 2014

Sweet! Thanks

@hunghq19

This comment has been minimized.

Show comment Hide comment
@hunghq19

hunghq19 Apr 13, 2014

I'm fowlowed you. But I tried ping to google.com. I got ping: unknow host google.com. Please help me solve problem

I'm fowlowed you. But I tried ping to google.com. I got ping: unknow host google.com. Please help me solve problem

@killahquam

This comment has been minimized.

Show comment Hide comment
@killahquam

killahquam Apr 23, 2014

Awesome! Thanks
Q

Awesome! Thanks
Q

@declum

This comment has been minimized.

Show comment Hide comment
@declum

declum Apr 24, 2014

Hi,

I have configured static IP address (192.168.1.23). But everytime i boot up, its picking another IP address. (192.168.1.100).

But after the boot up, if i give "service network restart" it gets changed to my static IP. If the network is not restarted, its with its own (192.168.1.100). If i check the ifcfg-eth0 file, i see the IP which i have given.

How to fix it?

Regards,
Clement

declum commented Apr 24, 2014

Hi,

I have configured static IP address (192.168.1.23). But everytime i boot up, its picking another IP address. (192.168.1.100).

But after the boot up, if i give "service network restart" it gets changed to my static IP. If the network is not restarted, its with its own (192.168.1.100). If i check the ifcfg-eth0 file, i see the IP which i have given.

How to fix it?

Regards,
Clement

@nasery

This comment has been minimized.

Show comment Hide comment
@nasery

nasery May 10, 2014

how to change linux centose ip address

nasery commented May 10, 2014

how to change linux centose ip address

@unikhil

This comment has been minimized.

Show comment Hide comment
@unikhil

unikhil Jul 4, 2014

Hi Clement,

I have similar problem , everytime I reboot its pickingip another IP. Is your problem resolved? have you found reason?

Regards,

unikhil commented Jul 4, 2014

Hi Clement,

I have similar problem , everytime I reboot its pickingip another IP. Is your problem resolved? have you found reason?

Regards,

@keshara

This comment has been minimized.

Show comment Hide comment
@keshara

keshara Jul 19, 2014

Check below link if someone still have issues with static ip on centos 6.
https://gist.github.com/keshara/2f50045430ab193006af

keshara commented Jul 19, 2014

Check below link if someone still have issues with static ip on centos 6.
https://gist.github.com/keshara/2f50045430ab193006af

@zrajm

This comment has been minimized.

Show comment Hide comment
@zrajm

zrajm Mar 23, 2015

Based on a Redhat network config, I simply added the DNS by adding the following extra lines to /etc/sysconfig/network-scripts/ifcfg-eth0. Then after restarting the network I already had the correct values in /etc/resolv.conf.

 DNS1=8.8.8.8
 DNS2=8.8.4.4

zrajm commented Mar 23, 2015

Based on a Redhat network config, I simply added the DNS by adding the following extra lines to /etc/sysconfig/network-scripts/ifcfg-eth0. Then after restarting the network I already had the correct values in /etc/resolv.conf.

 DNS1=8.8.8.8
 DNS2=8.8.4.4
@kakheo

This comment has been minimized.

Show comment Hide comment
@kakheo

kakheo Mar 23, 2015

Thank you!

kakheo commented Mar 23, 2015

Thank you!

@grobin89

This comment has been minimized.

Show comment Hide comment
@grobin89

grobin89 Apr 16, 2015

Hey declum/unikhil,

I had the same issue but managed to resolve it. The service NetworkManager appears to override any configurations made in /etc/sysconfig/network-scripts. A couple of remedies:

  1. Add the line NM_CONTROLLED=no to the config file.... or

  2. Disable network manager by

systemctl stop NetworkManager.service systemctl disable NetworkManager.service

Hey declum/unikhil,

I had the same issue but managed to resolve it. The service NetworkManager appears to override any configurations made in /etc/sysconfig/network-scripts. A couple of remedies:

  1. Add the line NM_CONTROLLED=no to the config file.... or

  2. Disable network manager by

systemctl stop NetworkManager.service systemctl disable NetworkManager.service
@bvassilis

This comment has been minimized.

Show comment Hide comment
@bvassilis

bvassilis Apr 22, 2015

Thanks!!!

Thanks!!!

@JayMaree

This comment has been minimized.

Show comment Hide comment
@JayMaree

JayMaree May 10, 2015

Thanks! Need to create my own note :)

Thanks! Need to create my own note :)

@mike-bailey

This comment has been minimized.

Show comment Hide comment
@mike-bailey

mike-bailey Jul 2, 2015

Thanks! Helped a lot.

Thanks! Helped a lot.

@mahamuniraviraj

This comment has been minimized.

Show comment Hide comment
@mahamuniraviraj

mahamuniraviraj Jul 31, 2015

Thank you so much.

Thank you so much.

@jorge-1987

This comment has been minimized.

Show comment Hide comment
@jorge-1987

jorge-1987 Aug 31, 2015

Great! Thanks for share!

Great! Thanks for share!

@ranjith520

This comment has been minimized.

Show comment Hide comment
@ranjith520

ranjith520 Oct 30, 2015

Thanks

Thanks

@ponpanit

This comment has been minimized.

Show comment Hide comment
@ponpanit

ponpanit Feb 27, 2016

Great!
it's work confirm!!!!

Great!
it's work confirm!!!!

@zhaizhongping

This comment has been minimized.

Show comment Hide comment
@zhaizhongping

zhaizhongping Mar 28, 2016

thanks

thanks

@DougSr

This comment has been minimized.

Show comment Hide comment
@DougSr

DougSr 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!

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

This comment has been minimized.

Show comment Hide comment
@skumar12001

skumar12001 Apr 14, 2016

Thanks..

Thanks..

@ObeliskNet

This comment has been minimized.

Show comment Hide comment
@ObeliskNet

ObeliskNet Apr 28, 2016

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!

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

This comment has been minimized.

Show comment Hide comment
@dbaranidharan

dbaranidharan May 10, 2016

Thanks, It's helpful to me.

Thanks, It's helpful to me.

@ameyaagashe

This comment has been minimized.

Show comment Hide comment
@ameyaagashe

ameyaagashe Jun 18, 2016

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

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

@Darksaint08

This comment has been minimized.

Show comment Hide comment
@Darksaint08

Darksaint08 Aug 8, 2016

@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

@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

This comment has been minimized.

Show comment Hide comment
@Arinerron

Arinerron Aug 28, 2016

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

@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

This comment has been minimized.

Show comment Hide comment
@wellington1993

wellington1993 Sep 5, 2016

Thanks! Lower is better!

wellington1993 commented Sep 5, 2016

Thanks! Lower is better!

@abbymalson

This comment has been minimized.

Show comment Hide comment
@abbymalson

abbymalson Sep 15, 2016

Thank you

Thank you

@calmamani

This comment has been minimized.

Show comment Hide comment
@calmamani

calmamani Oct 6, 2016

Thank you. :-)

Thank you. :-)

@Ganisherjon

This comment has been minimized.

Show comment Hide comment
@Ganisherjon

Ganisherjon Nov 15, 2016

Thanks!!!!

Thanks!!!!

@anteracorp

This comment has been minimized.

Show comment Hide comment
@anteracorp

anteracorp Jan 26, 2017

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

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

@LuckyX182

This comment has been minimized.

Show comment Hide comment
@LuckyX182

LuckyX182 Apr 26, 2017

Thank you very much!

Thank you very much!

@arunm8489

This comment has been minimized.

Show comment Hide comment
@arunm8489

arunm8489 Sep 22, 2017

thank you..

thank you..

@lizmelbin

This comment has been minimized.

Show comment Hide comment
@lizmelbin

lizmelbin Dec 10, 2017

Thank you so much 👍 :D

Thank you so much 👍 :D

@jonsbun

This comment has been minimized.

Show comment Hide comment
@jonsbun

jonsbun Jan 27, 2018

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

jonsbun commented Jan 27, 2018

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

@ben-ba

This comment has been minimized.

Show comment Hide comment
@ben-ba

ben-ba 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.

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

This comment has been minimized.

Show comment Hide comment
@MVPicazo

MVPicazo Mar 30, 2018

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.

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-

This comment has been minimized.

Show comment Hide comment
@winny-

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

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

This comment has been minimized.

Show comment Hide comment
@NoobAtOpenStack

NoobAtOpenStack 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?

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?

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