我正在使用DD-WRT的PPTP客户端连接到VPN。在Services/PPTP Client配置页面,我指定了远程子网192.168.112.0和掩码255.255.255.0。
一旦连接建立,该路由将自动添加。但是,还有其他子网可以通过该连接使用,例如192.168.7.0,但是我必须在命令行中手动添加这些路由才能使其工作。
我相信VPN服务器一定在发送路由列表,因为当我使用Windows XP连接到VPN时,所有这些子网的路由都会自动添加到路由表中。
是否有办法让DD-WRT在连接建立时自动添加这些路由?也就是说,如果VPN服务器后面的网络配置发生了变化,我就不必手动编辑DD-WRT上的路由表了。
同样的事情为DNS服务器,有没有一种方法来避免手动输入DNS服务器用于VPN连接?
当ppp连接开始时:
/etc/ppp/ip-up
在您的系统中执行。注意,有一些变量是从服务器传递过来的。阅读最后的for
语句,它将启动更多的脚本:
#!/bin/sh
# This script is run by pppd after the link is established.
# It executes all the scripts available in /etc/ppp/ip-up.d directory,
# with the following parameters:
# $1 = interface name (e.g. ppp0)
# $2 = tty device
# $3 = speed
# $4 = local IP address
# $5 = remote IP address
# $6 = ipparam (user specified parameter, see man pppd)
ifconfig $1 mtu 1280 || true
cd /etc/ppp/ip-up.d || exit
for SCRIPT in *.sh ; do
. ./"${SCRIPT}" "$@"
done
在/etc/ppp/ip-up.d
文件夹我有一个文件叫40-dns.sh
。它看起来像这样,它将使用VPN服务器发送的DNS服务器设置/etc/resolve.conf
#!/bin/sh
# Handle resolv.conf generation when usepeerdns pppd option is being used.
# Used parameters and environment variables:
# $1 - interface name (e.g. ppp0)
# $USEPEERDNS - set if user specified usepeerdns
# $DNS1 and $DNS2 - DNS servers reported by peer
if [ "$USEPEERDNS" ]; then
if [ -x /sbin/resolvconf ]; then
{
echo "# Generated by ppp for $1"
[ -n "$DNS1" ] && echo "nameserver $DNS1"
[ -n "$DNS2" ] && echo "nameserver $DNS2"
} | /sbin/resolvconf -a "$1"
else
# add the server supplied DNS entries to /etc/resolv.conf
# (taken from debian's 0000usepeerdns)
# follow any symlink to find the real file
REALRESOLVCONF=$(readlink -f /etc/resolv.conf)
if [ "$REALRESOLVCONF" != "/etc/ppp/resolv.conf" ]; then
# merge the new nameservers with the other options from the old configuration
{
grep --invert-match '^nameserver[[:space:]]' $REALRESOLVCONF
cat /etc/ppp/resolv.conf
} > $REALRESOLVCONF.tmp
# backup the old configuration and install the new one
cp -dpP $REALRESOLVCONF $REALRESOLVCONF.pppd-backup
mv $REALRESOLVCONF.tmp $REALRESOLVCONF
# correct permissions
chmod 0644 /etc/resolv.conf
chown root:root /etc/resolv.conf
fi
fi
fi
对于要在建立连接时推送到路由表中的路由,您应该能够执行类似的技巧。到pppd手册页查看您需要使用的变量名。
这个代码示例来自我的Gentoo Linux PC,但是这个东西是Linux通用的,所以它也可以在DD-WRT上工作。
虽然前面的答案对于一般linux来说是正确的,但是在一些ddwrt路由器上不能轻松地编辑或添加文件。
当pptp客户端运行时,我使用的所有4个ddwrt路由器都会生成这些文件,因此不可能只是更改或添加文件。
这是一个解决方案,似乎在大多数路由器上工作http://stadar.org/content/ddwrt-pptp-client-add-routes-after-connection