在macOS中配置VPN

Gao

为 macOS 配置 VPN

配置 VPN 服务器

搭建 vpn 服务

从系统仓库安装ipsec 安装xl2tpd

在服务器上启动服务

配置好服务账户

systemctl restart ipsec
systemctl restart xl2tpd

配置 VPN Client

Mac App Store安装Apple Configurator 2

创建 VPN 描述文件

选择l2tp协议配置服务器地址、用户名、密码和共享密钥

把描述文件安装到macOS的系统配置,iOS通过airDrop安装

安装完成即可连接 vpn

配置 macOS 在 VPN 连接时的路由表

使用[static-routes][https://github.com/gsmlg/static-routes]的配置

路由表数据时使用 maxmine 公开的 geoip 数据库来进行配置

/etc/ppp/目录配置ip-up,ip-down对应在 VPN 启动和停止时执行对应脚本

脚本中可以使用变量说明

$1 interface etc: ppp0
$2 none?
$3 ? 0
$4 client ip
$5 remote ip
$6 local gateway

命令行中控制 VPN

VPN connections

Usage: scutil --nc [command]

	list
		List available network connection services in the current set

	status <service>
		Indicate whether a given service is connected, as well as extended status information for the service

	show <service>
		Display configuration information for a given service

	statistics <service>
		Provide statistics on bytes, packets, and errors for a given service

	select <service>
		Make the given service active in the current set. This allows it to be started

	start <service> [--user user] [--password password] [--secret secret]
		Start a given service. Can take optional arguments for user, password, and secret

	stop <service>
		Stop a given service

	suspend <service>
		Suspend a given service (PPP, Modem on Hold)

	resume <service>
		Resume a given service (PPP, Modem on Hold)

	ondemand [-W] [hostname]
	ondemand -- --refresh
		Display VPN on-demand information

	trigger <hostname> [background] [port]
		Trigger VPN on-demand with specified hostname, and optional port and background flag

	enablevpn <service or vpn type> [path]
		Enables the given VPN application type. Takes either a service or VPN type. Pass a path to set ApplicationURL

	disablevpn <service or vpn type>
		Disables the given VPN application type. Takes either a service or VPN type

	help
		Display available commands for --nc