VMware Communities
paulehoffman
Contributor
Contributor
Jump to solution

Changing the network interface from the CLI on Workstation/Linux 6.5?

Greetings. vmrun seems to be able to do a zillion things on a virtual machine, but one of them isn't to change the network interface settings. Am I missing something? Is there a different CLI that lets me do this?

0 Kudos
1 Solution

Accepted Solutions
DaveP
Commander
Commander
Jump to solution

vmrun readVariable and writeVariable can be used to modify VMX parameters. Use the runtimeConfig parameter and then name value pair. Not persisted in VMX file, but will override the values stored there. Not at a Linux machine and not able to test but should work if the value is stored in VMX.

View solution in original post

0 Kudos
11 Replies
kingneutron
Expert
Expert
Jump to solution

--What exactly are you trying to accomplish, and why... If you need to change the interface from Bridged to NAT or something programmatically, there may be a way to do it in the VIX API but I'm not 100% on that.

--If you're using a Linux host, you could use SED on the VMX file...

./. If you have appreciated my response, please remember to apply Helpful/Correct points. TIA

./. If you have appreciated my response, please remember to apply Helpful/Correct points. TIA
0 Kudos
lamw
Community Manager
Community Manager
Jump to solution

You can use VMware VIX's vmrun binary to make guestOS modifications as you would if you were logged into the guest (supports Workstation/Server and ESX/ESXi).

Check out: http://professionalvmware.com/2008/12/18/vixated-with-vmwares-vix/ for an example of modifying the route table on either Linux/Windows

Here are some more VIX examples: http://engineering.ucsb.edu/~duonglt/vmware/#vmware_vix

=========================================================================

William Lam

VMware vExpert 2009

VMware ESX/ESXi scripts and resources at:

0 Kudos
paulehoffman
Contributor
Contributor
Jump to solution

--What exactly are you trying to accomplish, and why...

I have a virtual machine with one network interface. I want to change it from (for example) /dev/vmnet0 to /dev/vmnet4 and then back again at a later time.

>If you need to change the interface from Bridged to NAT or something programmatically, there may be a way to do it in the VIX API but I'm not 100% on that.

I thought the VIX API is for manipulating the client operating system, not the VMware settings for the virtual machine, but (like you) I'm not 100% on that. Thus my question.

--If you're using a Linux host, you could use SED on the VMX file...

While it is running? I would be surprised if that is safe. Changing the setting in VM->Settings is safe, but I haven't seen anything that says that editing the .vmx file is.

0 Kudos
paulehoffman
Contributor
Contributor
Jump to solution

You can use VMware VIX's vmrun binary to make guestOS modifications as you would if you were logged into the guest (supports Workstation/Server and ESX/ESXi).

Yes, but I'm not trying to make guestOS modifications; I'm trying to change the settings for the guestOS, namely which network device it is attached to.

0 Kudos
kingneutron
Expert
Expert
Jump to solution

[[ I have a virtual machine

with one network interface. I want to change it from (for example)

/dev/vmnet0 to /dev/vmnet4 and then back again at a later time.

]]

--What I would recommend is adding a 2nd vNIC card to the VM, and point it to vmnet4. Then you can enable/disable the interface from within the VM at will, using normal commands.

--You are correct also, the .vmx file should not be edited while the VM is running; however you can do it while it is powered off (or in some cases, suspended - you just have to close the VM's Tab in the GUI -- and be Really Careful.)

./. If you have appreciated my response, please remember to apply Helpful/Correct points. TIA

./. If you have appreciated my response, please remember to apply Helpful/Correct points. TIA
0 Kudos
paulehoffman
Contributor
Contributor
Jump to solution

--What I would recommend is adding a 2nd vNIC card to the VM, and point it to vmnet4. Then you can enable/disable the interface from within the VM at will, using normal commands.

You are not understanding my problem. I want to do this from the host, not from the VM. I am aware of the possibilities (and the great difficulties) of doing this with different clients.

--You are correct also, the .vmx file should not be edited while the VM is running; however you can do it while it is powered off (or in some cases, suspended - you just have to close the VM's Tab in the GUI -- and be Really Careful.)

Again, that's not my scenario. I want to do, from the command line, the same thing I could do by giving the VM -> Settings command.

I'll take the lack of positive response as a "no, you can't do it" and will send in a suggestion.

0 Kudos
jokke
Expert
Expert
Jump to solution

I am not familiar with workstation on linux host, but on windows you can manipulate the network settings from cli with vnetlib.

If that tool is included on linux installs, it may do what you seek..

Joakim

0 Kudos
paulehoffman
Contributor
Contributor
Jump to solution

I am not familiar with workstation on linux host, but on windows you can manipulate the network settings from cli with vnetlib.

If that tool is included on linux installs, it may do what you seek..

It is not, and this is indeed frustrating. Can someone from VMware respond here? Am I just missing some CLI tool that is available on Windows?

0 Kudos
DaveP
Commander
Commander
Jump to solution

vmrun readVariable and writeVariable can be used to modify VMX parameters. Use the runtimeConfig parameter and then name value pair. Not persisted in VMX file, but will override the values stored there. Not at a Linux machine and not able to test but should work if the value is stored in VMX.

0 Kudos
paulehoffman
Contributor
Contributor
Jump to solution

vmrun readVariable and writeVariable can be used to modify VMX parameters. Use the runtimeConfig parameter and then name value pair. Not persisted in VMX file, but will override the values stored there. Not at a Linux machine and not able to test but should work if the value is stored in VMX.

Thank you, that is it. I missed it because readVariable and writeVariable are listed in the vmrun docs as "Guest Operating System Commands", whereas they should also be listed in Maintenance Commands (because they can get variables from either the guest OS or the settings table).

And, to complete the loop, the variable that I needed is ethernet0.vnet. Thus:

# vmrun readVariable <pathtovmx> runtimeConfig ethernet0.vnet
/dev/vmnet0
# vmrun writeVariable <pathtovmx> runtimeConfig ethernet0.vnet /dev/vmnet1

0 Kudos
DaveP
Commander
Commander
Jump to solution

Glad you got it working. I think they need their own section in the documentation as the commands affect both host VMX parameters and guest variables. You could post a documentation change request in the relevant forum.

0 Kudos