如何为我的 OpenVPN 服务器分配特定的 IP 地址?

mik*_*ike 7 openvpn

我正在尝试设置一个 OpenVPN 服务器,它可以从给定范围内动态地为客户端分配 IP 地址,并且我需要该服务器具有一个特定的静态 IP 地址,该地址不在地址范围的开头(例如 192.168.0.200 而不是192.168.0.1)。这是我的服务器配置文件:

mode server
port 1134
proto tcp6-server
dev tap
ca ca.crt
cert server.crt
key server.key
dh dh1024.pem
server 192.168.0.0 255.255.255.0
; the following line does not work :-(
ifconfig 192.168.0.200 255.255.255.0
client-to-client
duplicate-cn
keepalive 10 120
cipher AES-256-CBC
comp-lzo
max-clients 32
verb 15
mute 10
Run Code Online (Sandbox Code Playgroud)

在研究了网上的文档和示例后,我认为“ifconfig ...”行可以解决问题,但 openvpn 一直将 192.168.0.1 分配给虚拟接口 (tap0)。在 openvpn 服务器初始化期间,可以看到这一行:

Fri Apr  4 14:58:07 2014 us=410085 /sbin/ifconfig tap0 192.168.0.1 netmask 255.255.255.0 mtu 1500 broadcast 192.168.0.255
Run Code Online (Sandbox Code Playgroud)

为什么 openvpn 忽略“ifconfig ...”行?我不知道它是否相关,但我使用 openvpn 2.3 和 Ubuntu OS。

有什么建议?

小智 7

例如,如果您希望您的服务器使用 10.8.0.254 IP 而不是 10.8.0.1,那么您需要对配置文件进行一些更改。

首先将“proto tcp”或“proto udp”行改为“proto tcp-server”或“proto udp-server”

然后注释掉这一行:

server 10.8.0.0 255.255.255.0
Run Code Online (Sandbox Code Playgroud)

并添加这些行:

mode server
tls-server
ifconfig 10.8.0.254 10.8.0.253
ifconfig-pool 10.8.0.1 10.8.0.252
route 10.8.0.0 255.255.255.0
push "route 10.8.0.254"
Run Code Online (Sandbox Code Playgroud)

重启 openvpn 服务,就是这样。


Zor*_*che 2

我向您指出该--server选项的文档。如果您想手动指定内容,请不要使用该--server选项。相反,手动输入您想要的指令。请参阅完整的手册页以获取其功能列表--server

   --server network netmask
          A helper directive designed to  simplify  the  configuration  of
          OpenVPN's  server  mode.   This directive will set up an OpenVPN
          server which will allocate addresses to clients out of the given
  ->>>>   network/netmask.   The  server itself will take the ".1" address
          of the given network for use as the server-side endpoint of  the
          local TUN/TAP interface.

          For example, --server 10.8.0.0 255.255.255.0 expands as follows:

               mode server
               tls-server
               push "topology [topology]"

               ...

               if dev tap OR (dev tun AND topology == subnet):
                 ifconfig 10.8.0.1 255.255.255.0
                 if !nopool:
                   ifconfig-pool 10.8.0.2 10.8.0.254 255.255.255.0
                 push "route-gateway 10.8.0.1"
Run Code Online (Sandbox Code Playgroud)