Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

CentOS Network Interface Post-Up Script Not Executing

I am running CentOS 7.2, and I'm struggling to get a simple script to execute on ifup of any interface.

My /sbin/ifup-local looks like this:

[root@oracle2 ~]# cat /sbin/ifup-local
#!/bin/bash
 if [[ "$1" == "eth0" ]]
   then
     exec /vpnup
 fi
[root@oracle2 ~]#

The referenced script /vpnup looks like this:

[root@oracle2 ~]# cat /vpnup
#!/bin/bash
#
# CompanyX Production L2TP VPN - UP
#
#
echo -e "\n"
echo -e "PLEASE WAIT\n"
echo -e "Dialling Production L2TP VPN... \n"
echo -e ".........................................\n"
ipsec auto --up L2TP-PSK && echo "c qvprodvpn" > /var/run/xl2tpd/l2tp-control
echo -e ".........................................\n"
echo "Connected..."
echo "Adding local static route to manage VPN bound traffic..."
sleep 6s
ip route add 10.10.24.0/24 via 10.10.24.51
echo "Route added..."
echo -e "...\n"
[root@oracle2 ~]#

Fairly simple, the script works fine when called at command line. It just dials into a L2TP VPN that I've setup, to get this box access to the production LAN of another segment of their network.

However, if I execute "service network restart" or indeed "systemctl restart network.service", the VPN interface does not come up, nor does the ip route get added. If I manually execute ifdown eth0, and then ifup eth0, it also does not run the script as intended.

If I execute "/sbin/ifup-local eth0" the script runs as expected, so I know my script is fine, and I know my ifup-local is fine.

Am I missing something obvious? I've never worked with pre/post up scripts before, but I always figured they were pretty simple... Was I wrong?

like image 828
Dave Byrne Avatar asked Mar 12 '23 00:03

Dave Byrne


1 Answers

Ensure your ifcfg-eth0 script includes

NM_CONTROLLED=no

Otherwise, calling systemctl restart network or ifup eth0 will not execute ifup-pre-local, ifup-eth, ifup-post, ifup-local, etc. for eth0. They will still be called for lo, though.

like image 168
mysteryegg Avatar answered Mar 25 '23 01:03

mysteryegg