我正在使用DD-WRT的PPTP客户端连接到VPN。在Services / PPTP客户端配置页面上,我指定了远程子网192.168.112.0和掩码255.255.255.0。
一旦建立了连接,就会自动添加该路由。但是,通过该连接还可以使用其他子网,例如192.168.7.0,但我必须在命令行中手动添加这些路由才能使其正常工作。
我相信VPN服务器一定是在发送路由列表,因为当我使用Windows XP连接到VPN时,所有这些子网的路由都会自动添加到路由表中。
有没有办法让DD-WRT在建立连接时自动添加这些路由?也就是说,如果VPN服务器后面的网络配置发生了变化,我就不必在DD-WRT上手动编辑路由表。
DNS服务器也是如此,有没有一种方法可以避免手动输入用于VPN连接的DNS服务器?
发布于 2013-03-23 07:08:47
当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上工作。
发布于 2014-03-28 17:32:34
尽管前面的答案对于linux通常是正确的,但是您不能在某些ddwrt路由器上轻松地编辑或添加文件。
当pptp客户端运行时,我使用的所有4个ddwrt路由器都会生成这些文件,这使得更改或添加文件变得不可能。
以下是一种似乎适用于大多数路由器http://stadar.org/content/ddwrt-pptp-client-add-routes-after-connection的解决方法
https://stackoverflow.com/questions/5595877
复制相似问题