CentOS: Configure network

This tutorial is intended for system administrators wanting to either change the IP address or add additional LAN cards (NIC) on their CentOS 5 system. There are a couple of ways to configure the network card using the command line but only some commands will take immediate effect on kernel. If you are doing this remotely remember that you will lose connectivity or if your configuration on your network is incorrect be unable to connect.

Configure network with immediate effect

Using a single command line to configure the network


Configure network with setup or netconfig

If you are using netconfig (or) setup utility it will only overwrite the /etc/sysconfig/network-scripts/ifcfg-eth0 file. Then , after that u have to restart the network service like follow,

Network configuration -> Edit Devices -> eth0 (eth0) – Intel Corporation 82540EM Gigabit Ethernet Controller

Save your settings and quit


Edit Devices -> eth0 (eth0) – Intel Corporation 82540EM Gigabit Ethernet Controller

Save your settings and quit

Restart your network in order for your configuration to take effect.

Configure network by editing configuration

Lastly you can configure the network by editing the configuration files stored in the /etc/sysconfig/network-scripts/ directory.

Append/modify as follows:

Save and close the file. Define default gateway and hostname in /etc/sysconfig/network configuration file

Append/modify configuration as follows:

Save and close the file. Restart networking:

  • Torikul

    Nice post…Thanks a lot………Keep it up!

  • Peter

    This helped a lot today! Cheeers!

  • Macgyvertr

    Worked for me too. I loves from Turkey armful. 🙂

  • Eng Beshoy95

    sorry i set network and i but default dns for me is dns of yahoo as i have a problem in my network 
    but i access yahoo web but can’t access the mail link 
    so i want to know my problem is what ?
    please , i want to solve this problem 
    me email is   eng.beshoy95@yahoo.com

  • Anuragranjan242

    I want to connect Ethernet cable to centos 6 by manually and use the image

  • Mafatahna

    nice info

  • Syedimran

    I like it very much

  • G.Zografov

    Great “How to”!
    Thanks for your post.
    Greetings from Bulgaria.

  • MR.Zero1

    Thanks To Post :X
    I Have Questions
    1.How To Save In Command ? For Example In Windows ” Ctrl+s ”
    Now in Linux ?
    2. After The Edit Network , Can i log in too centos with putty ?

    Thanks a Lot

  • Barangsin

    Thank for your Post.

  • Rick Buczynski

    Great post! Very helpful to a Linux newbie 🙂

  • Junaid Ashraf

    You Will save the Vi file.
    first press the (Esc ) Button.
    then type
    :wq this mean save and quite the file

  • Paul Laudenslager

    Thank you! I thought it was a driver issue on a new install of Centos 6.5. It was the ONBOOT=yes that was my problem – mine was set to no.
    Thanks again from Virginia!

  • Deep S.

    A simple edit in /etc/sysconfig/network-scripts/ifcfg-eth0
    ONBOOT=yes (before no) solved my issue. Save it and reboot.