This article provides instructions on how to configure IPv4 static routes on the switch through the Command Line Interface (CLI).
Static routing refers to the configuration of the path selection of routers. This type of mechanism takes place in the absence of communication between routers regarding the current topology of the network and thus, manually configuring routes to the routes table on the switch is recommended. Static routes help reduce the overhead on the switch CPU. This feature also allows you to deny access to certain networks.
When routing traffic, the next hop is decided on according to the longest prefix match (LPM) algorithm. A destination IPv4 address may match multiple routes in the IPv4 Static Route Table. The device uses the matched route with the highest subnet mask, that is, the longest prefix match. If more than one default gateway is defined with the same metric value, the lowest IPv4 address from among all the configured default gateways is used.
Note: For instructions on how to configure IPv4 static routes settings on the switch through the web-based utility, click here.
You cannot configure a static route through a directly‑connected IP subnet where the device gets its IP address from a DHCP server. To configure a static IPv4 interface on the switch, click here for instructions.
Step 1. Log in to the switch console. The default username and password is cisco/cisco. If you have configured a new username or password, enter the credentials instead.
To learn how to access an SMB switch CLI through SSH or Telnet, click here.
Note: The commands may vary depending on the exact model of your switch.
Step 2. To display the current routes on the switch, enter the following:
CBS350#show ip routeNote: In this example, a directly connected route to 192.168.100.0 network is displayed.
Step 3. From the Privileged EXEC mode of the switch, enter the Global Configuration mode by entering the following:
CBS350#configureStep 4. In the Global Configuration mode, enter the ip route command to establish static routes:
CBS350#ip route [prefix[mask | prefix-length][ip-address][metric value]]The options are:
Note: In this example, a static route to 192.168.1.0 network is established through 192.168.100.0. The defined administrative distance is 2. The route goes to a router with IP address 192.168.100.1.
Step 5. (Optional) To remove all static routes to the given subnet, enter the following:
CBS350#no ip route [prefix[mask | prefix-length]Step 6. (Optional) To remove only one static route to the given subnet via the given next hop, enter the following:
CBS350#no ip route {prefix[mask | prefix-length][ip-address]}Step 7. Enter the exit command to go back to the Privileged EXEC mode:
CBS350#exitStep 8. (Optional) To display the configured route, enter the following:
CBS350#show ip routeStep 9. (Optional) In the Privileged EXEC mode of the switch, save the configured settings to the startup configuration file, by entering the following:
CBS350#copy running-config startup-configStep 10. (Optional) Press Y for Yes or N for No on your keyboard once the Overwrite file [startup-config]… prompt appears.
You have now configured IPv4 static routes on your switch through the CLI.