VMware Communities
richsark2000
Contributor
Contributor

Old vmnet script does not work on fussion 12

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.0Adding VMNET Adapter vmnet

Password:ifconfig: interface vmnet does not exist

 

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

 

# Ok... here is the skinny.   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
Spoiler
 
 

Could someone adjust it so it works on the most current vmware fusion.?


 

Reply
0 Kudos
3 Replies
tgbauer
Contributor
Contributor

Looks like there was a move from vmnet to bridge.

might be worth changing the line:

  ifconfig | grep -i vmnet | cut -d ":" -f1 | xargs -n1 ifconfig

to:

  ifconfig | grep -i ^bridge | cut -d ":" -f1 | xargs -n1 ifconfig

 

Reply
0 Kudos
tgbauer
Contributor
Contributor

Looks like there was a move from vmnet to bridge.

might be worth changing the line:

 

  ifconfig | grep -i vmnet | cut -d ":" -f1 | xargs -n1 ifconfig

 

to:

 

  ifconfig | grep -i ^bridge | grep -iv -e ^bridge0: | cut -d ":" -f1 | xargs -n1 ifconfig

 

This version excludes 'bridge0:' as that seems to be unrelated to Fusion.  If you have other bridge interfaces unrelated to Fusion, can add them with additional (-e) parameters after  ' -e ^bridge0:' and changing the number to match the one want to exclude

 

Reply
0 Kudos
Technogeezer
Immortal
Immortal

I don't think it's going to be as easy as that. The proposed changes don't impact the error message seen as the changes are not in the section of code adds an interface. It's being thrown directly from vmnet-cfgcli and is complaining that it doesn't know about a "vmnet" interface. 

Given that Fusion has changed its implementation to adhere to newer Apple guidelines, the host interface naming doesn't appear to be as straightforward as it used to be. As an example, here's what you would see if you did make the changes suggested and ran the script with the --interfaces option. It's not obvious at all outside of the IP addresses which vmnets these interfaces belong to (and note there's a bridge0 that has nothing to do with Fusion networking):

% ifconfig | grep -e ^bridge | grep -iv -e ^bridge0: | cut -d ":" -f1 | xargs -n1 ifconfig
bridge100: flags=8863<UP,BROADCAST,SMART,RUNNING,SIMPLEX,MULTICAST> mtu 1500
options=3<RXCSUM,TXCSUM>
ether 16:98:77:33:23:64 
inet 192.168.49.1 netmask 0xffffff00 broadcast 192.168.49.255
inet6 fe80::1498:77ff:fe33:2364%bridge100 prefixlen 64 scopeid 0x14 
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: vmenet0 flags=3<LEARNING,DISCOVER>
        ifmaxaddr 0 port 19 priority 0 path cost 0
Address cache:
nd6 options=201<PERFORMNUD,DAD>
media: autoselect
status: active
bridge101: flags=8863<UP,BROADCAST,SMART,RUNNING,SIMPLEX,MULTICAST> mtu 1500
options=3<RXCSUM,TXCSUM>
ether 16:98:77:33:23:65 
inet 192.168.33.1 netmask 0xffffff00 broadcast 192.168.33.255
inet6 fe80::1498:77ff:fe33:2365%bridge101 prefixlen 64 scopeid 0x16 
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: vmenet1 flags=3<LEARNING,DISCOVER>
        ifmaxaddr 0 port 21 priority 0 path cost 0
member: vmenet2 flags=3<LEARNING,DISCOVER>
        ifmaxaddr 0 port 23 priority 0 path cost 0
Address cache:
0:50:56:f8:6e:55 Vlan1 vmenet1 1195 flags=0<>
nd6 options=201<PERFORMNUD,DAD>
media: autoselect
status: active 

Update: I debugged the script and found that while the script does make the expected changes into the networking configuration file the interface doesn't seem to be found in the macOS ifconfig listing. I have the Fusion Tech Preview release (equivalent of Fusion Pro) and while the new vmnet appears in the GUI networking selections, it looks to be an incomplete configuraiton as no network interfaces come alive on the macOS side of things.

And also, the add script does do a "ifconfig <vmnetnane>" to try and verify that the new interface has come alive on macOS, which does fail, as you see...

It's likely that the changes necessary for Fusion to use the macOS virtualization framework have changed some things to configure the interfaces. There's obviously more going on now to configure the network interface than what you see in this script.

This is not a simple fix since VMware doesn't document how to use the vmnet-clicfg command to manage interfaces on macOS. There would have to be a bit more reverse engineering time and effort (and trial and error) to make this work.

Manually editing the "networking" file and restarting Fusion is probably the suggested workaround for the time being (or, purchaing Fusion Pro which has this functionality built-in).

- Paul (Technogeezer)
Editor of the Unofficial Fusion Companion Guides
Reply
0 Kudos