ESXi Add Static Route using esxcli


I was doing some workaround with ESXi networks and I had to add static route to my ESXi hosts. And now if I want to Add static Route to ESXi I can browse my own blog instead of searching on the internet.

This is done on VMware 6.5, but it should work on 6.7 also.


ESXi Add Static Route

The command to add static route to your ESXi host is like this:

esxcli network ip route ipv4/ipv6 add -n IPv4_network/mask -g IPv4_gateway_ip
 Usage: esxcli network ip route ipv4 add [cmd options]
 Description:
   add                   Add IPv4 route to the VMkernel.
 Cmd options:
   -g|--gateway=    The Ipv4 address of the gateway through which a route to be added. (required)
   -N|--netstack=   The network stack instance; if unspecified, use the default netstack instance
   -n|--network=    The Ipv4 address and prefix length of the network to add the route to. Specify 'default' to indicate the default network. (required)

Example adding network 10.90.20.0/23 with gateway 10.92.20.5

esxcli network ip route ipv4 add -n 10.90.20.0/23 -g 10.92.20.5

ESXi List Routes

The command to list ESXi host routes is like this:

esxcli network ip route ipv4 list

You should get output similar to this:

[root@esx05:~] esxcli network ip route ipv4 list
 Network        Netmask          Gateway        Interface  Source
 -------------  ---------------  -------------  ---------  ------
 default        0.0.0.0          xxx.xxx.xxx.1  vmk0       DHCP
 10.90.20.0     255.255.254.0    10.92.20.5     vmk1       MANUAL
 10.92.20.0     255.255.254.0    0.0.0.0        vmk1       MANUAL
 xxx.xxx.xxx.0  255.255.255.192  0.0.0.0        vmk0       MANUAL
 [root@esx05:~]

ESXi Remove Static Route

The command to remove static route to your ESXi host is like this:

esxcli network ip route ipv4 remove -n IPv4_network/mask -g IPv4_gateway_ip
Usage: esxcli network ip route ipv4 remove [cmd options]
 Description:
   remove                Remove IPv4 route
 Cmd options:
   -g|--gateway=    The Ipv4 address of the gateway through which a route to be removed (required)
   -N|--netstack=   The network stack instance; if unspecified, use the default netstack instance
   -n|--network=    The Ipv4 address and prefix length of the network to remove the route from. Specify 'default' to indicate the default network. (required)

Example of removing previously added 10.90.20.0/23 with gateway 10.92.20.5

esxcli network ip route ipv4 remove -n 10.90.20.0/23 -g 10.92.20.5

VMware KB: https://kb.vmware.com/s/article/2001426



Subscribe
Notify of
guest
0 Comments
Inline Feedbacks
View all comments

Advertisement