[SOLVED] Run Script after upcomming ppp interface

Issues related to configuring your network
Post Reply
fredo788
Posts: 3
Joined: 2015/03/19 14:41:04

[SOLVED] Run Script after upcomming ppp interface

Post by fredo788 » 2015/03/20 07:34:46

Good morning,

Iam new in thes Forum, because its my first time CentOS. :-)

My problem is, when a l2tp connections getting up as pppX interface the server has to run a Script.

I testing the follow things.

at the end of: /etc/sysconfig/network-scripts/ifup-post:
if [ -x /sbin/ifup-script ]; then
echo ${REALDEVICE} ${IPADDR} > /tmp/ifup.log
/sbin/ifup-script ${REALDEVICE} ${IPADDR}
fi

at the end of: /etc/sysconfig/network-scripts/ifup-ppp:
if [ -x /sbin/ifup-script ]; then
echo ${REALDEVICE} ${IPADDR} > /tmp/ifup.log
/sbin/ifup-script ${REALDEVICE} ${IPADDR}
fi


/sbin/ifup-script:
#!/usr/bin/perl
$device = $ARGV[0] or die;
$remip = $ARGV[1] or die;
$device =~ /^ppp(\d+)$/ or die;
($network,$ip) = $remip =~ /^192\.168\.(\d+)\.(\d+)$/ or die;
$ip = $ip - 1;
$network = "192.168.$network.$ip/26";
system( "/sbin/route add -net $network dev $device" );


My problem ist, wenn a pppX "interface" comes up, I found nothing in the logs.
When I reboot the whole system, I only found the information about eth1 and the correct IP-Address of eth1.
But noting about eth0 and the pppX connections.

So I think the script doenst run. Because why, were I have to put in the Lines, to start the script correct?

Thanks für your Support.


Best reguards.

drk
Posts: 405
Joined: 2014/01/30 20:38:28

Re: Run Script after upcomming ppp interface

Post by drk » 2015/03/20 17:12:07

It's been a while since I've done ppp but I don't think you want to touch any of the system scripts but, rather, you can add "ip-up.local" and "ip-down.local" scripts in /etc/ppp to do all your extra processing in them.

fredo788
Posts: 3
Joined: 2015/03/19 14:41:04

Re: Run Script after upcomming ppp interface

Post by fredo788 » 2015/03/23 08:26:29

Thank you for your answer.

I test it and now the pppX interface is in the log. But the IP-Address not.
What ist the variable for the IP-Address ${IPADDR} doesnt work in the if-up or if-up.local script.

drk
Posts: 405
Joined: 2014/01/30 20:38:28

Re: Run Script after upcomming ppp interface

Post by drk » 2015/03/23 16:59:19

fredo788 wrote:Thank you for your answer.

I test it and now the pppX interface is in the log. But the IP-Address not.
What ist the variable for the IP-Address ${IPADDR} doesnt work in the if-up or if-up.local script.
The man page for pppd has that information. Check out the environment variables that are set but there is also this section that shows the arguments given to ip-up/down:
/etc/ppp/ip-up
A program or script which is executed when the link is available
for sending and receiving IP packets (that is, IPCP has come
up). It is executed with the parameters

interface-name tty-device speed local-IP-address
remote-IP-address ipparam

fredo788
Posts: 3
Joined: 2015/03/19 14:41:04

Re: [SOLVED] Run Script after upcomming ppp interface

Post by fredo788 » 2015/03/24 07:21:29

Problem Solved.
look at the working Scripts:

/etc/ppp/ip-up.local:
#!/bin/bash

PATH=/sbin:/usr/sbin:/bin:/usr/bin
export PATH

LOGDEVICE=$6
REALDEVICE=$1
IPADDR=$5

if [ -x /sbin/ifup-my_script ]; then
/sbin/ifup-my_script ${REALDEVICE} ${IPADDR}
fi

exit 0


/sbin/ifup-my_script:
#!/usr/bin/perl
$device = $ARGV[0] or die;
$remip = $ARGV[1] or die;
$device =~ /^ppp(\d+)$/ or die;
($network,$ip) = $remip =~ /^192\.168\.(\d+)\.(\d+)$/ or die;
$ip = $ip - 1;
$network = "192.168.$network.$ip/26";
system( "/sbin/route add -net $network dev $device" );



Thanks for your Support! :-)

Post Reply