Created on 12-06-2023 09:47 PM Edited on 10-22-2024 10:45 PM By Anthony_E
This article describes how to use the TCL script in FortiManager to create static routes on FortiGates by fetching gateway IP from an existing route.
FortiManager.
config system admin setting
(setting) set show_tcl_script enable
(setting) end
Check it under Device manager -> Scripts, select Create new and TCL Script option is now available.
#!
proc do_cmd {cmd} {
puts [exec "$cmd\n" "# " 15]
}
do_cmd "config router static"
#
# Selecting the existing route to fetch the gateway IP from
#
do_cmd "edit 4"
set query [exec "show\n" "# "]
#puts $query
set output [split $query \n]
#
# Find IP address and splitting the octets
# Below regex will first look for 'gateway' and then the IP address.
#
regexp {gateway[ ]([0-9]+)\.([0-9]+)\.([0-9]+)\.([0-9]+)} $output match first second third fourth
do_cmd "end"
#
# creating a static routes
#
do_cmd "config router static"
#
do_cmd "edit 0"
do_cmd "set dst 10.0.0.0 255.0.0.0"
do_cmd "set gateway $first.$second.$third.$fourth"
do_cmd "set device port1"
do_cmd "set comment Route_to_Internet"
do_cmd "next"
#
# configure second additional static route
#
do_cmd "edit 0"
do_cmd "set dst 92.168.1.0 255.255.255.0"
do_cmd "set gateway $first.$second.$third.$fourth"
do_cmd "set device port1"
do_cmd "set comment Route_to_Internet"
do_cmd "end"
Select the FortiGate and select the right arrow:
Select Run Now:
Select OK:
The script will start running:
Script ran successfully:
Related documents:
Technical Tip: How to troubleshoot TCL Scripts failed in FortiManager
The Fortinet Security Fabric brings together the concepts of convergence and consolidation to provide comprehensive cybersecurity protection for all users, devices, and applications and across all network edges.
Copyright 2024 Fortinet, Inc. All Rights Reserved.