我试图build立一个OpenVPN的服务器,将dynamic分配客户端的IP地址从给定的范围,我需要服务器有一个特定的静态IP地址,而不是在地址范围的开始(例如192.168.0.200而不是192.168.0.1)。 这是我的服务器configuration文件:
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
在研究了网上的文档和例子之后,我认为“ifconfig …”这一行可以做到这一点,但是openvpn一直在为虚拟接口(tap0)分配192.168.0.1。 在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
为什么openvpn忽略“ifconfig …”这一行? 我不知道它是否相关,但我使用openvpn 2.3和Ubuntu操作系统。
有什么build议么?
我把你指向了--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"
例如,如果您希望您的服务器使用10.8.0.254 IP而不是10.8.0.1,则需要对configuration文件进行一些更改。
首先将“proto tcp”或“proto udp”行更改为“proto tcp-server”或“proto udp-server”
然后注释掉这一行:
server 10.8.0.0 255.255.255.0
并添加这些行:
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"
重新启动openvpn服务,就是这样。