CentOS: How to edit your NIC via the command line

There are several ways you can edit the settings of your NIC via the command line. All changes take effect right away. You can pass new configuration data directly by the command prompt or by editing the actual file responsible for the active NIC. The first method is temporary because in a case of a reboot the machine may get a new IP from the DHCP server. The second method ensure that the changes are permanent.

1st) Change the IP address directly on the command prompt:

As root you can use the ifconfig command and give the new IP address and/or the new netmask. Here is an example.

#ifconfig eth0 netmask

The change will be read instantly by the kernel. However this change is not permanent.


2nd) Change the IP address by editing the config file for your NIC:

The file that stores the configuration for your NIC  is


When you originally view this file most likely you will see the following parameters in it


The parameters you need in the file are listed below


DEVICE refers to the NIC you are working on.

IPADDR refers to the IP address assigned to the NIC

NETMASK, HWADDR DNS and Gateway are obvious.

ONBOOT is responsible for turning on or off the NIC during bootup.

BOOTPROTO refers to the protocol. As you can see in the original state of the file it had DHCP. However since we want this machine to have a static IP address we opted to enter “none”.

NM_CONTROLLED this will either allow or not for eth0 to be controlled by the NetworkManager service. For automation purposes it would be a good idea to set it to yes.




Share Button

Leave a Reply

Your email address will not be published.

Time limit is exhausted. Please reload the CAPTCHA.