virtual-machine - 如何访问 VMWare Fusion VM 内的 VPN
问题描述
我在 MacOS BigSur 中有一个 VPN 连接,但我无法在 VMWare Fusion V12.1.2 下运行的 Linux VM 中访问它。
解决方案
该问题已在 V12.2.0 VMWare Fusion 12.2.0 发行说明中得到修复
解决方案是手动创建 VPN 隧道并将其链接到 VM,因为涉及多个命令并且 IP 地址可以更改我创建了以下脚本来执行所需的命令。
#!/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
推荐阅读
- rest - 通过 REST 将 msg 发送到 Azure 服务总线队列
- regex - 找出一个字符串是否只包含 ASCII 字符
- amazon-cloudfront - 在记录之前修改 CloudFront 请求?
- python - 使用 Python 从 Microsoft Forms 下载 .xlsx 文件
- asp.net-core-2.0 - asp.net core 2.0 Configuration.GetConnectionString 似乎没有读取 appsetting.environment.json
- shell - 检查是否在给定的时间戳范围内创建了目录
- python - 在 python 中使用 re.compile 和搜索计算微分多项式的系数
- r - R - 应用于列表的深层嵌套元素
- sql - 如何将数据从 SQL Server 传输到 mongodb(使用 mongoose 模式进行验证)
- asp.net-mvc - DataType.PhoneNumber 属性对显示没有影响