2.6. Using NetworkManager with Network Scripts
This section describes how to run a script and how to use custom commands in network scripts.
network scripts refers to the script
/etc/init.d/network and any other installed scripts it calls. Although NetworkManager provides the default networking service, scripts and NetworkManager can run in parallel and work together. Red Hat recommends to test them first.
Running Network Script
Run a network script only with the
The systemctl utility clears any existing environment variables and ensures correct execution.
In Red Hat Enterprise Linux 7, NetworkManager is started first, and
/etc/init.d/network checks with NetworkManager to avoid tampering with NetworkManager's connections. NetworkManager is intended to be the primary application using sysconfig configuration files, and
/etc/init.d/network is intended to be secondary.
/etc/init.d/network script runs:
It is a manual process and does not react to events that happen after boot. Users can also call the
- manually - using one of the
- on boot and shutdown if the network service is enabled - as a result of the
systemctl enable networkcommand.
ifdown scripts manually.
systemctl reload network.service command does not work due to technical limitations of initscripts. To apply a new configuration for the network service, use the
This brings down and brings up all the Network Interface Cards (NICs) to load the new configuration. For more information, see the Red Hat Knowledgebase solution Reload and force-reload options for network service.
systemctl restart network.service
Using Custom Commands in Network Scripts
Custom commands in the
ifdown-local scripts are only executed if these devices are controlled by the
/etc/init.d/network service. The
ifup-local file does not exist by default. If required, create it under the
ifup-local script is readable only by the initscripts and not by NetworkManager. To run a custom script using NetworkManager, create it under the
dispatcher.d/ directory. See the section called “Running Dispatcher scripts”.
Modifying any files included with the initscripts package or related rpms is not recommended. If a user modifies such files, Red Hat does not provide support.
Custom tasks can run when network connections go up and down, both with the old
network scripts and with NetworkManager. If NetworkManager is enabled, the
ifdown script will ask NetworkManager whether NetworkManager manages the interface in question, which is found from the “DEVICE=” line in the
Devices managed by NetworkManager:
- calling ifup
- When you call
ifupand the device is managed by NetworkManager, there are two options:
- If the device is not already connected, then
ifupasks NetworkManager to start the connection.
- If the device is already connected, then nothing to do.
- calling ifdown
- When you call
ifdownand the device is managed by NetworkManager:
ifdownasks NetworkManager to terminate the connection.
Devices unmanaged by NetworkManager:
If you call either
ifdown, the script starts the connection using the older, non-NetworkManager mechanism that it has used since the time before NetworkManager existed.
Running Dispatcher scripts
NetworkManager provides a way to run additional custom scripts to start or stop services based on the connection status. By default, the
/etc/NetworkManager/dispatcher.d/ directory exists and NetworkManager runs scripts there, in alphabetical order. Each script must be an executable file owned by
root and must have
write permission only for the file owner. For more information about running NetworkManager dispatcher scripts, see the Red Hat Knowledgebase solution How to write a NetworkManager dispatcher script to apply ethtool commands.