稳定端口映射工具_内网穿透软件_本地映射外网教程交流_nat123论坛客服

 找回密码
 获得新生
查看: 999189|回复: 36

[分享] 无公网IP搭建openNPV虚拟网配置详细过程,及外网的连接访问

  [复制链接]
发表于 2014-8-6 12:09:04 | 显示全部楼层 |阅读模式
通过nat123,不管身在何处,都可访问无公网IP搭建的NPV虚拟网。

环境描述:
A机openNPV服务端,无公网IP,内网地址192.168.1.26(NPV地址10.8.0.1)。
B机openNPV客户端,无公网IP,内网地址192.168.1.22(NPV地址10.8.0.6)。
A机与B机属于同一局域网,B机只是为了测试NPV搭建成功。

实现目标:
不管身在何处,都可通过NPV访问A机内网,即使A机是无公网IP部署的NPV。
实现手段:
Nat123全端口映射(转发)P2P。
教程案例内容概要:A机无公网IP搭建部署NPV——B机在内网测试NPV的连通性——不管身在何处都可通过nat123访问A机NPV。

一,无公网IP搭建部署NPV
新手建议尽量使用默认配置,流程走通了,默认的成功搭建好了后再进一步学习扩展配置。
1.下载安装NPV
openNPV安装包是没有区分服务端和客户端的,服务端和客户端的安装过程都一样。自行百度网上找OpenNPV Windows版下载地址(建议选择最新版本下载使用,由于政策原因国外官网地址可能在国内不能访问,可自行找相关第三方下载)本文以openNPV2.3.4版本为示例。在安装过程中,提示选择组件时,有二个加密组件SSL/RSA默认是没有选择的,需要选择打勾。


其他默认即可。安装后,可以发现电脑多了一个新的本地连接,它就是NPV连接用的。

2.NPV服务端配置
(1)配置固定信息。
OpenNPV安装目录\easy-rsa\vars.bat.sample修改这个配置文件的固定信息,在配置过程中会出现显示。这里配置好了,在配置过程中出现时,直接回车使用这些配置即可。
set KEY_COUNTRY=CN              国家set KEY_PROVINCE=GD              省份
set KEY_CITY=GZ              城市
set KEY_ORG=nat123              组织
set KEY_EMAIL=nat123@nat123.com                            邮箱


(2)初始化及证书生成
开始菜单/运行/CMD打开命令窗口,进入安装目录下的easy-rsa目录开始相关配置。
C:\Documents and Settings\Administrator>cd C:\Program Files\OpenNPV\easy-rsa
C:\Program Files\OpenNPV\easy-rsa>init-config
C:\Program Files\OpenNPV\easy-rsa>copy vars.bat.sample vars                            由上一个命令自动生成
已复制         1 个文件。
C:\Program Files\OpenNPV\easy-rsa>vars              如在配置过程中,中断关闭CMD窗口,需要先执行一次vars.bat再继续
C:\Program Files\OpenNPV\easy-rsa>clean-all              如出现“找不到路径文件”提示,忽略它
已复制         1 个文件。
已复制         1 个文件。



C:\Program Files\OpenNPV\easy-rsa>build-ca              执行ca命令
WARNING: can't open config file: /etc/ssl/openssl.cnf
Loading 'screen' into random state - done
Generating a 1024 bit RSA private key
...........................................++++++.++++++
writing new private key to 'keys\ca.key'
-----
You are about to be asked to enter information that will be incorporatedinto your certificate request.
What you are about to enter is what is called a Distinguished Name or a DN.There are quite a few fields but you can leave some blank
For some fields there will be a default value,
If you enter '.', the field will be left blank.
-----
Country Name (2 letter code) [CN]:              直接回车,使用[]里面预设配置信息State or Province Name (full name) [GD]:              直接回车,使用[]里面预设配置信息
Locality Name (eg, city) [GZ]:              直接回车,使用[]里面预设配置信息
Organization Name (eg, company) [nat123]:                            直接回车,使用[]里面预设配置信息
Organizational Unit Name (eg, section) [changeme]:nat123                            自定义
Common Name (eg, your name or your server's hostname) [changeme]:nat123ca              唯一名称
Name [changeme]:nat123              自定义
Email Address [nat123@nat123.com]:                            直接回车,使用[]里面预设配置信息

这里需要注意的是,common name是唯一标记,接下来配置出现的这个common name名称都是唯一的,不能有相同的common name名称,否则,它会报错:找不到 C:\Program Files\OpenNPV\easy-rsa\keys\*.old"。为避免名称不符错误,所有自定义名称都使用同一个名称(nat123),以下配置也是。

C:\Program Files\OpenNPV\easy-rsa>build-dh              执行dh命令
WARNING: can't open config file: /etc/ssl/openssl.cnf
Loading 'screen' into random state - done
Generating DH parameters, 1024 bit long safe prime, generator 2
This is going to take a long time
............................+....................................


C:\Program Files\OpenNPV\easy-rsa>build-key-server server              生成服务端证书
WARNING: can't open config file: /etc/ssl/openssl.cnf
Loading 'screen' into random state - done
Generating a 1024 bit RSA private key
........++++++
..................++++++
writing new private key to 'keys\server.key'
-----
You are about to be asked to enter information that will be incorporated
into your certificate request.
What you are about to enter is what is called a Distinguished Name or a DN.
There are quite a few fields but you can leave some blank
For some fields there will be a default value,
If you enter '.', the field will be left blank.
-----
Country Name (2 letter code) [CN]:              回车,使用[]里面预设配置
State or Province Name (full name) [GD]:              回车,使用[]里面预设配置
Locality Name (eg, city) [GZ]:              回车,使用[]里面预设配置
Organization Name (eg, company) [nat123]:                            回车,使用[]里面预设配置
Organizational Unit Name (eg, section) [changeme]:nat123                            自定义
Common Name (eg, your name or your server's hostname) [changeme]:server              唯一名称
Name [changeme]:nat123              自定义
Email Address [nat123@nat123.com]:              回车,使用[]里面预设配置
Please enter the following 'extra' attributes
to be sent with your certificate request
A challenge password []:12345678                            密码
An optional company name []:nat123              自定义
WARNING: can't open config file: /etc/ssl/openssl.cnf
Using configuration from openssl-1.0.0.cnf
Loading 'screen' into random state - done
Check that the request matches the signature
Signature ok
The Subject's Distinguished Name is as follows
countryName           RINTABLE:'CN'
stateOrProvinceName   RINTABLE:'GD'
localityName          RINTABLE:'GZ'
organizationName      RINTABLE:'nat123'
organizationalUnitNameRINTABLE:'nat123'
commonName            RINTABLE:'server'
name                  RINTABLE:'nat123'
emailAddress          :IA5STRING:'nat123@nat123.com'
Certificate is to be certified until Aug  2 16:17:51 2024 GMT (3650 days)
Sign the certificate? [y/n]:y              输入y确认
1 out of 1 certificate requests certified, commit? [y/n]y                            输入y确认
Write out database with 1 new entries
Data Base Updated                            表示服务端证书生成成功

为避免自定义名称不符错误,所有自定义名称都使用同一个(nat123),以下配置也是。为避免密码不符错误,所有密码都使用同一个(12345678),以下配置也是。
C:\Program Files\OpenNPV\easy-rsa>build-key client                            生成客户端证书
WARNING: can't open config file: /etc/ssl/openssl.cnf
Loading 'screen' into random state - done
Generating a 1024 bit RSA private key
.........++++++
..............++++++
writing new private key to 'keys\client.key'
-----
You are about to be asked to enter information that will be incorporated
into your certificate request.
What you are about to enter is what is called a Distinguished Name or a DN.There are quite a few fields but you can leave some blank
For some fields there will be a default value,
If you enter '.', the field will be left blank.
-----
Country Name (2 letter code) [CN]:              回车,使用[]里面预设值
State or Province Name (full name) [GD]:              回车,使用[]里面预设值
Locality Name (eg, city) [GZ]:              回车,使用[]里面预设值
Organization Name (eg, company) [nat123]:              回车,使用[]里面预设值
Organizational Unit Name (eg, section) [changeme]:nat123                            自定义
Common Name (eg, your name or your server's hostname) [changeme]:client              唯一名称
Name [changeme]:nat123              自定义
Email Address [nat123@nat123.com]:              回车,使用[]里面预设值
Please enter the following 'extra' attributes
to be sent with your certificate request
A challenge password []:12345678                            密码
An optional company name []:nat123              自定义
WARNING: can't open config file: /etc/ssl/openssl.cnf
Using configuration from openssl-1.0.0.cnf
Loading 'screen' into random state - done
Check that the request matches the signature
Signature ok
The Subject's Distinguished Name is as follows
countryName           RINTABLE:'CN'
stateOrProvinceName   RINTABLE:'GD'
localityName          RINTABLE:'GZ'
organizationName      :PRINTABLE:'nat123'
organizationalUnitName:PRINTABLE:'nat123'
commonName            :PRINTABLE:'client'
name                  :PRINTABLE:'nat123'
emailAddress          :IA5STRING:'nat123@nat123.com'
Certificate is to be certified until Aug  2 16:38:28 2024 GMT (3650 days)
Sign the certificate? [y/n]:y              输入y确定
1 out of 1 certificate requests certified, commit? [y/n]y                            输入y确定
Write out database with 1 new entries

笔者在配置过程中,为避免名称/密码不符错误,所有自定义名称一样为(nat123),以下配置也是。所有密码输入都一样为(12345678),以下配置也是。
执行完以上相关命令后,可以发现,多了个OpenNPV\easy-rsa\keys文件夹目录,及里面一堆生成的证书文件什么的。


(3)复制服务端相关文件到指定目录
将OpenNPV\easy-rsa\keys目录下服务端相关文件复制到OpenNPV\config目录下。相关文件有:ca.crt、ca.key、dh1024.pem、server.crt、server.csr、server.key。将\OpenNPV\sample-config\server.oNPV文件复制到OpenNPV\config目录下

修改文件\OpenNPV\config\server.oNPV内容(推荐修改使用TCP协议)。

(4)启动服务
控制面板/系统工具/服务/openNPV service服务名,默认启动方式是手动的,需要手动启动它。



3.NPV客户端配置连接
(1)复制客户端相关文件到指定目录
将OpenNPV(服务端)\easy-rsa\keys目录下客户端相关文件复制到OpenNPV(客户端)\config目录下。相关文件有:ca.crt、ca.key、client.crt、client.csr、client.key。
将\OpenNPV\sample-config\client.oNPV文件复制到OpenNPV\config目录下

修改文件\OpenNPV\config\client.oNPV内容。修改连接访问NPV服务器内网IP地址(同时推荐使用TCP)。
remote 192.168.1.26 1194              这个IP地址就是NPV内网IP地址
proto tcp               推荐修改使用TCP可靠协议通信(同时需要在服务端的server.oNPV同样使用tcp一致协议)



(2)启动NPV客户端测试连接
双击桌面上的openNPV快速图标,或开始菜单里面的NPV目录,启动名称OpenNPV GUI。启动后电脑右下角出现NPV图标,右键/connect连接


连接成功后有successful提示,可查看到本地NPV本地、服务端NPV地址等相关信息。

到此表示,NPV已搭建成功。如果服务端主机允许远程桌面,可以使用NPV服务端地址(10.8.0.1)远程桌面测试下。

远程桌面成功,表示NPV木有问题,可以通过NPV地址进行连接访问。  

二,外网访问内网无公网IP的NPV
1.NPV服务端或其局域网安装使用nat123
添加nat123端口映射,使用全端口映射(转发)p2p。内网地址是NPV服务端主机地址,外网地址是域名,域名可以直接使用提示默认免费二级域名NPV26.nat123.net(xxx.nat123.net格式,xxx自定义)。

2.NPV客户端安装使用nat123访问者,访问NPV
Nat123安装包安装后包含nat123和nat123p2p访问者。桌面或开始菜单找到nat123p2p访问者,启用访问者后,添加NPV被nat123映射后的域名NPV26.nat123.net及访问端口1194。
修改文件\OpenNPV\config\client.oNPV内容。修改连接访问NPV服务器内网IP地址。
remote NPV26.nat123.net 1194              将这个地址修改为nat123p2p访问者访问的域名


打开NPV客户端进行成功连接。出现127地址表示NPV客户端是经过本地nat123p2p访问者连接的。

到此表示,nat123访问者已打通NPV访问。如果服务端主机允许远程桌面,可以使用NPV服务端地址(10.8.0.1)远程桌面测试下。

远程桌面成功,表示nat123访问者没有问题,可以通过nat123访问者进行连接访问。


三,总结
NPV配置总结:
\OpenNPV\easy-rsa\vars.bat.sample配置预定固定信息
init-configvars
clean-all
build-ca
build-dh
build-key-server server 服务端证书
build-key client1 客户端证书
build-key client2客户端证书
build-key client3客户端证书
\easy-rsa\keys\服务端配置文件+\sample-config\server.oNPV复制到——服务端\config\目录
在服务端,启动NPV服务
\easy-rsa\keys\客户端配置文件+\sample-config\client.oNPV复制到——客户端\config\目录
在客户端,打开NPV桌面快速方式GUI进行连接
Nat123映射NPV总结:
在NPV服务端主机或局域网内使用nat123全端口映射
在外网NPV客户端使用nat123访问者
  
提示:
1.全端口映射在某些特定环境下会穿透失败,如P2P终结者等2端网络路由限制时,穿透失败会自动走转发。
2.如默认UDP不行,可更换为TCP,注意server.oNPV和client.oNPV需要对应。
3.由于NPV版本环境的不断更新,建议参考更多第三方教程搭建好NPV服务且确保在局域网内测试可以正常先再使用映射外网。

  
Codeplayer《OpenNPV下载、安装、配置及使用详解》http://www.365mini.com/page/14.htm月光博客《OpenNPV的配置和使用》http://www.williamlong.info/archives/3814.html
更多技术交流访问nat123论坛http://bbs.nat123.com






本帖子中包含更多资源

您需要 登录 才可以下载或查看,没有帐号?获得新生

x
发表于 2014-10-16 15:52:51 | 显示全部楼层
学习一下
发表于 2014-10-16 13:37:19 | 显示全部楼层

谢谢,分享~~~
发表于 2014-8-9 10:09:19 | 显示全部楼层
有没有PPTP的vpn设置教程呢
发表于 2014-8-11 11:42:38 | 显示全部楼层
学习一下
发表于 2014-9-19 10:30:50 | 显示全部楼层
学习一下
发表于 2014-9-23 21:49:52 | 显示全部楼层

学习一下
发表于 2014-9-27 21:22:41 | 显示全部楼层
VPN有什么用啊,好像几乎没用过   自  由   门,,倒是一直在用
发表于 2014-9-28 18:24:01 | 显示全部楼层
不懂?
发表于 2014-10-11 11:33:51 | 显示全部楼层
不明觉厉
您需要登录后才可以回帖 登录 | 获得新生

本版积分规则

http穿透|80网站穿透|非80网站穿透|内网穿透路由器|内网穿透SVN|内网穿透FTP|内网穿透SSH|内网穿透远程桌面|nat123

GMT+8, 2025-3-25 01:01 , Processed in 0.140391 second(s), 21 queries .

Powered by Discuz! X3.1

© Comsenz Inc. | 反馈:natbbs#163.com(#换成@)

快速回复 返回顶部 返回列表