Link to home
Start Free TrialLog in
Avatar of richsark
richsarkFlag for United States of America

asked on

shell script broke for VMware vmnet-cfg cli

I have this shell script that used to work on older fusion 9x and 10x. Seems that on 11 and above. I not an expert yet, seems that some triggers have changed and I cant figure out which one is it and what I need to change.
I would seek help from an expert to help make this work please.

When I run it.. I get this
even as su still a no go.

==> ./vmnet-util.sh --add vmnet100 100.100.100.0 255.255.255.0
Adding VMNET Adapter vmnet


Password:
ifconfig: interface vmnet does not exist

Open in new window


I know its there cause I used it before. I think a utility has changed but dont know what I need to modify inside this shell script

#VMWARE has not provided any documentation or
# KB articles for the vmnet-cfgcli utility.   This is the utility that used
# to create the adapters.  This script will only create host-only adapters.  
# If you require something other than host-only, just edit the networking file
# manually.   
###############################################################################

#set -x # Uncomment to Debug

###############################################################################
#
# Functions
#
###############################################################################

##
function add_adapter() {
  ${asroot} "${vmapppath}"vmnet-cfgcli addadapter ${vmnet}
  ${asroot} "${vmapppath}"vmnet-cfgcli setsubnetaddr ${vmnet} ${network_subnet}
  ${asroot} "${vmapppath}"vmnet-cfgcli setsubnetmask ${vmnet} ${subnet_mask}
  ${asroot} "${vmapppath}"vmnet-cfgcli updateadapterfromconfig ${vmnet}
}
##
function remove_adapter() {
  ${asroot} "${vmapppath}"vmnet-cfgcli removeadapter ${vmnet}
  ${asroot} "${vmapppath}"vmnet-cfgcli deletevnet ${vmnet}
  ${asroot} "${vmapppath}"vmnet-cfgcli vnetcfgremove ${vmnet}
  ${asroot} "${vmapppath}"vmnet-cfgcli updateadapterfromconfig ${vmnet}
}
##
function update_adapter() {
  ${asroot} "${vmapppath}"vmnet-cfgcli setsubnetaddr ${vmnet} ${network_subnet}
  ${asroot} "${vmapppath}"vmnet-cfgcli setsubnetmask ${vmnet} ${subnet_mask}
  ${asroot} "${vmapppath}"vmnet-cfgcli updateadapterfromconfig ${vmnet}
}
##
function reload_svcs() {
  ${asroot} "${vmapppath}"vmnet-cli --configure
  ${asroot} "${vmapppath}"vmnet-cli --stop
  ${asroot} "${vmapppath}"vmnet-cli --start
}
##
function rebuild_vmnet() {
  echo Removing "${configfile}"
  ${asroot} rm "${configfile}"
  echo Dynamically Rebuilding "${configfile}"
  ${asroot} "${vmapppath}"vmnet-cli --configure
}
##
function export_config() {
  ${asroot} "${vmapppath}"vmnet-cfgcli exportconfig ${backupfile}
}
##
function import_config() {
  ${asroot} "${vmapppath}"vmnet-cfgcli importconfig ${backupfile}
}
##
function show_vmnets() {
  tput clear
  ifconfig | grep -i vmnet | cut -d ":" -f1 | xargs -n1 ifconfig
}

###############################################################################
##
## Main
##
###############################################################################

###############################################################################
# Define Variables
###############################################################################
version="1.3"
filename=`basename $0`
vmapppath='/Applications/VMware Fusion.app/Contents/Library/'
configfile='/Library/Preferences/VMware Fusion/networking'
vmnet=${2} 
network_subnet=${3}
subnet_mask=${4}
bitbucket="/dev/null"
vmware_pid="/var/run/vmnet-bridge.pid"
ROOT_UID=0 # Only users with $UID 0 have root privileges
# Set some basic colors for TXT output
fmt_red=`tput setaf 1`
fmt_bold=`tput bold`
fmt_normal=`tput sgr0`
fmt_bold_red=${fmt_bold}${red}
fmt_underline=`tput smul`

# Check if VMWARE fusing is running.  We are checking this by looking for the 
# Existence of the vmnet-bridge.pid
if [ ! -f ${vmware_pid} ];
then
  tput clear
  echo ${fmt_red}
  echo "┌──────────────────────────────────────────────────────────┐"
  echo "│    VMWARE Fusion must be running to use this script!     │"
  echo "│            Start VMWARE Fusion and rerun.                │"
  echo "└──────────────────────────────────────────────────────────┘"
  echo ${fmt_normal}
  exit 
fi

# Check if User is running as root.  If not force sudo
if [ "$UID" -ne "$ROOT_UID" ];
then
  asroot="sudo"
else
  asroot=""
fi  

case "${1}" in
--add)
    echo "Adding VMNET Adapter ${vmnet}"
    echo ""
    add_adapter > ${bitbucket}
    reload_svcs > ${bitbucket}
    ifconfig ${vmnet}
;;

--update)
    echo "Updating VMNET Adapter ${vmnet}"
    echo ""
    echo "Old Configuration"
    ifconfig ${vmnet}
    update_adapter > ${bitbucket}
    reload_svcs > ${bitbucket}
    echo ""
    echo "New Configuration"
    ifconfig ${vmnet}
;;

--remove)
    echo "Removing VMNET Adapter ${vmnet}"
    echo ""
    ifconfig ${vmnet}
    remove_adapter  > ${bitbucket}
    reload_svcs  > ${bitbucket}
;;

--reload)
    echo "Restarting VMNET Network Services"
    echo ""
    reload_svcs  > ${bitbucket}
;;

--rebuild)
    echo "Restoring VMNET Networks to Factory Default"
    echo ""
    rebuild_vmnet
    reload_svcs > ${bitbucket}
;;

--export)
    backupfile=${2}
    export_config > ${bitbucket}
;;
--import)
    backupfile=${2}
    import_config > ${bitbucket}
;;
--interfaces)
    show_vmnets
;;
*)
  tput clear
  echo ""
  echo "${fmt_bold}${fmt_red}Utility Script:${fmt_normal}${fmt_bold}${filename}${fmt_normal}" 
  echo "Allows for the quick addition, updating and removal of vmnet adapters."  
  echo "In order for new vmnet adapters to become visible within the Virtual"
  echo "Machine, restart the virtual machine so it is re-initialized.  ${fmt_bold}${fmt_underline}VMWARE"
  echo "Fusion does not need to be restarted.${fmt_normal}"
  echo ""
  echo "${fmt_bold}Version: ${fmt_red}${version}${fmt_normal}"
  echo ""
  echo "${fmt_bold}Add, Update, Remove VMNET Adapter:${fmt_normal}"
  echo "${fmt_bold}Usage:${fmt_normal} ${filename} --add vmnet20 10.10.10.0 255.255.255.0"
  echo "       ${filename} --update vmnet20 10.10.11.0 255.255.255.0"
  echo "       ${filename} --remove vmnet20"  
  echo ""
  echo "${fmt_bold}Restart Services:${fmt_normal}"
  echo "${fmt_bold}Usage:${fmt_normal} ${filename} --reload"
  echo ""
  echo "${fmt_bold}Rebuild Networking Database:${fmt_normal}"
  echo "${fmt_bold}Usage:${fmt_normal} ${filename} --rebuild"
  echo ""
  echo "${fmt_bold}Export Networking Database:${fmt_normal}"
  echo "${fmt_bold}Usage:${fmt_normal} ${filename} --export [filename]"
  echo ""
  echo "${fmt_bold}Import Saved Networking Database:${fmt_normal}"
  echo "${fmt_bold}Usage:${fmt_normal} ${filename} --import [filename]"
  echo ""
  echo "${fmt_bold}Show Fusion Interfaces:${fmt_normal}"
  echo "${fmt_bold}Usage:${fmt_normal} ${filename} --interfaces"
  exit 
esac

Open in new window

Avatar of noci
noci

can you show what interfaces do exist?  ifconfig -a
i am not sure why it would select vmnet while vmnet100 is specified.
Avatar of richsark

ASKER

Hi, Here is the ifconfig -a with VMware Fusion Professional Version 12.1.0 running

I select that name " vmnet100" as its the name I gave it when I originally ran the script



==> ifconfig -a
lo0: flags=8049<UP,LOOPBACK,RUNNING,MULTICAST> mtu 16384
    options=1203<RXCSUM,TXCSUM,TXSTATUS,SW_TIMESTAMP>
    inet 127.0.0.1 netmask 0xff000000
    inet6 ::1 prefixlen 128
    inet6 fe80::1%lo0 prefixlen 64 scopeid 0x1
    nd6 options=201<PERFORMNUD,DAD>
gif0: flags=8010<POINTOPOINT,MULTICAST> mtu 1280
stf0: flags=0<> mtu 1280
en10: flags=8863<UP,BROADCAST,SMART,RUNNING,SIMPLEX,MULTICAST> mtu 1500
    ether ac:de:48:00:11:22
    inet6 fe80::aede:48ff:fe00:1122%en10 prefixlen 64 scopeid 0x4
    nd6 options=201<PERFORMNUD,DAD>
    media: autoselect (100baseTX <full-duplex>)
    status: active
ap1: flags=8802<BROADCAST,SIMPLEX,MULTICAST> mtu 1500
    options=400<CHANNEL_IO>
    ether f2:18:98:12:de:24
    media: autoselect
    status: inactive
en0: flags=8863<UP,BROADCAST,SMART,RUNNING,SIMPLEX,MULTICAST> mtu 1500
    options=400<CHANNEL_IO>
    ether f0:18:98:12:de:24
    inet6 fe80::10bf:8943:4de2:c5dd%en0 prefixlen 64 secured scopeid 0x6
    inet 192.168.1.30 netmask 0xffffff00 broadcast 192.168.1.255
    nd6 options=201<PERFORMNUD,DAD>
    media: autoselect
    status: active
en3: flags=8963<UP,BROADCAST,SMART,RUNNING,PROMISC,SIMPLEX,MULTICAST> mtu 1500
    options=460<TSO4,TSO6,CHANNEL_IO>
    ether 82:23:af:e4:38:05
    media: autoselect <full-duplex>
    status: inactive
en4: flags=8963<UP,BROADCAST,SMART,RUNNING,PROMISC,SIMPLEX,MULTICAST> mtu 1500
    options=460<TSO4,TSO6,CHANNEL_IO>
    ether 82:23:af:e4:38:04
    media: autoselect <full-duplex>
    status: inactive
en1: flags=8963<UP,BROADCAST,SMART,RUNNING,PROMISC,SIMPLEX,MULTICAST> mtu 1500
    options=460<TSO4,TSO6,CHANNEL_IO>
    ether 82:23:af:e4:38:01
    media: autoselect <full-duplex>
    status: inactive
en2: flags=8963<UP,BROADCAST,SMART,RUNNING,PROMISC,SIMPLEX,MULTICAST> mtu 1500
    options=460<TSO4,TSO6,CHANNEL_IO>
    ether 82:23:af:e4:38:00
    media: autoselect <full-duplex>
    status: inactive
en12: flags=8863<UP,BROADCAST,SMART,RUNNING,SIMPLEX,MULTICAST> mtu 1500
    options=6467<RXCSUM,TXCSUM,VLAN_MTU,TSO4,TSO6,CHANNEL_IO,PARTIAL_CSUM,ZEROINVERT_CSUM>
    ether 00:e0:4c:68:00:20
    nd6 options=201<PERFORMNUD,DAD>
    media: autoselect (none)
    status: inactive
bridge0: flags=8863<UP,BROADCAST,SMART,RUNNING,SIMPLEX,MULTICAST> mtu 1500
    options=63<RXCSUM,TXCSUM,TSO4,TSO6>
    ether 82:23:af:e4:38:01
    Configuration:
        id 0:0:0:0:0:0 priority 0 hellotime 0 fwddelay 0
        maxage 0 holdcnt 0 proto stp maxaddr 100 timeout 1200
        root id 0:0:0:0:0:0 priority 0 ifcost 0 port 0
        ipfilter disabled flags 0x0
    member: en1 flags=3<LEARNING,DISCOVER>
            ifmaxaddr 0 port 9 priority 0 path cost 0
    member: en2 flags=3<LEARNING,DISCOVER>
            ifmaxaddr 0 port 10 priority 0 path cost 0
    member: en3 flags=3<LEARNING,DISCOVER>
            ifmaxaddr 0 port 7 priority 0 path cost 0
    member: en4 flags=3<LEARNING,DISCOVER>
            ifmaxaddr 0 port 8 priority 0 path cost 0
    nd6 options=201<PERFORMNUD,DAD>
    media: <unknown type>
    status: inactive
awdl0: flags=8943<UP,BROADCAST,RUNNING,PROMISC,SIMPLEX,MULTICAST> mtu 1500
    options=400<CHANNEL_IO>
    ether 22:bb:f1:34:5e:ea
    inet6 fe80::20bb:f1ff:fe34:5eea%awdl0 prefixlen 64 scopeid 0xd
    nd6 options=201<PERFORMNUD,DAD>
    media: autoselect
    status: active
llw0: flags=8863<UP,BROADCAST,SMART,RUNNING,SIMPLEX,MULTICAST> mtu 1500
    options=400<CHANNEL_IO>
    ether 22:bb:f1:34:5e:ea
    inet6 fe80::20bb:f1ff:fe34:5eea%llw0 prefixlen 64 scopeid 0xe
    nd6 options=201<PERFORMNUD,DAD>
    media: autoselect
    status: active
utun0: flags=8051<UP,POINTOPOINT,RUNNING,MULTICAST> mtu 1380
    inet6 fe80::e6d5:2b08:9605:7496%utun0 prefixlen 64 scopeid 0xf
    nd6 options=201<PERFORMNUD,DAD>
utun1: flags=8051<UP,POINTOPOINT,RUNNING,MULTICAST> mtu 2000
    inet6 fe80::fbf:5c08:b1e1:7f8c%utun1 prefixlen 64 scopeid 0x10
    nd6 options=201<PERFORMNUD,DAD>


Possibly the host now uses the "new" naming schema introduced short before systemd was released. ("aka stable names").
Question is what interface is what.  Can you determine the MAC address of your VM and mitch it in the above list?

Otherwise the vmnet service has not been started yet. (maybe move from sysv -> systemd?).
I do expect that an upgrade procedure should handle this. Any errors during the procedure?
hi. If the script worked, and fusion is running I would see that vmnet100 listed. Plus any other ones I made. When fusion is stopped they go away

my speculation is that the vmnetcfg util does not recognize the switches.
Utility Script:vmnet-util.sh

Allows for the quick addition, updating and removal of vmnet adapters.
In order for new vmnet adapters to become visible within the Virtual
Machine, restart the virtual machine so it is re-initialized.  VMWARE
Fusion does not need to be restarted.

Version: 1.3

Add, Update, Remove VMNET Adapter:
Usage: vmnet-util.sh --add vmnet20 10.10.10.0 255.255.255.0
       vmnet-util.sh --update vmnet20 10.10.11.0 255.255.255.0
       vmnet-util.sh --remove vmnet20

Restart Services:
Usage: vmnet-util.sh --reload

Rebuild Networking Database:
Usage: vmnet-util.sh --rebuild

Export Networking Database:
Usage: vmnet-util.sh --export [filename]

Import Saved Networking Database:
Usage: vmnet-util.sh --import [filename]

Show Fusion Interfaces:
Usage: vmnet-util.sh --interfaces

/Users/richsark/


Open in new window

With debug on

/Users/

==> ./vmnet-util.sh --add vmne200 200.200.200.0 255.255.255.0
+ version=1.3
++ basename ./vmnet-util.sh
+ filename=vmnet-util.sh
+ vmapppath='/Applications/VMware Fusion.app/Contents/Library/'
+ configfile='/Library/Preferences/VMware Fusion/networking'
+ vmnet=vmne200
+ network_subnet=200.200.200.0
+ subnet_mask=255.255.255.0
+ bitbucket=/dev/null
+ vmware_pid=/var/run/vmnet-bridge.pid
+ ROOT_UID=0
++ tput setaf 1
+ fmt_red=''
++ tput bold
+ fmt_bold=''
++ tput sgr0
+ fmt_normal=''
+ fmt_bold_red=''
++ tput smul
+ fmt_underline=''
+ '[' '!' -f /var/run/vmnet-bridge.pid ']'
+ '[' 501 -ne 0 ']'
+ asroot=sudo
+ case "${1}" in
+ echo 'Adding VMNET Adapter vmne200'
Adding VMNET Adapter vmne200
+ echo ''

+ add_adapter
+ sudo '/Applications/VMware Fusion.app/Contents/Library/vmnet-cfgcli' addadapter vmne200
+ sudo '/Applications/VMware Fusion.app/Contents/Library/vmnet-cfgcli' setsubnetaddr vmne200 200.200.200.0
+ sudo '/Applications/VMware Fusion.app/Contents/Library/vmnet-cfgcli' setsubnetmask vmne200 255.255.255.0
+ sudo '/Applications/VMware Fusion.app/Contents/Library/vmnet-cfgcli' updateadapterfromconfig vmne200
+ reload_svcs
+ sudo '/Applications/VMware Fusion.app/Contents/Library/vmnet-cli' --configure
+ sudo '/Applications/VMware Fusion.app/Contents/Library/vmnet-cli' --stop
+ sudo '/Applications/VMware Fusion.app/Contents/Library/vmnet-cli' --start
+ ifconfig vmne200
ifconfig: interface vmne200 does not exist


Open in new window


What if you execute the commands by hand...

'/Applications/VMware Fusion.app/Contents/Library/vmnet-cfgcli'  addadapter vmne200

As the script dumps all output to the trashcan ( /dev/null )
alternatively redfine the bitbucket variable to /dev/tty in stead of /dev/nul
Hi, I made the modification.
first I ran that line as is like you saus:

'/Applications/VMware Fusion.app/Contents/Library/vmnet-cfgcli'  addadapter vmne200
This command (addadapter) is not supported when using MacOS network virtualization API

Then I changed the /dev/null/ to /dev/tty
now what we get

/Users/richsark/Dropbox
==> ./vmnet-util.sh --add vmnet330 30.30.30.0 255.255.255.0
Adding VMNET Adapter vmnet330

Password:
This command (addadapter) is not supported when using MacOS network virtualization API

Library Loaded
vmnetcfg: vnlsetsubnetaddr - Setting/ Removing subnet address for vnet: vmnet330 failed
Error executing command: "setsubnetaddr"

Unrecognized vnetlib command: "setsubnetsubnet_mask".
vmnetcfg Usage:
    setloglevel
    getloglevel
    setdefaultloglevel
    getdefaultloglevel
    servicestart
    servicestatus
    servicestop
    getvmnetfeatures
    gethostadapterlist
    getbridge
    getnatusage
    setnatusage
    updatenatfromconfig
    getnatportfwd
    setnatportfwd
    enumportfwd
    deletevnet
    assignsubnet
    getvmnetcount
    getvnetwithfeatures
    setsubnetaddr
    setsubnetmask
    vnetcfgget
    vnetcfgadd
    vnetcfgremove
    getdefaultbridge
    setdefaultbridge
    exportconfig
    importconfig
    createdb
    getunusedsubnet
    getunusedvnet

This command (updateadapterfromconfig) is not supported when using MacOS network virtualization API

Stopped all configured services on all networks
Backed up existing network settings to backup file "/tmp/vmware.k6AOKz"
Restored network settings
Stopped all configured services on all networks
Started all configured services on all networks
ifconfig: interface vmnet330 does not exist

Open in new window


it tels you the addadapter doesn't work so that needs a change...

And it seems more has been changed.. as the previous argument setsubnetmask now has become  setsubnetsubnet_mask ....
First you have to find out how to add adapters on your MacOS. (I have no Apple devices so i have no idea how to solve that.)



Ok. Perhaps someone can jump in? Would it be as easy as rename the command it changed too?
yes almost.    the arguments to the new command need to be given as well.
A shell script is like all commands as given from the command line, only executed one after the other.
yes you can use while / for etc. on the command line as well, but it looks a lot less friendly there.

So you can first try the commands needed from the command line and if you are satisfied, modify the script accordingly

This question needs an answer!
Become an EE member today
7 DAY FREE TRIAL
Members can start a 7-Day Free trial then enjoy unlimited access to the platform.
View membership options
or
Learn why we charge membership fees
We get it - no one likes a content blocker. Take one extra minute and find out why we block content.