在本地外网/局域网环境下搭建的网站,正常情况下只能在同个局域网下访问,想要实现内网用户也才能正常访问,可以通过外网穿透来实现。
做外网穿透,无需网段IP,也无需步入到路由器配置,在本地安装个外网穿透工具,之后创建隧洞,将其映射到网段,生成网段地址就可以。
如cpolar外网穿透,只须要在本地安装顾客端,进行简单的配置,就可以实现内网访问外网,不限制流量,支持http/https/tcp合同,支持Windows/linux/macOS。
1.安装配置cpolar外网穿透顾客端(支持永久免费)
须要先注册一个cpolar帐号,旁边会用到。
cpolar-安全的外网穿透工具
1.1Windows
windows系统可以在cpolar官网下载最新的安装包,之后解压默认安装即可。
1.2Linux
linux系统支持一键手动安装脚本
1.2.1安装
国外使用
curl -L https://www.cpolar.com/static/downloads/install-release-cpolar.sh | sudo bash
美国使用
curl -sL https://git.io/cpolar | sudo bash
1.2.2向系统添加服务
sudo systemctl enable cpolar
1.2.3启动服务
sudo systemctl start cpolar
1.2.4查看服务状态
sudo systemctl status cpolar
如正常显示active,则说明早已启动成功。
1.3macOS
在官网下载下载适用于macOS平台的zip压缩包,解压后得到cpolarlinux 内网访问外网,之后通过命令行带参数运行即可。
1.3.1通过Homebrew包管理器安装
brew tap probezy/core && brew install cpolar
1.3.2token认证
登陆cpolar官网后台————验证linux 输入法,查看自己的认证tokenlinux 内网访问外网,然后将token贴在命令行里
cpolar authtoken xxxxxxx
1.3.2安装服务
sudo cpolar service install
1.3.2启动服务
sudo cpolar service start
2.确认所需映射的本地端口
如将本地8080端口下的网站,发布到内网可访问。创建隧洞映射本地8080端口,http合同
cpolar http 8080
隧洞创建成功后,会生成相应的网段URL地址,内网用户访问该URL地址就可以访问到外网/局域网的网站红旗linux系统,如右图: