17

On CentOS I no longer have a ifcfg-eth0 configuration file (I deleted it). When I run system-configure-network it shows no interfaces that I can edit. How can I recreate the ifcfg-eth0 configuration file? (Like the CentOS installer does)

I can manually do a: ifconfig eth0 192.168.0.199 and then a ping 192.168.0.1. But that's not the proper way. How can I do it using the CentOS network scripts?

I prefer not to do this by hand as there are many hardlinks and confusing stuff. I am new to CentOS.

8 Answers 8

13

There might be a utility, but I don't know what it is. You can just create a file at /etc/sysconfig/network-scripts/ifcfg-eth0 with contents similar to:

DEVICE=eth0
BOOTPROTO=static
ONBOOT=yes
IPADDR=192.168.0.199
NETMASK=255.255.255.0
GATEWAY=192.168.0.1
2
  • Running system-config-network seems to be a good idea after recreating the ifcfg-eth0 file.
    – unixman83
    May 24, 2011 at 4:22
  • 7
    This answer neglects to mention the HWADDR= field which contains the MAC address of the device. This step is one of the bigger pain points of creating ifcfg-ethN by hand. Sep 18, 2014 at 19:04
5

I use the command: system-config-network-tui

Creating the file by hand is a good answer too, but this will get the MAC address for you.

2
  • For me I don't edit these files enough to create from scratch but I can more easily edit one that exists. So this utility is way faster than needing to googling until I find a trusted example. In my case it missed the ONBOOT=yes value so I still had to edit but it was much better than handwriting the whole thing from scratch. Oct 2, 2015 at 17:21
  • 4
    On Centos 7, use nmtui
    – knb
    Mar 10, 2017 at 9:58
3

This may not be valuable anymore to the asker but for someone else, if you have the gui running you can go to System > Preferences > Network Connections and a window will open. Now if you see a device listed there then click on it and just make some edit and save and the file will appear. If no device is listed (will be rare and only if you aren't getting internet connectivity) then you can simply click add and name it eth0 or whatever you like and click save. No need to edit anything, it'll automatically do it all for you.

PS: the file ifcfg-"NAME" is the name you give it in the network connections window when you created it.

2

So this Worked for me.

History:

  • I added a new Virtual Network card, whose ifcfg-eth2 file was not generated after a re-boot.

  • I navigated the the network-scripts directory and ran the commands in the below sequence.

    # cd /etc/sysconfig/network-scripts
    # ./net.hotplug
    # ./ifup-eth
    # ifup eth2
    -- the ifcfg-eth2 file was generated at this point, but was missing the "HWADDR" field --
    
    # system-config-network
    -- Select your Device and edit settings if needed, before saving the settings --
    -- After saving the Configuration settings, the "HWADDR" filed was added as well --
    
1

There is a utility called sysconf-network or something like that to allow you to manager the network connections. That is a command line utility.

Here is a link to the FAQ about their /etc/sysconfig system.

1

Under CentOS 8, I used the nmtui tool that comes with minimal installation in order to recreate the /etc/sysconfig/network-scripts/ifcfg-{interface} files. So far the easiest I found.

1
  • On CentOS 7.9 it works too. Started nmtui -> Edit a connection -> selected ethX with missing ifcfg-ethX file in /etc/sysconfig/network-script -> Edit -> In my case I wanted automatic connect -> OK -> Back (exit the program), the result, ifcfg-ethX was created. I have checked the content, looks ok. Jun 6, 2022 at 12:08
0

For example, to configure an interface with static network settings using ifcfg files, for an interface with the name enp1s0, create a file with the name ifcfg-enp1s0 in the /etc/sysconfig/network-scripts/ directory, that contains: For IPv4 configuration

DEVICE=enp1s0
BOOTPROTO=none
ONBOOT=yes
PREFIX=24
IPADDR=10.0.1.27

systemctl restart network

0

Below cmds will re-generate the ifcfg file.

nmcli device
nmcli device connect eth0
New contributor
Xinliang Liu is a new contributor to this site. Take care in asking for clarification, commenting, and answering. Check out our Code of Conduct.
1

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .