5

When after I change dhcp to static in network-scripts and then I restart servicesystemctl restart NetworkManager. The static ip settings suppose to be updated but it doesn't. so I try

ip link set dev enp0s3 down and then up

didn't update the ip

and then I try with ifdown enp0s3 then ifup enp0s3

it worked

Why has it worked with ifup?

Rui F Ribeiro
  • 56,709
  • 26
  • 150
  • 232
ppc
  • 123

2 Answers2

5

Preamble: ip and ifconfig are utilities for controlling and monitoring networking. They are not typically used for reading/writing persistent configuration files - and this is why ip link did not work. Persistent configuration management has to be accomplished by other means, such as NetworkManager.

(It's likely needless to say, but, as a side note, iproute2, which provides ip, has been/is being adopted by many distributions as a replacement for net-tools, which provides ifconfig. They are often both shipped as default packages in distributions for compatibility reasons).

Why ifup worked and systemctl restart NetworkManager did not:

On CentOS (I have checked for CentOS 7), ifup and ifdown are provided by initscripts; they operate on the scripts in /etc/sysconfig/network-scripts/, provided by the same package. Thus, no surprise in ifup being able to apply the changes you made there.

NetworkManager - the default networking service provider that CentOS inherited from upstream - on Red Hat and Fedora is configured to use the ifcfg-rh plugin to read/write network configuration from /etc/sysconfig/network-scripts/ifcfg-*. But it does not monitor those files.

man nm-settings-ifcfg-rh warns that

Users can create or modify the ifcfg-rh connection files manually, even if that is not the recommended way of managing the profiles. However, if they choose to do that, they must inform NetworkManager about their changes (see monitor-connection-file in nm-settings(5), and nmcli con (re)load).

Thus, systemctl reload NetworkManager is not supposed to reload the configuration of a network connection from file on CentOS. To do that you can invoke nmcli connection reload or change NetworkManager configuration as stated in man NetworkManager.conf:

monitor-connection-files
Whether the configured settings plugin(s) should set up file monitors and immediately pick up changes made to connection files while NetworkManager is running. This is disabled by default; NetworkManager will only read the connection files at startup, and when explicitly requested via the ReloadConnections D-Bus call. [...]

fra-san
  • 10,205
  • 2
  • 22
  • 43
  • thank you :) how do you check which packages belong to which group package – ppc Nov 20 '18 at 07:17
  • Sorry for being late. I'm not an expert here, I would just suggest to start from this answer on StackOverflow. To list packages in a given group: yum groups info your_group. To know which group a package belongs to: yum groups info '*' | less +/your_package or yum groupinfo '*' | less +/your_package. – fra-san Nov 21 '18 at 16:27
2

ip directly changes the state of the hardware, just like ifconfig. The only difference between ifconfig and ip is that ip has a different syntax, and supports some features ifconfig doesn't.

ifup and ifdown, on the other hand, run a lot of scripts, read your /etc/network/interfaces file and other configuration files, and act on that. That includes adding the static IP settings which you probably put into /etc/network/interfaces.

In principle, Network Manager should pick up those, too, but I don't run Network Manager (most of the time it gets in my way), so I can't tell you why it didn't work.

So: if you want your network configuration files to be taken into consideration, use ifup/ifdown and Network Manager. If you want to directly change the interface settings, use ip and ifconfig.

dirkt
  • 32,309
  • 1
    Right for debian based distro. For RHEL the network scripts should be under /etc/sysconfig/network-scripts/ – GAD3R Nov 19 '18 at 09:27