So, I needed to add a static route to a VMware ESXi server. Specifically, I was looking to add the static route to the ESXi host in order to mount a particular NFS datastore. I did not need to add the static route to the guest machines — either Windows or Linux — that were running on the host. Googling, I kept finding the solution to the latter scenario, which just didn’t apply to my situation.
Finally, I figured it out. This includes the step-by-step process to enter a shell console on an ESXi server (always useful) and also to add the static route.
- Login to the ESXi server:
- I happened to be using an HP blade server, so I used HP’s integrated lights-out functionality (iLO).
- Press F2 to “Customize System/View Logs”
- Enter your server credentials to login.
- Enable the shell functionality:
- Scroll down to “Troubleshooting Options”
- Select “Enable ESXi Shell”
(Note: when you enable the shell, the option toggles to “Disable ESXi Shell”. This is normal behavior.) - Press Alt-F1 to get into a shell command prompt
- View the static routes:
- You will be prompted for a user name.
- You will be prompted for a user password.
- At the # prompt, enter: esxcfg-route -l
(More Info: This will display the current static routes.)
- Add the new static route:
- At the # prompt: esxcfg-route -a IP MASK GATEWAY
(Example: esxcfg-route -a 10.10.10.0 255.255.255.0 10.10.20.1)
(More Info: to validate the settings have taken, display the routes again.) - At the # prompt, enter: exit
- At the # prompt: esxcfg-route -a IP MASK GATEWAY
- Disable the shell functionality and logout:
- Select “Disable ESXi Shell” to disable it.
(Note: when you disable the shell, the option toggles back to “Enable ESXi Shell”.) - Press ESC to exit the troubleshooting menu.
- Press ESC to logout.
- Select “Disable ESXi Shell” to disable it.
I tested mounting my datastore after defining the static route, and the datastore mounted without errors. Additionally, I rebooted the ESXi host (using the vCenter GUI) and was pleasantly surprised to find that (a) the datastore stayed mounted and (b) that logging back into the ESXi host proved the new static route was persistent.