Adding and deleting static routes is a task I routinely perform in my job, to assist in reconnecting remote users to our network when a remote switch goes down. In the large network that my AIX boxes are attached to, it’s not unusual for a remote switch to go down at a distant office. To reconnect the users to the network, I set up alternative routing, which enables them to reconnect via another route. After the downed switch has been fixed, I need to remove the temporary route I put in.
Here's the thing about AIX static routes. You can add or remove routes by using the route command, but doing so doesn't update the AIX Object Data Manager (ODM); it only adds or removes the ODM from the kernel that's running. Thus, adding or removing routes via the route command should only be considered as a temporary measure. When you remove a route using the route command (run the command netstat -r to verify that it's been removed), the next time the box is rebooted, the route will return.
So how can you permanently remove a route? You can do so either by using the chdev command or via the System Management Interface Tool (SMIT) remove route command. My personal preference is to use the chdev command (first running the lsattr command to verify that the ODM knows about the route in question). Of course, you can use SMIT to add routes as well; doing so updates the ODM. Just try to avoid using the route commands on the command line. Remember these two rules for routes:
- The route command removes the route temporarily.
- The chdev command removes the route permanently.
Follow along with me as I show you an example of adding a route, which we’ll then remove permanently using chdev.
Adding a Route
If you get a request from the network team to add or remove a route, they’ll no doubt use the shorthand network mask notation. Here are a couple of common netmasks in shorthand:
255.255.255.0 = /24
Indeed, you might get a request to add a route using a shorthand notation like the following:
The shorthand translates to this:
Destination address is 172.25.70
Gateway is : 172.25.6.1
Network Mask: 255.255.255.0
Interface to use: en0 (assume the default interface)
You can add the route in SMIT simply by entering the previous information in the required fields. The route is then created. After you’ve finished adding the route, run the netstat -r command. Look at the Use column (the column before the interface -- en0) to confirm that the route is actually present and that packets are going through that route:
172.25.70/24 172.25.6.1 UG 8 206 en0 - -
Wait a few seconds, then re-run the command. You'll see that the packet total has grown:
172.25.70/24 172.25.6.1 UG 8 390 en0 - -
Removing the Route—Permanently!
Now suppose we have to remove that route. As noted earlier, running the route command won’t remove the route permanently. For example, you could run the following route command to temporarily remove the route:
But after a reboot, the route will come back to haunt you.
Of course, you could use SMIT to remove the route, by using the same values that you used to add the route. However, I recommend using chdev from the command line, because this will definitely remove the route from the ODM and will also enable you to review other routes the ODM knows about.
Before using chdev to remove the route, first run the lsattr command to review the route in question. Here's an example:
route net,-hopcount,0,-netmask,255.255.255.0,,,,,172.25.70.0,172.25.6.1 Route True
Once you've identified and reviewed the route, copy the following section from the previous output:
Now run the chdev command, adding the interface the route is to be removed from, using the following format:
Here's what the actual command looks like, with the copied and pasted section of the lsattr output:
It doesn’t get much easier than that! The route has now been removed and won't return after a reboot. To confirm that the route has been removed, run the netstat command again—or even better, the lsattr command, as I just demonstrated.
Using chdev Avoids Confusion
Some system admins I've spoken with about route deletion described issues they had when they removed a route via SMIT. They got this dreaded error message:
0514-009 Cannot delete an object from the device
These admins didn’t want to use the chdev command to remove a route and instead used the route delete command, which removed the route temporarily until the system was rebooted. To circumvent the problem of the deleted route returning upon reboot, the admins put a route delete command in a /etc/rc.local or /etc/rc.net file (these files are executed when the system comes back up after a reboot or a shutdown). Thus, by using this approach, the admins removed the route again because it came back. I don't consider this a good practice, though, because it provides a quick fix rather than a permanent solution.
One final note: If you use the route command to delete a route, but then you try running chdev to get rid of the route permanently, the chdev command will fail because the route delete command already removed the route from the routing table. In this case, to remove the route permanently, you must first reboot the box. Once the system is rebooted, you'll be able to see that the route exists, and you can then use chdev to remove it.
If you follow my advice and always remember that chdev removes a route permanently, you'll be prepared to use the appropriate route-removal solution your situation requires.