If you've spent any time configuring user authentication on... Full Story
By Manny Fernandez
November 14, 2019
Search and Add Line Script
The other day, a friend called me about a Cisco ASA configuration he migrated to Fortigate. They needed to add over 347 address objects to a group that could be used in an address group. They wanted to then use that group in a static route. The problem is that each address object needs to have the
set allow-routing enable
turned on. In order for the group to be able to turn on the feature. Obviously, every member of the group has to have the set allow-routing enable turned on in order to enable it globally on the group object.

From the GUI, the Static Route Configuration button is what adds the set allow-routing enabled to the command line.

To show you how this looks, I created a test address object in my lab. As you can see the name is InfoSecMonkey-Test & I have the Static Route Configuration selected.

Now when you create a new static route, you can:
- Select the
Named Addressbutton on the top which will allow you to search the address objects with theStatic Route Configurationselected. - The drop-down shows the
InfoSecMonkey-Testobject I created. - The destination interface; you will also need to add a gateway IP.
- Make sure it is enabled.
The Source File
Here is what the source file looks like
edit "Spoke2-LAN" set uuid 379d4b0e-ce5e-51e9-af32-5ead2c57a463 set color 6 set subnet 10.3.3.0 255.255.255.0 set color 6 next edit "Hub-LAN" set uuid 4556e6f6-ce5e-51e9-77d2-8998088099fa set color 18 set subnet 10.1.1.0 255.255.255.0 set color 6 next edit "Spoke1-LAN" set uuid d7ef66fa-ce5e-51e9-81f4-3000592203be set color 6 set subnet 10.2.2.0 255.255.255.0 set color 6 next edit "SEC-LAN-1" set uuid 2fb047fa-0042-51ea-ccf2-beae0044ff87 set color 18 set subnet 10.221.1.0 255.255.255.0 set color 6 next edit "SEC-LAN-2" set uuid 37103afa-0042-51ea-659c-2c2ceb431e0d set color 18 set subnet 10.222.1.0 255.255.255.0 set color 6 next edit "ASA-LOCAL-LAN" set uuid 8bd0e474-0153-51ea-89d6-d4877711f1bc set color 6 set subnet 2.2.2.0 255.255.255.0 set color 6 next end
As you can see, there is no set allow-routing enable on the output above.
The Script
Here is the script
#!/bin/bash
#
#
tab_spacing="\\ \\ \\ \\ \\ \\ \\ \\ "
command_to_add="set allow-routing enable"
command_to_add="${tab_spacing}${command_to_add}"
filename="$1"
#macOS sed really needs a NEWLINE character before and after the command you want to add!
sed -i '' "/^.*set subnet .* 255.255.255.0/a\\
${command_to_add}
" "$filename"
#If you want to add more commands, just copy the part and change the command.
#
#command_to_add="MY NEW COMMAND"
#command_to_add="${tab_spacing}${command_to_add}"
#sed -i '' "/^.*set subnet .* 255.255.255.0/a\\
#${command_to_add}
#" "$filename"
Here we can see the script. We are searching for the line that contains set subnet .* 255.255.255.0 and we are going to add the line set allow-routing enable. You can modify the script to look for any pattern inside the file and replace it with the command_to_add.
How To Run The Script
To run the script, I normally make the script executable by running the following command:
chmod +x script.sh
Now we will run the script against the file
./script.sh Before.txt

Call the script and tell it the name of the file you want to run the script against.
The Output
Here is the output from the command above. You can now see the set allow-routing enable
edit "Spoke2-LAN" set uuid 379d4b0e-ce5e-51e9-af32-5ead2c57a463 set color 6 set subnet 10.3.3.0 255.255.255.0 set allow-routing enable set color 6 next edit "Hub-LAN" set uuid 4556e6f6-ce5e-51e9-77d2-8998088099fa set color 18 set subnet 10.1.1.0 255.255.255.0 set allow-routing enable set color 6 next edit "Spoke1-LAN" set uuid d7ef66fa-ce5e-51e9-81f4-3000592203be set color 6 set subnet 10.2.2.0 255.255.255.0 set allow-routing enable set color 6 next edit "SEC-LAN-1" set uuid 2fb047fa-0042-51ea-ccf2-beae0044ff87 set color 18 set subnet 10.221.1.0 255.255.255.0 set allow-routing enable set color 6 next edit "SEC-LAN-2" set uuid 37103afa-0042-51ea-659c-2c2ceb431e0d set color 18 set subnet 10.222.1.0 255.255.255.0 set allow-routing enable set color 6 next edit "ASA-LOCAL-LAN" set uuid 8bd0e474-0153-51ea-89d6-d4877711f1bc set color 6 set subnet 2.2.2.0 255.255.255.0 set allow-routing enable set color 6 next end
Hope this helps
Recent posts
-
-
DNS is one of those technologies that quietly underpins... Full Story
-
BGP issues on FortiGate firewalls usually trace back to... Full Story
-
Every time your laptop talks to your router, a... Full Story
-
If you've spent any time configuring NAT on a... Full Story
-
If you have spent any time configuring firewall policies... Full Story
-
High availability on FortiGate is one of those features... Full Story
-
If you've configured SD-WAN on a FortiGate, you've almost... Full Story
-
FortiLink is the management protocol that turns a FortiSwitch... Full Story
-
FortiSwitches are pretty rock solid from Mean Time Between... Full Story
-
This is a quicky tip. Have you ever gone... Full Story
-
DNS is one of those quiet pieces of internet... Full Story
-
This article is an updated version of the previous... Full Story
-
You will add ns2 as a secondary (slave) BIND9... Full Story
-
In the process of deploying my lab, I needed... Full Story
-
RFC 8805, used to be known as Self-Correcting IP... Full Story
-
Years back, I wrote an article about certificate pinning. ... Full Story
-
FortiGates have the ability to send alerts to Microsoft... Full Story
-
In this post, I am going to walk through... Full Story
-
Troubleshooting VoIP on a FortiGate can feel like trying... Full Story
-
Prior to FortiOS 7.0, there were three commands to... Full Story
-
In this post, I am going to go over... Full Story
-
What we are going to do: We are going... Full Story
-
Choosing between FGCP (FortiGate Clustering Protocol) and FGSP (FortiGate... Full Story
-
Creating a VLAN on macOS (The "Pro" Move) A... Full Story
-
This blog post explores the logic behind how macOS... Full Story
-
Pretty Fly for a Wi-Fi Tell My Wi-Fi Love... Full Story
-
Part of my daily gig is creating BoMs (Bill-of-Materials)... Full Story
-
ICMP introduces several security risks, but careful filtering, rate... Full Story
-
The command diag debug application dhcps -1 enables full... Full Story
-
In the world of FortiOS, execute tac report is... Full Story
-
LLDP; What is it The Link Layer Discovery Protocol... Full Story
-
What it actually does When you run diagnose fdsm... Full Story
-
Monkey Bites are bite-sized, high-impact security insights designed for... Full Story
-
I have run macOS in macOS with Parallels but... Full Story
-
Don't be confused with my other FortiNAC posts where... Full Story
-
This is the third session in a multi-part article... Full Story
-
Today I was configuring key-based authentication on a FortiGate... Full Story
-
Netcat, often called the "Swiss Army knife" of networking,... Full Story
-
At its core, IEEE 802.1X is a network layer... Full Story
-
In case you did not see the previous FortiNAC... Full Story
-
This is our 5th session where we are going... Full Story
-
Now that we have Wireshark installed and somewhat configured,... Full Story
-
The Philosophy of Packet Analysis Troubleshooting isn't about looking... Full Story
-
Overview FortiOS 8.0 introduces custom tags as a first-class... Full Story
-
These are two distinct mechanisms on FortiOS, and conflating... Full Story
-
Replacement messages are the pages and text blocks that... Full Story