Submit Hint Search The Forums LinksStatsPollsHeadlinesRSS
14,000 hints and counting!


Click here to return to the 'A script to provide VPN split routing via PPPTP' hint
The following comments are owned by whoever posted them. This site is not responsible for what they say.
A script to provide VPN split routing via PPPTP
Authored by: dani++ on Aug 21, '03 12:26:18PM
'silas' perl script does not work for me... but I have improved the original scrip to work even more automagically (does still need to be called after the VPN connection is started, automatically or manually).

Must be run as root, of course.

#!/bin/bash
################################################################################
# FIX VPN ROUTING . SH
# Author: Daniel Giribet
# Improvement over shell script published by 'Anonymous' on macosxhints.com
# 'silas' perl script did not work for me, so I use this one.
# Though the scipt is trivial, use at your own risk.

PPP_LOG=/tmp/ppp.log

default_=$(/usr/sbin/netstat -nr | grep ' UHLW ' | awk '{print $1}')
remote_vpn_str=$(/usr/bin/tail -5 $PPP_LOG|/usr/bin/grep 'remote IP address')
n=$(echo $remote_vpn_str |/usr/bin/wc -w|/usr/bin/tr -d '\n' |/usr/bin/tr -d ' ')
remote_vpn=$(echo $remote_vpn_str | awk '{print $'$n'}')
mask=$(echo $remote_vpn|/usr/bin/sed -e 's/\./ /g'|awk '{print $1"."$2".0.0"}')

/usr/bin/logger 'fix_vpn_routing.sh: modifying routes...'

/sbin/route delete default $remote_vpn
/sbin/route add default $default_
/sbin/route add $mask $remote_vpn

/usr/bin/logger "fix_vpn_routing.sh: default: $default_ mask: $mask"



[ Reply to This | # ]

A script to provide VPN split routing via PPPTP
Authored by: carbon14 on Dec 08, '03 02:52:18AM

This script worked for me, but I had to change a few things to make it work. Here is the new script:

#!/bin/bash
################################################################################
# FIX VPN ROUTING . SH
# Author: Daniel Giribet
# Improvement over shell script published by 'Anonymous' on macosxhints.com
# 'silas' perl script did not work for me, so I use this one.
# Though the scipt is trivial, use at your own risk.
#
# 12/7/03 - modified by carbon14
# fixed mask to be derived from local ip
# fixed mask sed script. You can alter the mask size by changing "$3" to 0

PPP_LOG=/tmp/ppp.log

default_=$(/usr/sbin/netstat -nr | grep ' UHLW ' | awk '{print $1}')
remote_vpn_str=$(/usr/bin/tail -5 $PPP_LOG|/usr/bin/grep 'remote IP address')
local_vpn_str=$(/usr/bin/tail -5 $PPP_LOG|/usr/bin/grep 'local IP address')
n=$(echo $remote_vpn_str |/usr/bin/wc -w|/usr/bin/tr -d 'n' |/usr/bin/tr -d ' ')
remote_vpn=$(echo $remote_vpn_str | awk '{print $'$n'}')
local_vpn=$(echo $local_vpn_str | awk '{print $'$n'}')
mask=$(echo $local_vpn|/usr/bin/sed -e 's/\./ /g' | awk '{print $1"."$2"."$3".0"}')

/usr/bin/logger 'fix_vpn_routing.sh: modifying routes...'

/sbin/route delete default $remote_vpn
/sbin/route add default $default_
/sbin/route add $mask $remote_vpn

/usr/bin/logger "fix_vpn_routing.sh: default: $default_ mask: $mask"


There was a problem with the sed script not having the proper escape for "."

You can also modify the size of the mask by removing the "$3" and setting it to 0

-Carbon14



[ Reply to This | # ]
A script to provide VPN split routing via PPPTP
Authored by: aleck on Dec 16, '03 11:30:21AM

I'm new to Unix stuff, so I'm having trouble how to start this after I connect to VPN.

I've set chmod 777 for this file, and tried to add it as the last line in the set-homepage file, as discussed for the perl script, but no luck.

What is the command line for starting this file? Simply typing the file name has no effect.



[ Reply to This | # ]