How to create NetworkManager dispatcher script to remove local route?
Environment
- Red Hat Enterprise Linux 7
- Red Hat Enterprise Linux 8
- Red Hat Enterprise Linux 9
- Red Hat Enterprise Linux 10
- NetworkManager
Issue
- How to create NetworkManager dispatcher script to remove local route?
- How to remove local route persistently?
Resolution
NOTE: Removing a local route can break Layer 2 (L2) communication on the server. Before applying this solution, ensure it will not cause any unintended impact.
- Create a file named 99-remove-route inside the
/etc/NetworkManager/dispatcher.d/directory with the following content:
#!/bin/bash
if [ "$2" = "up" ]; then
/usr/sbin/ip route del 192.0.2.0/24<-Specify the local Network
fi
- Grant execute permission to the script and Restart the NetworkManager service to apply the changes.
$ chmod a+x /etc/NetworkManager/dispatcher.d/99-remove-route
$ systemctl restart NetworkManager
Diagnostic Steps
- Check the route by executing following command
Before:
$ ip route show all
default via 192.0.2.1 dev ens2 proto static metric 100
192.0.2.0/24 dev ens2 proto kernel scope link src 192.0.2.2 metric 100
After:
$ ip route show all
default via 192.0.2.1 dev ens2 proto static metric 100
This solution is part of Red Hat’s fast-track publication program, providing a huge library of solutions that Red Hat engineers have created while supporting our customers. To give you the knowledge you need the instant it becomes available, these articles may be presented in a raw and unedited form.
Comments