3

We've deployed the caching server in local ISP and peered it with the ISP router via BGP protocol in order to get all advertised ip prefixes of ISP. We need to redirect all of these ip prefixes into a file and sync it to the DNS server. So, we'll add all of these prefixes into bind view directive in order to direct all requests coming from our local ISP clients towards the local caching server.

can i use the combination of bash with quagga and redirect all bgp routes into the file ? show ip bgp command displays all the advertised routes but i am unable to redirect these routes into the file. Linux route command also shows these prefixes but i need cidr notation i.e 1.2.3.4/24 but route command doesn't support it.

Please suggest me if you have better approach.

  • This question may be better suited on StackOverflow. If you can get the ouput on the comand line then a simple bash script or similar can save the output to a file (so the question of "How can I save that output to a file in bash" makes it more suited to StackOverflow. Can you provide some of the example output you want to save to file? – jwbensley Jul 4 '14 at 9:49
  • @jwbensley these will be 1800+ lines of ip prefixes like : 1.2.1.4/24 – shahzaib1 Jul 4 '14 at 21:20
2

Let's assume that you are in a bash shell on the quagga router... use the script command to capture output from quagga (or any other interactive CLI session)... a contrived example which saves the quagga bgp routes to a file named bgp_routes.txt

$ script bgp_routes.txt
Script started, file is bgp_routes.txt
$ telnet localhost 2605
... authenticate as required
Router# terminal length 0
... run show ip bgp command
Router# exit
$ exit
| improve this answer | |
  • thanks for script command, but the problem with show ip bgp is, it contains 1800+ lines and i have to keep pressing ENTER in order to record all 1800+ lines in the file bgp_routes.txt. Is there a way that i can get all routes via script command without using ENTER key all the way to the bottom? – shahzaib1 Jul 4 '14 at 19:07
  • @shahzaib1, Use terminal length 0 – Mike Pennington Jul 4 '14 at 23:06
  • that's much better, – shahzaib1 Jul 5 '14 at 9:24
0

This should do the trick for you.

vtysh -c "show ip bgp neighbors X.X.X.X routes" | sed '1,6d' | awk '{print $2}' | head -n -2 > routes.txt

This will output only the routes into the file routes.txt

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.