Security
Security

How-To: Add a large list of IP addresses to a prefix-list using CLI

by Juniper Employee on ‎06-10-2016 08:58 AM - edited on ‎09-22-2017 03:49 PM by Administrator Administrator (7,544 Views)

Overview

There are times when you need to add a large list of IP addresses to a prefix-list. You can use the CLI to add these IP addresses.

Solution

Use the load merge CLI command to load the edited prefix list to the Junos OS device. You should first edit the prefix list with a script or editor to append ';' to the end of each IP address. 

Example

Use sed on a Linux platform to append ';' to the end of each IP address in the prefix.txt file.

> sed -e 's/$/;/' prefix.txt

On the Junos OS device, use the edit policy prefix-list <name> command and then load merge relative terminal command to add the list of IP addresses.

 

[edit policy-options prefix-list TEST]
root@PE2# load merge relative terminal
[Type ^D at a new line to end input]
10.38.108.24;
10.54.42.82;
10.61.171.253;
10.62.98.162;
10.128.34.171;
10.139.161.113;
10.141.27.91;
10.141.31.16;
10.141.31.19;
load complete

[edit policy-options prefix-list TEST]
root@PE2# show
10.38.108.24/32;
10.54.42.82/32;
10.61.171.253/32;
10.62.98.162/32;
10.128.34.171/32;
10.139.161.113/32;
10.141.27.91/32;
10.141.31.16/32;
10.141.31.19/32;

 

Note: for large lists (over 200 IP addresses), load the IP addresses from the local  prefix2.txt file. Then use the load merge <file-path> relative command to bring those IP addresses into the prefix-list.

 

From File:

 

root@JUNOS# edit policy-options prefix-list TEST

[edit policy-options prefix-list TEST]
root@JUNOS# load merge /var/tmp/prefix2.txt relative
load complete

[edit policy-options prefix-list TEST]
root@JUNOS# show | count
Count: 346 lines  

 

'
Comments
Jun 20, 2016
Distinguished Expert

Nice work!

Jul 3, 2016
Distinguished Expert

The alternate way to load large portions of configuration from the command line is using "load set" from a file.  I generally prefer this method because I can use excel to drag copy all the common commands across the multiple rows and save as text to get the file.  This can be easier than correctly formating the hierarchy and final semi-colons.

 

  • load set (filename | terminal) <relative>—Executes configuration mode commands such as set, edit, exit, and top from a text file or from the text you type at the terminal. Press Ctrl+D to end terminal input.

http://www.juniper.net/documentation/en_US/src4.7/topics/concept/src-configuration-commands-load.htm...

 

set policy-options prefix-list TEST 10.38.108.24
Sep 6, 2016
Distinguished Expert

'sed' or other programming scripts can be used to generate set commands too:

$sed -e 's/^/set policy-options prefix-list TEST /' prefix.txt
set policy-options prefix-list TEST 10.38.108.24
set policy-options prefix-list TEST 10.54.42.82
set policy-options prefix-list TEST 10.61.171.253
set policy-options prefix-list TEST 10.62.98.162
set policy-options prefix-list TEST 10.128.34.171
set policy-options prefix-list TEST 10.139.161.113
set policy-options prefix-list TEST 10.141.27.91
set policy-options prefix-list TEST 10.141.31.16
set policy-options prefix-list TEST 10.141.31.19

 

Oct 16, 2016
Distinguished Expert

The only downside to generating full set commands is that there seems to be an inherent limitation in Junos about the amount of set data the CLI will accept at once (eg: after pasting in a couple of screens of input, the CLI will stop accepting new lines)

 

Load merge however doesn't seem to have this limitation.