DD-WRT(pptp-client):连接到VPN时自动添加路由和DNS信息?

发布于 2024-10-31 08:20:26 字数 396 浏览 3 评论 0原文

我正在使用 DD-WRT 的 PPTP 客户端连接到 VPN。在服务/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 服务器?

I'm using DD-WRT's PPTP client to connect to a VPN. On the Services / PPTP Client configuration page, I specified remote subnet 192.168.112.0 and the mask 255.255.255.0.

Once the connection is established, that route is automatically added. However, there other subnets that are available through that connection, such as 192.168.7.0 but I have to manually add these routes at the command line to make it work.

I believe the VPN server must be sending a list of routes because when I use Windows XP to connect to the VPN, routes for all those subnets are automatically added to the routing table.

Is there a way to have DD-WRT automatically add these routes when the connection is established? That was, if the network configuration changes behind the VPN server, I wouldn't have to manually edit the routing table on my DD-WRT.

Same thing for the DNS server, is there a way to avoid manually entering the DNS server to use for the VPN connection?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

对风讲故事 2024-11-07 08:20:26

当 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 上工作。

When the ppp connection starts this script:

/etc/ppp/ip-up

is executed in your system. Note that there are some variables that are passed from the server. Read the last for statement, it will start a few more scripts:

#!/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

in the /etc/ppp/ip-up.d folder I have a file called 40-dns.sh. It looks like this and it will set the /etc/resolve.conf with the DNS servers sent by the VPN server

#!/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

For the routes to be pushed in the routing table on connection estabilished you should be able to do a similar trick. Go to the pppd man pages to see the variable names that you need to use.

This code samples are from my Gentoo Linux PC, but this stuff is Linux generic so it will work also on DD-WRT.

娜些时光,永不杰束 2024-11-07 08:20:26

虽然之前的答案对于 Linux 一般而言是正确的,但您无法在某些 ddwrt 路由器上轻松编辑或添加文件。

我使用的所有 4 个 ddwrt 路由器都会在 pptp 客户端运行时生成这些文件,因此无法仅更改或添加文件。

这是一种似乎适用于大多数路由器的解决方法 http:// stadar.org/content/ddwrt-pptp-client-add-routes-after-connection

Although previous answer is correct for linux in general, you cannot edit or add files that easily on some ddwrt routers.

All 4 ddwrt routers I use generate these files when pptp client is run, making it impossible to just change or add files.

Here is a workaround that seems to work on most routers http://stadar.org/content/ddwrt-pptp-client-add-routes-after-connection

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文