现在不少家里都置办了NAS一类的设备,有不少败家的IT男也开始用尽方法去开发这些网络设备的用途,但是由于种种原因,我们的家用网络由于部署了内网,且很多没有公网ip,所以在外面直接访问家里的设备是不现实的的,于是乎类似于DDNS(以花生壳为代表的)以及内网穿透软件(Ngrok和frp为代表的)的软件或者服务应运而生,最近微魔看到了一个frp的一键脚本,对小白是比较友好的,于是就分享给大家,实际上,由于是Go语言编写,frp和ngrok本身的安装难度很低(直接下载就可以了),关键是配置文件可能需要一些时间去学习。
#突破LAN# 内网穿透FRP一键安装脚本
注意:frp的作者声称目前frp依然在不断的探索阶段,软件不适用于生产环境!关于frp的官方说明可以到Github地址查看:https://github.com/fatedier/frp
FRP包含两个,一个是frps(服务器端),一个是frpc(客户端);安装前,你需要(1)一台具有ipv4的VPS(用于运行frps);(2)本地主机(用于运行frpc)
FRP一键安装脚本,Github地址:https://github.com/dylanbai8/frpspro,系统要求CentOS 7+、Debian 8+(理论上该脚本在其他发行版上也可以用)
一、在服务器端运行脚本
wget -N --no-check-certificate git.io/f.sh && chmod +x f.sh && bash f.sh install
由于默认的token安装级别比较低,建议更换成更复杂的
bash f.sh token
脚本还支持其他功能
bash f.sh bind_port #修改 bind_port bash f.sh vhost_http_port #修改 vhost_http_port bash f.sh vhost_https_port #修改 vhost_https_port bash f.sh dashboard_port #修改 dashboard_port bash f.sh dashboard_user #修改 dashboard_user bash f.sh dashboard_pwd #修改 dashboard_pwd bash f.sh bind_udp_port #修改 bind_udp_port bash f.sh kcp_bind_port #修改 kcp_bind_port bash f.sh subdomain_host #修改 subdomain_host (用于泛解析子域名) bash f.sh uninstall #卸载 frps
二、在客户端上的设置
(1)Windows下
如果你是想在Windows上实现被穿透功能的话,可以直接下载一键包里的Windows便携启动脚本(FrpsPro.zip),参照frpc.ini里的内容适当修改即可(加红的地方是必须要修改的,server_addr改成刚才服务器的ip,token改成刚才修改过的token)
# 绑定你的 frps 服务器: # 1.服务器IP地址或域名 2.密钥 3.端口 # 如网络卡慢,可删除最后一行注释标签“#”开启kcp传输 [common] server_addr = 170.130.142.170 token = 12345678 server_port = 7000 # protocol = kcp # http 端口转发设置 # custom_domains 可以是域名或者服务器 IP # 如需开启密码访问,删除最后两行注释标签“#”即可 [http_001] type = http local_port = 80 custom_domains = vmvps.com # http_user = admin # http_pwd = admin # https 端口转发,需要使用时删除掉每行注释标签“#”即可 # [https_001] # type = https # local_port = 443 # custom_domains = vmvps.com (如果去掉#注释,这里也需要修改,如果没有则不需要) # 开启本机文件共享 [share_file] type = tcp remote_port = 8080 plugin = static_file # 要对外暴露的文件目录 plugin_local_path = D:\ plugin_strip_prefix = static plugin_http_user = admin plugin_http_passwd = admin # 修改链接内为自己的服务器IP,通过浏览器访问 http://170.130.142.170:8080/static/ # 来查看位于 C:\ 目录下的文件,会要求输入已设置好的用户名和密码(如不需要可以注释掉) # 提示:此功能可以用于搭建静态博客 # 远程桌面,无需修改。如不需要此项可在每行前加“#”号注释掉 # 默认远程桌面连接端口为:9090 [remote_desktop] type = tcp local_port = 3389 remote_port = 9090
(2)Linux下
到Frp官方的Github上下载最新客户端(zip里的frpc和frpc.ini):https://github.com/fatedier/frp/releases
配置文件(frp.ini)可以参照下面的修改,比如我想实现使用vmvps.com:7000访问家里在80端口架设的一个网站,然后运行./frpc -c ./frpc.ini
就可以了
[common] server_addr = 170.130.142.170 token = 12345678 server_port = 7000 # protocol = kcp [web] type = http local_port = 80 custom_domains = vmvps.com
下面是本文所说的脚本源代码,实际上手动安装也非常的简单,大家可以参照这个脚本学习
#!/bin/bash
#====================================================
# System Request: Centos 7+ Debian 8+
# Author: dylanbai8
# * Frps 一键安装脚本,Frpc Windows 便捷脚本!Frp 远程桌面!
# * 开源地址:https://github.com/dylanbai8/frpspro
# Blog: https://oo0.bid
#====================================================
# 获取frps最新版本号
get_version(){
api_url="https://api.github.com/repos/fatedier/frp/releases/latest"
new_ver=`curl ${PROXY} -s ${api_url} --connect-timeout 10| grep 'tag_name' | cut -d\" -f4`
touch ./version.txt
cat < ./version.txt
${new_ver}
EOF
sed -i 's/v//g' ./version.txt
get_releases=$(cat ./version.txt)
releases_url=https://github.com/fatedier/frp/releases/download/${new_ver}/frp_${get_releases}_linux_amd64.tar.gz
windows_url=https://github.com/fatedier/frp/releases/download/${new_ver}/frp_${get_releases}_windows_amd64.zip
rm -rf ./version.txt
}
# 安装frps
install_frps(){
wget -N --no-check-certificate ${releases_url}
tar -zxvf frp*.tar.gz
rm -rf /usr/local/frps
mkdir /usr/local/frps
mv ./frp*/frps /usr/local/frps/frps
mv ./frp*/frps_full.ini /usr/local/frps/frps.ini
rm -rf ./frp*
}
# 添加开机自启动
add_auto_run(){
touch /etc/systemd/system/frps.service
cat < /etc/systemd/system/frps.service
[Unit]
Description=frps server
After=network.target
Wants=network.target
[Service]
Type=simple
PIDFile=/var/run/frps.pid
ExecStart=/usr/local/frps/frps -c /usr/local/frps/frps.ini
RestartPreventExitStatus=23
Restart=always
User=root
[Install]
WantedBy=multi-user.target
EOF
}
# 启动frps
run_frps(){
systemctl daemon-reload
systemctl enable frps >/dev/null 2>&1
systemctl start frps
systemctl restart frps
}
# 卸载frps
set_uninstall(){
systemctl stop frps
systemctl disable frps
rm -rf /usr/local/frps
rm -rf /etc/systemd/system/frps.service >/dev/null 2>&1
echo -e "卸载成功!"
}
# 展示菜单
load_menu(){
local_ip=`curl -4 ip.sb`
clear
echo ""
echo -e "--------------------安装完成----------------------"
echo -e "管理面板:http://${local_ip}:7500"
echo -e "用户名:admin 密码:admin"
echo -e "默认 bind_port:7000"
echo -e "默认 token:12345678"
echo ""
echo -e "默认 vhost_http_port:80"
echo -e "默认 vhost_https_port:443"
echo ""
echo -e "默认 bind_udp_port:7001"
echo -e "默认 kcp_bind_port:7000"
echo -e "默认 allow_ports:2000-3000,3001,3003,4000-50000"
echo ""
echo -e "Windows 便捷脚本:https://github.com/dylanbai8/frpspro/raw/master/FrpsPro.zip"
echo -e "Windows 最新内核:${windows_url}"
echo -e "--------------------------------------------------"
}
# 各种设置项
# ====================================
set_bind_port(){
get_value=""
echo -e "你正在设置 bind_port "
read -e -p "请输入:" get_value
[[ -z ${get_value} ]] && get_value="none"
if [ "${get_value}" = "none" ];then
set_bind_port
else
echo -e "你设置的值为:${get_value}"
fi
sed -i '/^bind_port/c\bind_port = '"${get_value}"'' /usr/local/frps/frps.ini
systemctl restart frps
echo -e "设置成功!"
}
set_bind_udp_port(){
get_value=""
echo -e "你正在设置 bind_udp_port "
read -e -p "请输入:" get_value
[[ -z ${get_value} ]] && get_value="none"
if [ "${get_value}" = "none" ];then
set_bind_udp_port
else
echo -e "你设置的值为:${get_value}"
fi
sed -i '/^bind_udp_port/c\bind_udp_port = '"${get_value}"'' /usr/local/frps/frps.ini
systemctl restart frps
echo -e "设置成功!"
}
set_kcp_bind_port(){
get_value=""
echo -e "你正在设置 kcp_bind_port "
read -e -p "请输入:" get_value
[[ -z ${get_value} ]] && get_value="none"
if [ "${get_value}" = "none" ];then
set_kcp_bind_port
else
echo -e "你设置的值为:${get_value}"
fi
sed -i '/^kcp_bind_port/c\kcp_bind_port = '"${get_value}"'' /usr/local/frps/frps.ini
systemctl restart frps
echo -e "设置成功!"
}
set_vhost_http_port(){
get_value=""
echo -e "你正在设置 vhost_http_port "
read -e -p "请输入:" get_value
[[ -z ${get_value} ]] && get_value="none"
if [ "${get_value}" = "none" ];then
set_vhost_http_port
else
echo -e "你设置的值为:${get_value}"
fi
sed -i '/^vhost_http_port/c\vhost_http_port = '"${get_value}"'' /usr/local/frps/frps.ini
systemctl restart frps
echo -e "设置成功!"
}
set_vhost_https_port(){
get_value=""
echo -e "你正在设置 vhost_https_port "
read -e -p "请输入:" get_value
[[ -z ${get_value} ]] && get_value="none"
if [ "${get_value}" = "none" ];then
set_vhost_https_port
else
echo -e "你设置的值为:${get_value}"
fi
sed -i '/^vhost_https_port/c\vhost_https_port = '"${get_value}"'' /usr/local/frps/frps.ini
systemctl restart frps
echo -e "设置成功!"
}
set_dashboard_port(){
get_value=""
echo -e "你正在设置 dashboard_port "
read -e -p "请输入:" get_value
[[ -z ${get_value} ]] && get_value="none"
if [ "${get_value}" = "none" ];then
set_dashboard_port
else
echo -e "你设置的值为:${get_value}"
fi
sed -i '/^dashboard_port/c\dashboard_port = '"${get_value}"'' /usr/local/frps/frps.ini
systemctl restart frps
echo -e "设置成功!"
}
set_dashboard_user(){
get_value=""
echo -e "你正在设置 dashboard_user "
read -e -p "请输入:" get_value
[[ -z ${get_value} ]] && get_value="none"
if [ "${get_value}" = "none" ];then
set_dashboard_user
else
echo -e "你设置的值为:${get_value}"
fi
sed -i '/^dashboard_user/c\dashboard_user = '"${get_value}"'' /usr/local/frps/frps.ini
systemctl restart frps
echo -e "设置成功!"
}
set_dashboard_pwd(){
get_value=""
echo -e "你正在设置 dashboard_pwd "
read -e -p "请输入:" get_value
[[ -z ${get_value} ]] && get_value="none"
if [ "${get_value}" = "none" ];then
set_dashboard_pwd
else
echo -e "你设置的值为:${get_value}"
fi
sed -i '/^dashboard_pwd/c\dashboard_pwd = '"${get_value}"'' /usr/local/frps/frps.ini
systemctl restart frps
echo -e "设置成功!"
}
set_token(){
get_value=""
echo -e "你正在设置 token "
read -e -p "请输入:" get_value
[[ -z ${get_value} ]] && get_value="none"
if [ "${get_value}" = "none" ];then
set_token
else
echo -e "你设置的值为:${get_value}"
fi
sed -i '/^token/c\token = '"${get_value}"'' /usr/local/frps/frps.ini
systemctl restart frps
echo -e "设置成功!"
}
set_subdomain_host(){
get_value=""
echo -e "你正在设置 subdomain_host "
read -e -p "请输入:" get_value
[[ -z ${get_value} ]] && get_value="none"
if [ "${get_value}" = "none" ];then
set_subdomain_host
else
echo -e "你设置的值为:${get_value}"
fi
sed -i '/^subdomain_host/c\subdomain_host = '"${get_value}"'' /usr/local/frps/frps.ini
systemctl restart frps
echo -e "设置成功!"
}
# ====================================
# 关闭apache2 释放80端口
set_unapache2(){
systemctl disable httpd >/dev/null 2>&1
systemctl stop httpd >/dev/null 2>&1
killall -9 httpd >/dev/null 2>&1
systemctl disable apache2 >/dev/null 2>&1
systemctl stop apache2 >/dev/null 2>&1
killall -9 apache2 >/dev/null 2>&1
systemctl disable firewalld >/dev/null 2>&1
systemctl stop firewalld >/dev/null 2>&1
killall -9 firewalld >/dev/null 2>&1
systemctl disable iptables >/dev/null 2>&1
systemctl stop iptables >/dev/null 2>&1
killall -9 iptables >/dev/null 2>&1
echo -e "关闭 apache2 成功!"
echo -e "关闭 防火墙 成功!"
}
# 安装流程
set_install(){
get_version
install_frps
add_auto_run
run_frps
load_menu
}
# 脚本菜单
case "$1" in
bind_port|bind_udp_port|kcp_bind_port|vhost_http_port|vhost_https_port|dashboard_port|dashboard_user|dashboard_pwd|token|subdomain_host|install|uninstall|unapache2)
set_$1
;;
*)
echo -e "缺少参数,更多教程请访问:https://github.com/dylanbai8/kmspro"
;;
esac
# 转载请保留版权:https://github.com/dylanbai8/frpspro