linux – ip-tools vs old ifconfig

当我在网络脚本中将dhcp更改为静态然后重新启动servicesystemctl后重新启动NetworkManager.静态IP设置假设要更新,但事实并非如此.所以我试试

ip link设置dev enp0s3向下然后向上

没有更新ip

然后我尝试ifdown enp0s3然后ifup enp0s3

有效

为什么它与ifup一起使用?

解决方法:

序言:ip和ifconfig是用于控制和监控网络的实用程序.它们通常不用于读/写持久性配置文件 – 这就是为什么ip link不起作用的原因.持久配置管理必须通过其他方式完成,例如NetworkManager.

(这可能不用说了,但是,作为旁注,iproute2,提供ip,has been/is being adopted由许多发行版作为网络工具的替代品,提供ifconfig.出于兼容性原因,它们通常作为默认包发布在发行版中) .

为什么ifup工作和systemctl重启NetworkManager没有:

在CentOS上(我已经检查过CentOS 7),ifup和ifdown是由initscripts提供的;它们对/ etc / sysconfig / network-scripts /中的脚本进行操作,由同一个包提供.因此,ifup能够应用您在那里所做的更改并不奇怪.

NetworkManager – CentOS从上游继承的默认网络服务提供商 – 在Red Hat和Fedora上配置为使用the ifcfg-rh plugin从/ etc / sysconfig / network-scripts / ifcfg- *读取/写入网络配置.但它不会监视这些文件.

man nm-settings-ifcfg-rh警告说

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).

因此,systemctl重载NetworkManager不应该从CentOS上的文件重新加载网络连接的配置.为此,您可以调用nmcli连接重新加载或更改NetworkManager配置,如manManagerManager.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. […]

上一篇:重启网卡报错RTNETLINK answers: File exists


下一篇:linux – 使用/ etc / sysconfig / network-scripts / ifcfg-eth *文件