博客
-
用incus 开 NAT 小鸡
开小鸡条件
1、公网ipv4 vps一台做母鸡。注意:不能是NAT(必须)
2、ipv6(非必须):如果你的母鸡支持ipv6 /64,可以给小小鸡直接分配ipv6
如果没有,可以注册 he.net 账号,利用 he.net 的ipv6 隧道服务实现小小鸡ipv6 公网的支持步骤:
1、通过ssh连接你的vps
2、DD 重装系统(非必须)系统最好是debian 12, 也可以在主机商后台直接重装为debian12
我喜欢自己DD,命令如下:
没有安装wget curl的可以先安装一下apt update && apt install wget curl -y国外
curl -O https://raw.githubusercontent.com/bin456789/reinstall/main/reinstall.sh || wget -O ${_##*/} $_国内
curl -O https://cnb.cool/bin456789/reinstall/-/git/raw/main/reinstall.sh || wget -O ${_##*/} $_执行命令
bash reinstall.sh debian 11 --ssh-port SSH端口 --password 密码执行完输入 reboot 重启 等待重装完成
3、swap(可选)
curl -L https://raw.githubusercontent.com/spiritLHLS/addswap/main/addswap.sh -o addswap.sh && chmod +x addswap.sh && bash addswap.sh默认 选1 一直回车就行
检测环境
使用后续脚本的务必执行本命令检测宿主机是否符合要求
bash <(wget -qO- --no-check-certificate https://raw.githubusercontent.com/oneclickvirt/incus/main/scripts/pre_check.sh)incus 安装
curl -L https://raw.githubusercontent.com/oneclickvirt/incus/main/scripts/incus_install.sh -o incus_install.sh && chmod +x incus_install.sh && bash incus_install.sh自定义批量生成版本
curl -L https://github.com/oneclickvirt/incus/raw/main/scripts/add_more.sh -o add_more.sh && chmod +x add_more.sh && bash add_more.sh按提示生成即可
开完容器后,具体信息会生成在当前目录下的log文件中 使用
cat log查看已开容器
文章来源:https://www.nodeloc.com/t/topic/61325 -
服务器没有IPv6 却解析IPv6地址 导致无法访问网站
编辑
nano /etc/network/interfaces粘贴
iface eth0 inet6 static disable-ipv6 yes重启后生效
临时:
sudo sysctl -w net.ipv6.conf.all.disable_ipv6=1 sudo sysctl -w net.ipv6.conf.default.disable_ipv6=1永久生效 编辑
/etc/sysctl.conf添加:net.ipv6.conf.all.disable_ipv6 = 1 net.ipv6.conf.default.disable_ipv6 = 1 -
VPS常用命令及脚本
自动同步校正系统时间
apt install systemd-timesyncd timedatectl set-ntp true设置时区为北京时间
timedatectl set-timezone Asia/ShanghaiBBR调参脚本
wget http://sh.xdmb.xyz/tcp.sh && bash tcp.sh一个精简的 Linux TCP/IP & BBR 参数智能优化脚本
bash <(curl -sL https://raw.githubusercontent.com/yahuisme/network-optimization/main/script.sh)详情访问: https://github.com/yahuisme/network-optimization
科技lion脚本工具箱
bash <(curl -sL kejilion.sh)一键DD/重装脚本 (One-click reinstall OS on VPS)
详情访问:https://github.com/bin456789/reinstall
检测VPS回程国内三网路由
详情访问:https://github.com/zhucaidan/mtr_trace
curl https://raw.githubusercontent.com/zhucaidan/mtr_trace/main/mtr_trace.sh|bashIP质量体检脚本
详情访问:https://github.com/xykt/IPQuality
bash <(curl -Ls https://Check.Place) -Idocker版
docker run --rm --net=host -it xykt/check -I && docker rmi xykt/check > /dev/null 2>&1网络质量体检脚本
详情访问:https://github.com/xykt/NetQuality
bash <(curl -Ls https://Check.Place) -Ndocker版
docker run --rm --net=host -it xykt/check -N && docker rmi xykt/check > /dev/null 2>&1融合怪测评项目
详情访问:https://github.com/oneclickvirt/ecs
export noninteractive=true && curl -L https://raw.githubusercontent.com/oneclickvirt/ecs/master/goecs.sh -o goecs.sh && chmod +x goecs.sh && bash goecs.sh env && bash goecs.sh install && goecsdocker版
docker run --rm spiritlhl/goecs:latest -menu=false -l zh临时禁用IPv6
sysctl -w net.ipv6.conf.all.disable_ipv6=1 net.ipv6.conf.default.disable_ipv6=1其它
wget -qO- bench.sh | bashbash <(curl -sL https://run.NodeQuality.com) -
使用cloudflare测速及生成测速文件
测速网址:https://speed.cloudflare.com/
生成测速文件:
1G测速文件
https://speed.cloudflare.com/__down?during=download&bytes=107374182410G测速文件
https://speed.cloudflare.com/__down?during=download&bytes=10737418240以此类推
2G后面改成2147483648
5G后面改成5368709120
100G后面改成107374182400
VPS测速
wget "https://speed.cloudflare.com/__down?during=download&bytes=10737418240" -
Debain使用ntp同步时间
apt-get update apt-get install ntpdate ntpdate ntp1.aliyun.com -
Debian11 服务器禁用IPv6
1、编辑/etc/sysctl.conf文件
sudo nano /etc/sysctl.conf在文件末尾添加:
net.ipv6.conf.all.disable_ipv6 = 1 net.ipv6.conf.default.disable_ipv6 = 1保存文件后执行:
sudo sysctl -p或
sysctl -p -
服务器挂载webdav
1、安装davfs2
apt install davfs22、挂载
挂载时根据提示输入账号密码
mkdir /webdav mount -t davfs 这里是webdav地址 /webdav3、保存账号密码
echo "webdav地址 用户名 密码" > /etc/davfs2/secrets4、开机自动挂载
添加到/etc/rc.local
echo "mount -t davfs webdav地址 挂载路径" >> /etc/rc.local添加到/etc/fstab
echo "webdav地址 挂载路径 davfs defaults 0 0" >> /etc/fstab -
使用阿里云ESA边缘函数获取访问用户IP
async function handleRequest(request) { const url = new URL(request.url); const path = url.pathname; const ip = request.headers.get('x-forwarded-for')?.split(',')[0]||request.headers.get('x-alicdn-security-xff') if(path==='/'){ return new Response(ip, { headers: { "content-type": "text/html;charset=UTF-8", }, }) } else if(path==='/json'){ return new Response(JSON.stringify({ ip }), { headers: { 'content-type': 'application/json', }, }); } else if(path==='/info'){ const info = { ip, geo: request.info } return new Response(JSON.stringify({ info }), { headers: { 'content-type': 'application/json', }, }); } else { return new Response("404", {status: 404}) } } export default { async fetch(request) { return handleRequest(request); } }; -
使用EdgeOne的边缘函数获取用户IP
原本是想用EdgeOne Pages实现 像CloudFlare Pages那样部署一个
后来发现EdgeOne的边缘函数可以搞定 然后就折腾了一下
首先添加域名
进入edgeone控制台 选择已绑定域名
点击添加域名 输入你需要设置的二级域名 回源配置随便填 模板选择 不使用模板
添加完成后等待部署完成 HTTPS配置选择免费证书
在等待部署期间 左侧菜单滑动到底部 边缘函数 选择函数管理
新建函数 选第一个 创建Hello World 模板即可 点击下一步
输入函数名称 下面函数代码区域 粘贴函数代码 替换原有的
addEventListener('fetch', event => { event.respondWith(handleRequest(event.request)); }); function handleRequest(request) { const url = new URL(request.url); const path = url.pathname; // 通过 request.eo.clientIp 获取客户端 IP const ip = request.eo.clientIp || ''; if(path==='/'){ return new Response(ip, {status: 200,headers: { "content-type": "text/html;charset=UTF-8", }}) } else if(path==='/json'){ return new Response(JSON.stringify({ ip }), { headers: { 'content-type': 'application/json', }, }); } else if(path==='/info') { const info = { ip, geo: request.eo.geo } return new Response(JSON.stringify({ info }), { headers: { 'content-type': 'application/json', }, }); } else { return new Response("404", {status: 404}) } }20250905更新
支持cors白名单 设置allowedDomains 就行addEventListener('fetch', event => { event.respondWith(handleRequest(event.request)); }); function handleRequest(request) { const url = new URL(request.url); const path = url.pathname; const ip = request.eo.clientIp || ''; const origin = request.headers.get('Origin'); // ✅ 配置你想要支持的主域名列表(不包含协议和路径) const allowedDomains = [ 'lcsoul.cn', 'localhost', '127.0.0.1' ]; // 检查 origin 是否匹配任何一个允许的域名(包括子域名) const corsOrigin = isOriginAllowed(origin, allowedDomains) ? origin : null; // 处理预检请求 (OPTIONS) if (request.method === 'OPTIONS') { if (corsOrigin) { const headers = { 'Access-Control-Allow-Origin': corsOrigin, 'Access-Control-Allow-Methods': 'GET, POST, PUT, DELETE, OPTIONS', 'Access-Control-Allow-Headers': 'Content-Type, Authorization', 'Access-Control-Max-Age': '86400', // 24小时缓存预检 }; return new Response(null, { status: 204, headers }); } return new Response('Forbidden', { status: 403 }); } // 构建实际响应 let response; if (path === '/') { response = new Response(`${ip}\n`, { status: 200, headers: { 'content-type': 'text/html;charset=UTF-8' }, }); } else if (path === '/json') { response = new Response(JSON.stringify({ ip }), { headers: { 'content-type': 'application/json' }, }); } else if (path === '/info') { const info = { ip, geo: request.eo.geo, }; response = new Response(JSON.stringify({ info }), { headers: { 'content-type': 'application/json' }, }); } else { response = new Response('404 Not Found', { status: 404 }); } // 添加 CORS 响应头(仅当来源合法) if (corsOrigin) { response.headers.set('Access-Control-Allow-Origin', corsOrigin); response.headers.set('Access-Control-Allow-Methods', 'GET, POST, PUT, DELETE, OPTIONS'); response.headers.set('Access-Control-Allow-Headers', 'Content-Type, Authorization'); } return response; } /** * 判断 origin 是否属于允许的域名或其子域名 * 支持 http:// 和 https://,忽略协议 */ function isOriginAllowed(origin, allowedDomains) { if (!origin || typeof origin !== 'string') return false; try { const url = new URL(origin); // 自动补全协议处理 const hostname = url.hostname; // 如:api.example.com for (const domain of allowedDomains) { // 匹配主域名本身:example.com if (hostname === domain) return true; // 匹配子域名:*.example.com if (hostname.endsWith('.' + domain)) return true; } } catch (e) { return false; } return false; }点击 创建并保存部署
在部署成功弹窗中 点击新增触发规则
触发条件中填入上面添加的子域名然后确定保存
这时候就可以访问子域名获取访问用户的IP了
PS:添加域名时选择开启IPv6访问 因网络访问默认IPv6优先 大概率只能获取到v6地址(如果有)
如果需要获取IPv4 可以再添加一个域名 关闭IPv6访问 然后再去边缘函数 触发配置中 在刚添加的规则中添加新增的子域名即可
如果啥也不知道 添加完边缘函数 在列表中点击函数名称 进入详情后点击编辑代码
编辑页面右上角有个AI助手 可以让AI帮你写(有坑自行注意)
参考文档:
-
宝塔面版 docker访问面板数据库 远程访问数据库
进入mysql:
mysql -uroot -p使用mysql库:
use mysql;查看用户表:
SELECT `Host`,`User` FROM user;更新用户表:(其中%的意思是允许所有的ip远程访问)
UPDATE user SET `Host` = '%' WHERE `User` = 'root' LIMIT 1;强制刷新权限:
flush privileges;如果遇到
ERROR 2002 (HY000): Can't connect to local server through socket '/run/mysqld/mysqld.sock' (2)可以使用 TCP 连接代替 socket(临时绕过)
mysql -uroot -p -h 127.0.0.1