TJA
TJA

Reputation: 3041

How can I access a VPN inside a VMWare Fusion VM

I have a VPN connection in MacOS BigSur but I can't access it inside a Linux VM running under VMWare Fusion V12.1.2.

Upvotes: 2

Views: 1268

Answers (1)

TJA
TJA

Reputation: 3041

The issue has been fixed in V12.2.0 VMWare Fusion 12.2.0 Release Notes

The solution is to manually create the VPN tunnel and link it to the VM as there are multiple commands involved and the IP Address can change I created the following script to execute the required commands.

#!/bin/bash

function ask_yes_or_no() {
    read -p "$1 ([y]es or [N]o): "
    case $(echo $REPLY | tr '[A-Z]' '[a-z]') in
        y|yes) echo "yes" ;;
        *)     echo "no" ;;
    esac
}

currNatRules=$(sudo pfctl -a com.apple.internet-sharing/shared_v4 -s nat 2>/dev/null)
if test -z "$currNatRules" 
then
    echo -e "\nThere are currently no NAT rules loaded\n"
    exit 0
fi

utunCheck=$(echo $currNatRules | grep utun)
if test -n "$utunCheck"
then
    echo -e "\nIt looks like the VPN tunnel utun2 has already been created"
    echo -e "\n$currNatRules\n"

    if [[ "no" == $(ask_yes_or_no "Do you want to continue?") ]]
    then
        echo -e "\nExiting\n"
        exit 0
    fi
fi


natCIDR=$(echo $currNatRules | grep en | grep nat | cut -d\  -f 6)
if test -z "$natCIDR" 
then
    echo -e "\nCannot extract the NAT CIDR from:"
    echo -e "\n$currNatRules\n"
    exit 0
fi

interface=$(route get 10/8 | grep interface | cut -d\  -f 4)

echo -e "\nNAT CIDR=$natCIDR Interface=$interface\n"

newRule="nat on ${interface} inet from ${natCIDR} to any -> (${interface}) extfilter ei"

echo -e "\nAdding new rule: $newRule\n"

configFile="fixnat_rules.conf"

[[ -d $configFile ]] && rm $configFile
echo "$currNatRules" > $configFile
echo "$newRule" >> $configFile

sudo pfctl -a com.apple.internet-sharing/shared_v4 -N -f  ${configFile} 2>/dev/null

echo -e "\nConfig update applied\n"

sudo pfctl -a com.apple.internet-sharing/shared_v4 -s nat 2>/dev/null

echo -e "\n"

exit 0

Upvotes: 2

Related Questions