【问题标题】:DD-WRT (pptp-client): Automatically add routes and DNS info when connected to VPN?DD-WRT(pptp-client):连接到VPN时自动添加路由和DNS信息?
【发布时间】:2011-08-01 12:56:21
【问题描述】:

我正在使用 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 连接?

【问题讨论】:

    标签: routing dns vpn router


    【解决方案1】:

    虽然之前的答案通常对 linux 是正确的,但您无法在某些 ddwrt 路由器上轻松编辑或添加文件。

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

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

    【讨论】:

      【解决方案2】:

      当 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 上运行。

      【讨论】:

        猜你喜欢
        • 2011-01-26
        • 1970-01-01
        • 2012-08-20
        • 1970-01-01
        • 2011-06-08
        • 2023-02-04
        • 2019-09-14
        • 2015-03-08
        • 2015-11-03
        相关资源
        最近更新 更多