以管理员身份运行CMD
1 2 3 4 5 | #从IE导入代理设置 netsh winhttp import proxy ie #独立设置代理 netsh winhttp set proxy 127.0.0.1:1088 "<local>;localhost;127.*;10.*;172.16.*;192.168.*" |
以管理员身份运行CMD
1 2 3 4 5 | #从IE导入代理设置 netsh winhttp import proxy ie #独立设置代理 netsh winhttp set proxy 127.0.0.1:1088 "<local>;localhost;127.*;10.*;172.16.*;192.168.*" |
本文介绍使用 StrongSwan 搭建 VPN 的过程,适合有一定 linux 基础的用户。
StrongSwan 是基于 OpenSource IPsec 的 VPN 解决方案,官方网站:https://www.strongswan.org/ ,如果无法访问请使用科学上网,原因你懂的。
在命令行设置代理服务器。
1 2 3 4 5 6 | #获取 http 请求的代理设置 npm config get proxy npm config set proxy="http://127.0.0.1:1080" #获取 https 请求的代理设置 npm config get https-proxy npm config set https-proxy="http://127.0.0.1:1080" |
代理服务器可以使用小灰机(小灰机同时支持 socks 代理和 http 代理)
因为众所周知的原因,在国内使用 NuGet 时会经常无法下载包,严重影响工作效率,下面说一下如何给 NuGet 设置代理。
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 | <?xml version="1.0" encoding="utf-8"?> <configuration> <config> <add key="http_proxy" value="http://127.0.0.1:1080" /> </config> <packageSources> <add key="nuget.org" value="https://api.nuget.org/v3/index.json" protocolVersion="3" /> <add key="Microsoft Visual Studio Offline Packages" value="C:\Program Files (x86)\Microsoft SDKs\NuGetPackages\" /> </packageSources> <packageRestore> <add key="enabled" value="True" /> <add key="automatic" value="True" /> </packageRestore> <bindingRedirects> <add key="skip" value="False" /> </bindingRedirects> <packageManagement> <add key="format" value="0" /> <add key="disabled" value="False" /> </packageManagement> <disabledPackageSources> <add key="Microsoft Visual Studio Offline Packages" value="true" /> </disabledPackageSources> </configuration> |
代理服务器可以是任何 http 代理,也可以用小灰机代理(小灰机本身即是 socks 代理也是 http 代理)。
Win10 的 Hyper-V 虚拟机默认安装有一个虚拟交换机,这个交换机不能修改,也不能删除,它默认启用NAT, 可以连接外网。但有一个缺点,每次重启主机系统后它的ip都会随机改变,当有多个虚拟机想组内网时无法使用这个交换机。
1 2 3 4 5 6 7 8 | #下载安装脚本 wget https://raw.githubusercontent.com/Angristan/OpenVPN-install/master/openvpn-install.sh #给脚本增加可执行权限 chmod +x openvpn-install.sh #运行脚本安装 ./openvpn-install.sh |
想要更多?没了!就是这么简单。
安装过程需要用户选择多次选择设置项。按提示输入序号就可以。 具体说明请看 这里
如果你同我一样需要在路由器上连接 OpenVPN 服务端,可能会遇到一些问题,最典型的就是客户端的版本过低,服务端不支持。例如我的华硕路由器的 OpenVPN 客户端是 2.3.2 版本的,上面安装的服务端加密方式要求最低版本为2.4。
要解决这个问题,只需修改几项配置即可。
修改服务端配置
1 | nano /etc/openvpn/server.conf |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 | port 1194 proto udp dev tun user nobody group nobody persist-key persist-tun keepalive 10 120 topology subnet server 10.8.0.0 255.255.255.0 ifconfig-pool-persist ipp.txt push "dhcp-option DNS 8.8.8.8" push "dhcp-option DNS 8.8.4.4" push "redirect-gateway def1 bypass-dhcp" crl-verify crl.pem ca ca.crt cert server_7nXHxN25RjHzpvzv.crt key server_7nXHxN25RjHzpvzv.key dh dh.pem compress lz4-v2 push "compress lz4-v2" tls-server tls-auth tls-auth.key 0 cipher AES-256-CBC status /var/log/openvpn/status.log verb 3 |
修改客户端配置
在脚本的同一目录下会生成一个 .ovpn 文件,这是给客户端的配置文件。编辑它。
1 | nano client.ovpn |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 | client proto udp remote 你的ip或域名 1194 dev tun resolv-retry infinite nobind persist-key persist-tun remote-cert-tls server verify-x509-name server_TP2kfJ5lwhmkDCEc name auth SHA256 auth-nocache cipher AES-128-CBC tls-client #注释掉下面两行 #tls-version-min 1.2 #tls-cipher TLS-DHE-RSA-WITH-AES-128-GCM-SHA256 setenv opt block-outside-dns verb 3 <ca> #此处省略 </ca> <cert> #此处省略 </cert> <key> #此处省略 </key> key-direction 1 <tls-auth> #此处省略 </tls-auth> |
保存之后将此文件上传到路由器,即可成功连接vpn。
查看服务端运行状态
1 | systemctl status openvpn@server |