shell

mac 设置 vmware fusion Net 网卡网段

文 / sptk 来源 / 原创 阅读 / 384 1年前

1. 请复制下面脚本内容,保存成set_subnet.sh 你也可以使用其他名字。

#!/bin/bash
# sed usage: https://www.tutorialspoint.com/unix/unix-regular-expressions.htm

net_dir='/Library/Preferences/VMware Fusion'
dhcp_dir='/Library/Preferences/VMware Fusion/vmnet8'


echo "back up networking file..."
sudo mv "$net_dir/networking" "$net_dir/networking.bak"

echo "back up dhcpd.conf file..."
sudo mv "$dhcp_dir/dhcpd.conf" "$dhcp_dir/dhcpd.conf.bak"

# recieve subset from use input
echo 'Please input ip subnet address (example: 192.168.88):'
read ip

# sed -i in mac invalid,use >> replace it
# mac sed -i "" 's/pattern/replace/g',"" must exist
# in furture, update it! 
echo "update networking files for vmware8..."
sudo cat "$net_dir/networking.bak" | sed 's/\(VNET_8_HOSTONLY_SUBNET\) \([1-9]\{1,\}\.\)\{3\}/\1 '$ip'./g' >> "$net_dir/networking"

echo 'update subnet for hdcpd.conf...'
regex_str="s/\([1-9]\{1,\}\.\)\{3\}/'${ip}.'/g"
sudo cat "$dhcp_dir/dhcpd.conf.bak" | sed 's/\([1-9]\{1,\}\.\)\{3\}/'$ip'./g' >> "$dhcp_dir/dhcpd.conf"

# show info to prompt user for setting or updating static gateway and static dns 
# in mac: \033[1;31m  1; must exist
echo -e "\033[1;31m Set IP SubNet: $ip \033[0m"
echo -e "\033[1;31m If you set static ip, please set or update your linux gatway and dns: $ip.2 \033[0m"
echo -e "\033[1;31m Please quit completely your vmware fusion and restart it. \033[0m"

2. 切换到你保存脚本所在的路径,请修改权限 sudo chmod u+x set_subnet.sh

3. 执行脚本 sudo ./set_subnet.sh 根据脚本提示输入你要设置的网段即可。 例如设置成192.168.100 网段。 脚本支持设置的是C 类内网地址网段。不支持B类

0

站点声明:站点主要用于个人技术文章。

冀ICP备19037883号
相关侵权、举报、投诉及建议等,请发E-mail:804330969@qq.com