Urgent! Ifconfig ip address not same as under network-scripts file

Issues related to configuring your network
Post Reply
Posts: 1
Joined: 2021/04/08 01:02:14

Urgent! Ifconfig ip address not same as under network-scripts file

Post by adamyau » 2021/04/08 01:55:48

we have a cantos server running on a hyper V. It has 2 nice. Someone powered off the VM by accident. After we restarted the server, there lost connection. And we found out tate the ip address was wrong. The ip addressws show in IFCONFIG are wrong but the ip in ifcfg-eht0/ifcfg-eth1 are correct. How come they are different? I have restarted the server again. but still remain the same problem. can anyone pls help. I don't know linux. This server was configured by someone long ago.
ifconfig.jpg (129.52 KiB) Viewed 86 times

User avatar
Forum Moderator
Posts: 30579
Joined: 2009/09/24 10:40:56
Location: Brighton, UK

Re: Urgent! Ifconfig ip address not same as under network-scripts file

Post by TrevorH » 2021/04/08 10:42:31

The ip addresses are as you specified them but they are assigned to the opposite interface.

Try editing the ifcfg-ethX files and adding to each of them HWADDR="00:15:5d:11:0b:xx" where xx is the right digit to match the correct MAC address on the NICs you have.
CentOS 6 died in November 2020 - migrate to a new version!
Info for USB installs on http://wiki.centos.org/HowTos/InstallFromUSBkey
CentOS 5 is dead, do not use it.
Full time Geek, part time moderator. Use the FAQ Luke

User avatar
Posts: 3435
Joined: 2007/12/11 08:17:33
Location: Finland

Re: Urgent! Ifconfig ip address not same as under network-scripts file

Post by jlehtone » 2021/04/08 13:57:26

First: default method to configure network in CentOS 7 is NetworkManager.service. The more or less mutually exclusive method is network.service. If your system does use NetworkManager, then you do get a summary with nmcli

Second: the ifconfig and route commands did get better alternatives two decades ago. Whether you have NetworkManager or not, you can look at active configuration with:

Code: Select all

ip -s li
ip ad
ip ro
If NetworkManager is in use, then it is safer to use NetworkManager's tools: nmcli, nmtui, or the GUI applet to modify the config.
To see both saved and active config of those two connections one could use:

Code: Select all

nmcli con show eth0
nmcli con show "System eth1"
The ethN device names use the "old style". The names are created in the order the devices are enumerated during boot and that order is random. I have encountered this precisely with VM's. (On some virtualization platforms CentOS still uses the "old style" automatically.)

The CentOS installer does create NetworkManager connections and they do bind the config to device by the MAC address (the HWADDR variable) that in nmcli output shows as setting: 802-3-ethernet.mac-address.
If one defines a connection manually with nmcli, then it requires name of the device (shown as setting: connection.interface-name) and does not set the 802-3-ethernet.mac-address.

The "new style" device names ought to be predictable, i.e. persistent -- same on every boot -- and there matching config to device by connection.interface-name is sufficient.

There can be an additional hiccup: firewall.
Firewall rules can match device names. If the two connections should have different firewall rules, then the device names are used.
If the actual device names can change on every boot, then firewall rules must be written/updated during boot too.

The default solution in CentOS is to use FirewallD, which reads from the network connection which ruleset that connection does use what name the device has this time. That is about only decent feature in FirewallD that I can think of.

Post Reply

Return to “CentOS 7 - Networking Support”