Created Tue May, 28 2019 at 12:30PM
If you want to run something before or after starting up your network interfaces you can do so with the following scripts. If they don't exist, just create them and they will be called via /etc/sysconfig/network-scripts/ifup
and /etc/sysconfig/network-scripts/ifdown
scripts.
#Before bringing up interfaces:
/sbin/ifup-pre-local
#Before shutting down interfaces:
/sbin/ifdown-pre-local
#After bringing up interfaces
/sbin/ifup-local
#After shutting down interfaces
/sbin/ifdown-local
I was creating a save iptables & ipset rules on system shutdown and restoring them on system startup.
I used post shutdown network (ifdown-local
):
#!/bin/bash
ipset save > /home/vagrant/ipset_save
iptables-save > /home/vagrant/iptables_save
# you may want some rules to be put in place instead, load them here.
if [ -f /home/vagrant/iptables.downrules ]; then
iptables-restore < /home/vagrant/iptables.downrules
fi
fi
exit 0
However, I used the pre network up script (ifup-pre-local
) to load in the rules prior to getting network access for safety :
#!/bin/bash
if [ ! -f /tmp/.ipset_iptables_loaded ]; then
ipset restore < /home/vagrant/ipset_save
iptables-restore < /home/vagrant/iptables_save
touch /tmp/.ipset_iptables_loaded
fi
exit 0