概述:
# su获取root # wget https://github.com/fatedier/frp/releases/download/v0.26.0/frp_0.26.0_linux_amd64.tar.gz # wget https://github.com/fatedier/frp/releases/download/v0.53.2/frp_0.53.2_linux_amd64.tar.gz # wget https://github.com/fatedier/frp/releases/download/v0.52.3/frp_0.52.3_linux_amd64.tar.gz # 解压:tar xf frp_0.26.0_linux_amd64.tar.gz # 改名:mv frp_0.26.0_linux_amd64 frp # 进入目录:cd frp # 删除没用的客户端文件:rm -f frpc* # 配置文件:vim frps.ini # 编辑ini文件 按ins进入编辑(精简)
[common] bind_addr = xxx.xxx.xxx.xxx # frps内网服务器地址,如果有防火墙的话,设置下述端口映射 bind_port = xxxxx # frps服务端口 bind_udp_port = xxxx # udp服务端口 vhost_http_port = xxxxx # http服务端口 vhost_https_port = xxxxx # https服务端口 privilege_token = xxxxxxxx # 握手密钥 subdomain_host = xxxx.xxx # 填写顶级域名,意味着对应frpc的2级域名代理启用 dashboard_port = xxxx # 服务器面板端口 dashboard_user = xxxxx # 服务器面板用户 dashboard_pwd = xxxxxxx # 服务器面板密码 log_file = ./frpslog.log log_level = info log_max_days = 3
./frps -c ./frps.ini
nohup ./frps -c ./frps.ini &
ps -aux | grep frp
kill -9 PID
mkdir /etc/frps
cp /源目录/frps.ini /etc/frps/
cp /源目录/usr/etc/frps
/etc/systemd/system/
sudo vim /etc/systemd/system/frps.service 新建此文件,并写入以下内容
[Unit] Description=frps Dgn After=network.target [Service] Type=simple # User=root ExecStart=/usr/etc/frps/frps -c /etc/frps_aker/frps.ini # /usr/etc/frps 文件目录,注意service文件中要指向frps运行程序(这个没查到网上解释,以为只要放个空文档,其实要放入执行文件,搞了半天才运行成功!!!) # /etc/frps/frps.ini 配置目录 [Install] WantedBy=multi-user.target
sudo systemctl start frps # (把start改为stop即终止frps) sudo systemctl enable frps systemctl status frps # 查看frps状态
vi /etc/rc.local # 在最下面加一行/usr/sbin/frp/frps -c /usr/sbin/frp/frps.ini # 其中 /usr/sbin/frp是程序放置的目录,自己修改,重启ok
ps aux | grep frps
sudo systemctl status frps
firewall-cmd --permanent --add-port=xxxx/tcp # 开放bind_port(frps服务)# 必须 firewall-cmd --permanent --add-port=xxxx/tcp # 开放dashboard_port(服务面板http)# 必须 firewall-cmd --permanent --add-port=xxxx/tcp # 开放vhost_http_port(http端口)# 按需 firewall-cmd --permanent --add-port=xxxx/tcp # 开放vhost_http_port(https端口)# 按需 firewall-cmd --permanent --add-port=xxxx/tcp # 开放bind_udp_port端口(udp直连)# 按需 firewall-cmd --permanent --add-port=xxxx/tcp # 开放kcp_bind_port端口(kcp端口)# 按需 firewall-cmd --reload #重启防火墙(修改配置后要重启防火墙) firewall-cmd --list-all # 查看防火墙规则
firewall-cmd --zone=public --add-port=10067/tcp --permanent firewall-cmd --reload
yum install firewalld firewalld-config
firewall-cmd --zone=public --add-port=80/tcp --permanent firewall-cmd --zone=public --add-port=443/tcp --permanent firewall-cmd --zone=public --add-port=22/tcp --permanent firewall-cmd --zone=public --add-port=53/udp --permanent
firewall-cmd --zone=public --remove-port=80/tcp --permanent firewall-cmd --zone=public --remove-port=443/tcp --permanent firewall-cmd --zone=public --remove-port=22/tcp --permanent firewall-cmd --zone=public --remove-port=53/udp --permanent
firewall-cmd --permanent --add-rich-rule="rule family="ipv4" source address="192.168.100.1" port protocol="tcp" port="80" accept" #添加源IP 192.168.100.1访问80端口 firewall-cmd --permanent --add-rich-rule="rule family="ipv4" source address="192.168.100.0/24" port protocol="tcp" port="80" accept" #添加IP段访问80端口 firewall-cmd --permanent --remove-rich-rule="rule family="ipv4" source address="192.168.100.1" port protocol="tcp" port="80" accept" #删除源IP 192.168.100.1访问80端口
firewall-cmd --permanent --add-rich-rule="rule family="ipv4" source address="192.180.10.10" accept" firewall-cmd --reload
firewall-cmd --zone=public --add-port=4400-4600/udp --permanent firewall-cmd --zone=public --add-port=4400-4600/tcp --permanent
firewall-cmd --permanent --list-ports firewall-cmd --permanent --list-all firewall-cmd --permanent --list-rich-rules
[common] server_addr = xxx.xxx.xxx.xxx # 服务器地址 server_port = xxxx # 服务器端口 privilege_token = xxxxxx # token = xxxxxx 有些服务端版本采用这个字节,多数采用“privilege_token”字节,token理解为密码 protocol = tcp [http] type = http # http协议orhttps协议,如果两个都要的话就单独复制一段[https] local_ip = 192.168.x.xx # 群晖的内网IP local_port = xxxxx # 你自己的web服务器端口 custom_domains = xxxxxxx.xxx # 如果你有自己的域名,可以设置你自己的域名,先将自己的顶级域名解析到frp服务器域名(如二级域名的话用CNAME记录,不要用A记录) #subdomain = nas # 全局下唯一的子域名,你的访问地址将会是http://subdomain.xxx.xxx,服务器端必须已绑定顶级域名,否则不要设置; # 此外,顶级域名需要在域名系统上做好CNAME的泛解析,否则不可用。HOST:*.xxx.xxx;Value:xxx.xxx。 [ssh] type = tcp local_ip = 192.168.x.xxx local_port = xxxxxx # 需要转发到的端口,ssh端口默认是22 remote_port = xxxxxx # frp服务端的远程监听端口,即你访问服务端的remote_port就相当于访问客户端的 local_port,如果填0则会随机分配一个端口 #[DSM] # type = tcp # tcp协议 # local_ip = 192.168.x.xxx # 127.0.0.1指穿透本机,也可以填写群晖内网IP. # local_port = xxxxxx # 群晖内网HTTP端口,默认为5000. # remote_port = xxxx # 映射到外网端口,暴露给服务器,这个客户端必须唯一 # subdomain = nas # 全局下唯一的子域名,你的访问地址将会是http://subdomain.xxx.xxx,服务器端必须已绑定顶级域名,否则不要设置; # 此外,顶级域名需要在域名系统上做好CNAME的泛解析,否则不可用。HOST:*.xxx.xxx;Value:xxx.xxx。
frpc 是一款轻量级的反向代理客户端,用于实现内网穿透功能。它需要与 frps 服务端配合使用。以下是 frpc 的配置文件格式和示例。
从 frp 0.52.0 版本开始,支持 TOML、YAML 和 JSON 配置文件格式,并逐渐弃用 INI 格式。以下以 TOML 格式 为例进行说明。
以下是 frpc 的基本配置文件示例,用于将本地的 SSH 服务(端口 22)映射到公网:
# frpc.toml 配置文件示例 # 服务端基本信息 serverAddr = "your_server_ip" # frps 服务端的公网 IP 地址 serverPort = 7000 # frps 服务端监听的端口 auth.method = "token" # 认证方式(默认为 token) auth.token = "your_token" # 与服务端一致的认证 token # 是否启用 TLS 加密 transport.tls.enable = false # 定义一个隧道 [[proxies]] name = "ssh" # 隧道名称,可自定义 type = "tcp" # 隧道类型(tcp、http、https 等) localIP = "127.0.0.1" # 本地服务的 IP 地址 localPort = 22 # 本地服务的端口 remotePort = 20022 # 远程映射的端口
- serverAddr 和 serverPort:指定 frps 服务端的地址和端口[^39^]。 - auth.token:用于与服务端进行身份验证,确保连接的安全性[^39^]。 - proxies:定义一个或多个隧道,每个隧道可以配置不同的服务类型和端口[^39^]。 - type:支持多种协议类型,如 tcp、http、https 等[^39^]。 - localIP 和 localPort:指定本地服务的 IP 和端口[^39^]。 - remotePort:指定远程映射的端口,用于从公网访问本地服务[^39^]。
通常,frpc 的配置文件(如 `frpc.toml`)放置在 `/usr/local/frpc` 目录下[^41^]。你可以通过以下命令创建目录并编辑配置文件:
mkdir -p /usr/local/frpc cd /usr/local/frpc vim frpc.toml
配置完成后,使用以下命令启动 frpc:
./frpc -c frpc.toml
或者使用 systemd 管理服务[^41^]:
# 创建 systemd 服务文件 vi /etc/systemd/system/frpc.service # 添加以下内容 [Unit] Description=frpc service After=network.target [Service] Type=simple ExecStart=/usr/local/frpc/frpc -c /usr/local/frpc/frpc.toml [Install] WantedBy=multi-user.target # 启动服务 systemctl start frpc systemctl enable frpc
通过以上步骤,你可以在 CentOS 中完成 frpc 的配置,实现内网服务的外网访问[^41^]。
大鹿搭建frp反向代理服务的背景:
FRPS使用0.53.2版本,FRPC依旧采用0.26.0