add route called from script

Nathan Kinkade nkinkade at ub.edu.bz
Fri Jul 9 08:27:34 PDT 2004


On Fri, Jul 09, 2004 at 12:39:47AM +0200, Christian Hiris wrote:
> On Friday 09 July 2004 00:20, Bill Moran wrote:
> > "Per olof Ljungmark" <peo at intersonic.se> wrote:
> > > Hi all,
> > >
> > > I am experimenting with openvpn-2 and so far it looks promosing. As this
> > > version of openvpn can assign client addresses similar to dhcp, I need
> > > to find out how to assign a route from a script, like (this is the
> > > client end, running FreeBSD):
> > >
> > > [simplifed example]
> > > #!/bin/sh
> > > openvpn --daemon --config my-vpn.conf
> > > route add 192.168.0.0/16 <adress from tun{if} here>
> >
> > I'm no guru for either of these commands, but I'm guessing this is a
> > canonical job for sed and/or awk.  Something like:
> >
> > IPADDR = `ifconfig | awk '<awk magic to extract the IP>'`
> > route add 192.168.0.0/16 $IPADDR
> 
> If you know the number of the interface, ie tun0:
> 
> IPADDR=`ifconfig tun0 | awk '$1~/inet/&&$1!~/inet6/{print $2}'`
> 
> hth
> ch
> 
> >
> > I hope this is helpful, sorry I don't have a more precise answer.

One other way might be:

IPADDR=$(ifconfig tun0 | grep 'inet' | cut -d ' ' -f 2)
route add 192.168.0.0/16 ${IPADDR}

But as Christian mentioned, this assumes you know the tun interface
number.

Nathan
-- 
PGP Public Key: pgp.mit.edu:11371/pks/lookup?op=get&search=0xD8527E49
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 189 bytes
Desc: not available
Url : http://lists.freebsd.org/pipermail/freebsd-questions/attachments/20040709/c28703fd/attachment.bin


More information about the freebsd-questions mailing list