最近,我被要求为工作场所的一些“经常出差的人”提供 VPN 功能。我正在运行 CentOS 5.4 Linux 服务器。我选择 OpenVPN 作为我的 VPN 服务器,并成功部署和测试了多个 Windows XP 和 7 客户端。因此,我能够手动映射网络共享。此时,所有连接都成功且稳定。
我想要做的是能够在 VPN 隧道成功设置后自动运行批处理文件来创建网络共享。我该怎么做?
我读了一些关于 up 或 route-up 命令的内容OpenVPN 手册页但我似乎不知道如何调用批处理文件。任何帮助都会有帮助。
答案1
如果共享名称始终相同,那么您可以始终在操作系统中映射它们,并且它们将处于断开连接状态,直到用户使用 VPN。这就是我们的做法,效果很好。
查看手册页,我怀疑这是您在命令行上所需要的
--up c:\script.bat
以下是部分
--up cmd
Shell command to run after successful TUN/TAP device open (pre --user UID change). The up script is useful for specifying route commands which route IP traffic destined for private subnets which exist at the other end of the VPN connection into the tunnel.
For --dev tun execute as:
cmd tun_dev tun_mtu link_mtu ifconfig_local_ip ifconfig_remote_ip [ init | restart ]
For --dev tap execute as:
cmd tap_dev tap_mtu link_mtu ifconfig_local_ip ifconfig_netmask [ init | restart ]
See the "Environmental Variables" section below for additional parameters passed as environmental variables.
Note that cmd can be a shell command with multiple arguments, in which case all OpenVPN-generated arguments will be appended to cmd to build a command line which will be passed to the shell.
Typically, cmd will run a script to add routes to the tunnel.
Normally the up script is called after the TUN/TAP device is opened. In this context, the last command line parameter passed to the script will be init. If the --up-restart option is also used, the up script will be called for restarts as well. A restart is considered to be a partial reinitialization of OpenVPN where the TUN/TAP instance is preserved (the --persist-tun option will enable such preservation). A restart can be generated by a SIGUSR1 signal, a --ping-restart timeout, or a connection reset when the TCP protocol is enabled with the --proto option. If a restart occurs, and --up-restart has been specified, the up script will be called with restart as the last parameter.
The following standalone example shows how the --up script can be called in both an initialization and restart context. (NOTE: for security reasons, don't run the following example unless UDP port 9999 is blocked by your firewall. Also, the example will run indefinitely, so you should abort with control-c).
openvpn --dev tun --port 9999 --verb 4 --ping-restart 10 --up 'echo up' --down 'echo down' --persist-tun --up-restart
Note that OpenVPN also provides the --ifconfig option to automatically ifconfig the TUN device, eliminating the need to define an --up script, unless you also want to configure routes in the --up script.
If --ifconfig is also specified, OpenVPN will pass the ifconfig local and remote endpoints on the command line to the --up script so that they can be used to configure routes such as:
route add -net 10.0.0.0 netmask 255.255.255.0 gw $5
然后也许可以删除映射驱动器