Blue Boxes
Virtualization tips, news and more

VMware ESX Service Console | How to set IP address from command line

The VMware Service Console Allows you to administer yor VMware ESX Server from a command line. Sometimes is necesary to perform some changes on  the IP configuration of your systems either you must set it or a misconfiguration occurred and you need to fix it.
The best way to set or get your VMware ESX Server networking back from the command line is tu use the esxcfg-vswif command.
Let’s take a look at the options that VMware gives us when you execute the command:
[root@nsolop ~]# esxcfg-vswif
esxcfg-vswif <options> [<vswif>]
-a|—add                                      Add vswif, requires IP parameters.
                                                   Automatically enables interface.
-d|—del                                       Delete vswif.
-l|—list                                        List configured vswifs.
-e|—enable                                 Enable this vswif interface.
-s|—disable                                 Disable this vswif interface.
-p|—portgroup                            Set the portgroup name of the vswif.
-V|--dvs-name                             Set DVPort's DVSwitch name of the vswif.
                                                   Requires --dv-port-id to be specified
-P|--dv-port-id                            Set DVPort's DVPort ID of the vswif.
                                                   Requires --dvs-name to be specified
-i|--ip <IP Spec>                         Where <IP Spec> can be one of the following...
                                                   <X.X.X.X>      - to use static IPv4 address specified
                                                   DHCP           - to enable IPv4 DHCP for address.
                                                   <X:X:X::/X>    - to use static IPv6 address
                                                   DHCPV6         - to enable IPv6 DHCP for address.
                                                   AUTOCONF       - to enable IPv6 Router advertised address.
-U|--unset-ip <IP Spec>              Where <IP Spec> can be one of the following...
                                                   V4             - to unset IPv4 address.
                                                   <X:X:X::/X>    - to remove the specified IPv6 address
                                                   DHCPV6         - to disable IPv6 DHCP address.
                                                   AUTOCONF       - to disable IPv6 Router advertised flag.
-n|--netmask <X.X.X.X>              The IP netmask for this vswif.
-b|--broadcast <X.X.X.X>            The IP broadcast address for this vswif
                                                   (not required if netmask and ip are set).
-c|—check                                   Check to see if a virtual NIC exists.
                                                    Program outputs a 1 if the given vswif
                                                    exists and is enabled, 0 otherwise.
-D|--disable-all                             Disable all vswif interfaces.
                                                    (WARNING: This may result in a loss of network
                                                    connectivity to the Service Console).
-E|--enable-all                              Enable all vswif interfaces and bring them up.
-6|--enable-ipv6 <true|false>       Enable or disable IPv6 for next boot.
-r|—restore                                   Restore all vswifs from the configuration. 
                                                     file (FOR INTERNAL USE ONLY).
-h|—help                                       Show this message.
!!!WARNING!!!
Loss of network connectivity may result if invalid parameters are passed to
Add, Delete, Portgroup or IP operations.
Based on the options provided by the command if whe need to set the IP Address and subnet mask of our VMware ESX Server to 172.29.21.30/24 the command should be:
root]# esxcfg-vswif -i 172.29.21.30 -n 255.255.255.0 vswif0
 
Where vswif0 is the name of our service console.
Now that we have changed the ip address of our server we also need to change it on our /etc/hosts file in order to maintain consistency. Choose your favorite text editor (I always use vi) and edit the file in order to reflect the modifications.
After the modification of the /etc/hosts file we need to change the parameters of the /etc/sysconfig/network in order to define the new default gateway in case needed.