Linux routing help needed

Still so confusing.. Everything that seems to work perfectly on my end seems to fail in fun and interesting ways on yours.

Here's a script you can run from the command line. It should still log to iplocal, routes, routes1 and routes2, but if there are any syntax or awk errors they should show up on the command line. It assumes your routefile.txt is in /tmp/

It will also fail to create the routes, as the IPREMOTE address is bogus. But it should give us an idea of what's happening

execute by running from the command line (and assuming script is called localroute):
sh localroute

Code:
#!/bin/sh
IPLOCAL=196.1.1.1
IPREMOTE=1.1.1.1
case $IPLOCAL in
196.*)
        echo local: $IPLOCAL >/tmp/iplocal.txt;
        echo remote: $IPREMOTE >>/tmp/iplocal.txt;
        rm /tmp/routes.log
#       route add route-server.is.co.za gw $IPREMOTE;
#       echo -e "terminal length 0\nshow ip bgp\nexit" | nc route-server.is.co.za 23 | grep ^* | awk '{print $2}' > /tmp/routefile.txt;
        for i in `cat /tmp/routefile.txt | dos2unix`; do
                if [[ $i =~ "/32" ]]; then echo 1: $i - route add -host $i gw $IPREMOTE >> /tmp/routes.log; route add -host $i gw $IPREMOTE >> /tmp/routes.log 2>&1;
                        else if [[ $i =~ "/" ]]; then echo 2: $i - route add -net $i gw $IPREMOTE >> /tmp/routes.log; route add -net $i gw $IPREMOTE >> /tmp/routes.log 2>&1;
                                else echo 3: $i - route add -net `echo -n $i | awk '{FS="." ; if ($1 >= 1 && $1 <= 126) {printf $0"/8"}else if ($1 >= 128 && $1 <= 191){printf $0"/16"}else if ($1 >= 192 && $1 <= 223){printf $0"/24"} }'` gw $IPREMOTE >> /tmp/routes.log; route add -net `echo -n $i | awk '{FS="." ; if ($1 >= 1 && $1 <= 126) {printf $0"/8"}else if ($1 >= 128 && $1 <= 191){printf $0"/16"}else if ($1 >= 192 && $1 <= 223){printf $0"/24"} }'` gw $IPREMOTE >> /tmp/routes.log 2>&1;
                        fi;
                fi;
        done;
;;
41.*)
        echo $PPP_LOCAL >/etc/ppp/ipint.txt
;;
165.*)
        echo $PPP_LOCAL >/etc/ppp/ipint.txt
;;
esac
 
Last edited:
copied it exactly as above, ran the script and heres the output.
The screen fills up with hundreds of lines of this:
localroute: 27: [[: not found

the routes.log and routes1.log files were created and routes2.log has this:

Code:
no / routes go here
route add -net 10.0.0.0/8 gw 1.1.1.1
SIOCADDRT: Operation not permitted
route add -net gw 1.1.1.1
gw: Unknown host

and hundreds of lines of this:
Code:
route add -net gw 1.1.1.1
gw: Unknown host

and after that another hundred lines of this:

Code:
route add -net 129.227.206.0/24/16 gw 1.1.1.1
Usage: inet_route [-vF] del {-host|-net} Target[/prefix] [gw Gw] [metric M] [[dev] If]
       inet_route [-vF] add {-host|-net} Target[/prefix] [gw Gw] [metric M]
                              [netmask N] [mss Mss] [window W] [irtt I]
                              [mod] [dyn] [reinstate] [[dev] If]
       inet_route [-vF] add {-host|-net} Target[/prefix] [metric M] reject
       inet_route [-FC] flush      NOT supported

and in between the code above it has this:

Code:
route add -net 160.118.0.0/16 gw 1.1.1.1
SIOCADDRT: Operation not permitted
 
Last edited:
Give me these:

Code:
hq hjb # [b]route --version[/b]
net-tools 1.60
route 1.98 (2001-04-15)
+NEW_ADDRT +RTF_IRTT +RTF_REJECT +I18N
AF: (inet) +UNIX +INET +INET6 +IPX +AX25 +NETROM +X25 +ATALK +ECONET +ROSE
HW:  +ETHER +ARC +SLIP +PPP +TUNNEL +TR +AX25 +NETROM +X25 +FR +ROSE +ASH +SIT +FDDI +HIPPI +HDLC/LAPB

hq hjb # [b]awk --version[/b]
GNU Awk 3.1.5
Copyright (C) 1989, 1991-2005 Free Software Foundation.

This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.

hq hjb # [b]dos2unix --version[/b]
dos2unix 3.1 (Thu Nov 19 1998)

hq hjb # [b]grep --version[/b]
grep (GNU grep) 2.5.1

Copyright 1988, 1992-1999, 2000, 2001 Free Software Foundation, Inc.
This is free software; see the source for copying conditions. There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
 
Just the bits after the #:

route --version
awk --version
dos2unix --version
grep --version

Have you been running the script from before as root or as a regular user?

Run: sudo su
and then: sh localroute
 
my grep and route are the same as yours
awk says "not an option" or "option lacks arguments" (even tried --v, --V, -version, -V, -v. -Version, --Version)

and my dos2unix says:

Code:
tofrodos Ver 1.7.6 Converts text files between DOS and Unix formats.
Copyright (c) 1996-2005 by Christopher Heng. All rights reserved.
 
the output in the terminal is still a whole lot of:
localroutr: 25: [[: not found

This is the complete routes.log:

Code:
3: route add -net 10.0.0.0/8 gw 1.1.1.1
SIOCADDRT: File exists
3: route add -net gw 1.1.1.1
gw: Unknown host
3: route add -net gw 1.1.1.1
gw: Unknown host
3: route add -net gw 1.1.1.1
gw: Unknown host
3: route add -net gw 1.1.1.1
gw: Unknown host
3: route add -net gw 1.1.1.1
gw: Unknown host
3: route add -net gw 1.1.1.1
gw: Unknown host
3: route add -net gw 1.1.1.1
gw: Unknown host
3: route add -net gw 1.1.1.1
gw: Unknown host
3: route add -net gw 1.1.1.1
gw: Unknown host
3: route add -net gw 1.1.1.1
gw: Unknown host
3: route add -net gw 1.1.1.1
gw: Unknown host
3: route add -net gw 1.1.1.1
gw: Unknown host
3: route add -net gw 1.1.1.1
gw: Unknown host
3: route add -net gw 1.1.1.1

and iplocal:
Code:
local: 196.1.1.1
remote: 1.1.1.1
 
I've made another change. Sorry, I know you must be getting fed up, lol

I don't suppose you could get on irc? irc.shadowfire.org, #myadsl.co.za
 
same message in terminal

and this in routes.log now:

Code:
3: 32.238.152.0/24 - route add -net gw 1.1.1.1
gw: Unknown host

and then this:
Code:
3: 129.227.206.0/24 - route add -net 129.227.206.0/24/16 gw 1.1.1.1
Usage: inet_route [-vF] del {-host|-net} Target[/prefix] [gw Gw] [metric M] [[dev] If]
       inet_route [-vF] add {-host|-net} Target[/prefix] [gw Gw] [metric M]
                              [netmask N] [mss Mss] [window W] [irtt I]
                              [mod] [dyn] [reinstate] [[dev] If]
       inet_route [-vF] add {-host|-net} Target[/prefix] [metric M] reject
       inet_route [-FC] flush      NOT supported
 
hmmm. That returned true

Then i tried this:
Code:
if [[ "126.321.235.341/32" =~ "/" ]] ; then echo true ; else echo false ; fi

Also returned true
 
even better:

for i in `cat /tmp/routefile.txt | dos2unix` ; do if [[ $i =~ "/32" ]] ; then echo true ; else echo false ; fi ; done

should give you mostly false with a couple of true
 
ok, will try that now, but i added this:

if [[ "192.124.234.221/32" =~ "/32"]] ; then echo true >> /etc/ppp/routes.log; else echo false >> /etc/ppp/routes.log; fi;

in the original ip-up script and the routes.log came up with a whole lot of false!
 
Top
Sign up to the MyBroadband newsletter
X