Compare commits

...

5 Commits

Author SHA1 Message Date
dichgrem
04ce288ebc update:kernel_config 2025-12-04 16:24:13 +08:00
dichgrem
b734d178be add:momo_config
fmt:config_style
2025-12-04 10:15:46 +08:00
dichgrem
22ac82223c update:readme 2025-11-28 15:54:22 +08:00
dichgrem
db26e0df53 style:add_pic
fix:dns
2025-11-10 17:27:49 +08:00
dichgrem
f68d592b18 fix:ipv6only 2025-11-10 16:49:38 +08:00
21 changed files with 1017 additions and 3862 deletions

View File

@@ -4,7 +4,11 @@ Sing-box 是一个现代、高性能、功能强大的跨平台代理核心,
本仓库主要包括singbox示例配置以及快速,智能的部署脚本,可以一键部署以下协议并给出标准链接,具体实现见手动安装部分.
- 手动安装:见 [Hysteria2](https://github.com/Dichgrem/singbox-example/blob/main/hysteria2.md) / [Reality](https://github.com/Dichgrem/singbox-example/blob/main/singbox.md)
<p align="center">
<img src="https://github.com/Dichgrem/singbox-example/blob/main/run.png" width="400">
</p>
- 手动安装:见 [Hysteria2](https://github.com/Dichgrem/singbox-example/blob/main/tutorial/hysteria2.md) / [Reality](https://github.com/Dichgrem/singbox-example/blob/main/tutorial/singbox.md)
- 全自动安装Reality:
``wget https://raw.githubusercontent.com/Dichgrem/singbox-example/refs/heads/main/script/singbox.sh``,随后``bash ./singbox.sh``
- 全自动安装Hysteria2:

View File

@@ -0,0 +1,205 @@
{
"dns": {
"servers": [
{
"tag": "local",
"type": "udp",
"server": "223.5.5.5"
},
{
"tag": "public",
"type": "https",
"server": "dns.alidns.com",
"domain_resolver": "local"
},
{
"tag": "foreign",
"type": "https",
"server": "8.8.8.8",
"detour": "Server1"
},
{
"tag": "fakeip",
"type": "fakeip",
"inet4_range": "198.18.0.0/15",
"inet6_range": "fc00::/18"
}
],
"rules": [
{
"rule_set": "geosite-cn",
"server": "public"
},
{
"query_type": [
"A",
"AAAA"
],
"server": "fakeip",
"rewrite_ttl": 1
}
],
"final": "foreign",
"strategy": "prefer_ipv4",
"independent_cache": true,
"reverse_mapping": true
},
"outbounds": [
{
"tag": "Server1",
"type": "vless",
"server": "xxx.xxx.xxx.xxx",
"server_port": 8443,
"uuid": "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx",
"tls": {
"enabled": true,
"server_name": "xxxxxxxxxxxx",
"insecure": false,
"reality": {
"enabled": true,
"public_key": "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx",
"short_id": "xxxxxxxxxxxx"
},
"utls": {
"enabled": true,
"fingerprint": "firefox"
}
},
"flow": "xtls-rprx-vision"
},
{
"tag": "Server2",
"type": "vless",
"server": "xxx.xxx.xxx.xxx",
"server_port": 8443,
"uuid": "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx",
"tls": {
"enabled": true,
"server_name": "xxxxxxxxxxxx",
"insecure": false,
"reality": {
"enabled": true,
"public_key": "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx",
"short_id": "xxxxxxxxxxxx"
},
"utls": {
"enabled": true
}
},
"flow": "xtls-rprx-vision"
},
{
"tag": "GLOBAL",
"type": "selector",
"outbounds": [
"Server1",
"Server2",
"direct"
]
},
{
"tag": "direct",
"type": "direct"
}
],
"route": {
"rules": [
{
"action": "sniff",
"sniffer": [
"http",
"tls",
"quic",
"dns"
]
},
{
"inbound": "dns-in",
"action": "hijack-dns"
},
{
"ip_is_private": true,
"outbound": "direct"
},
{
"rule_set": "geosite-cn",
"outbound": "direct"
},
{
"rule_set": "geoip-cn",
"outbound": "direct"
}
],
"rule_set": [
{
"tag": "geosite-cn",
"type": "remote",
"format": "binary",
"url": "https://gh-proxy.com/https://raw.githubusercontent.com/MetaCubeX/meta-rules-dat/sing/geo/geosite/cn.srs",
"download_detour": "direct"
},
{
"tag": "geoip-cn",
"type": "remote",
"format": "binary",
"url": "https://cdn.jsdelivr.net/gh/Loyalsoldier/geoip@release/srs/cn.srs",
"download_detour": "direct"
}
],
"final": "GLOBAL",
"default_domain_resolver": {
"server": "public"
}
},
"inbounds": [
{
"tag": "dns-in",
"type": "direct",
"listen": "::",
"listen_port": 1053
},
{
"tag": "redirect-in",
"type": "redirect",
"listen": "::",
"listen_port": 7890
},
{
"tag": "tproxy-in",
"type": "tproxy",
"listen": "::",
"listen_port": 7891
},
{
"tag": "tun-in",
"type": "tun",
"interface_name": "momo",
"address": [
"172.31.0.1/30",
"fdfe:dcba:9876::1/126"
],
"auto_route": false,
"auto_redirect": false
}
],
"experimental": {
"cache_file": {
"enabled": true,
"path": "/etc/momo/run/cache.db",
"store_fakeip": true
},
"clash_api": {
"external_controller": "0.0.0.0:9095",
"external_ui": "/etc/momo/run/ui",
"external_ui_download_url": "https://gh-proxy.com/https://github.com/Zephyruso/zashboard/archive/refs/heads/gh-pages.zip",
"external_ui_download_detour": "direct",
"secret": "",
"default_mode": "rule"
}
},
"log": {
"disabled": false,
"level": "info",
"timestamp": true
}
}

View File

@@ -0,0 +1,204 @@
{
"dns": {
"servers": [
{
"tag": "local",
"type": "udp",
"server": "223.5.5.5"
},
{
"tag": "public",
"type": "https",
"server": "dns.alidns.com",
"domain_resolver": "local"
},
{
"tag": "foreign",
"type": "https",
"server": "8.8.8.8",
"detour": "Server1"
},
{
"tag": "fakeip",
"type": "fakeip",
"inet4_range": "198.18.0.0/15",
"inet6_range": "fc00::/18"
}
],
"rules": [
{
"rule_set": "geosite-cn",
"server": "public"
},
{
"query_type": [
"A",
"AAAA"
],
"server": "fakeip",
"rewrite_ttl": 1
}
],
"final": "foreign",
"strategy": "ipv4_only",
"independent_cache": true,
"reverse_mapping": true
},
"outbounds": [
{
"tag": "Server1",
"type": "vless",
"server": "xxx.xxx.xxx.xxx",
"server_port": 8443,
"uuid": "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx",
"tls": {
"enabled": true,
"server_name": "xxxxxxxxxxxx",
"insecure": false,
"reality": {
"enabled": true,
"public_key": "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx",
"short_id": "xxxxxxxxxxxx"
},
"utls": {
"enabled": true,
"fingerprint": "firefox"
}
},
"flow": "xtls-rprx-vision"
},
{
"tag": "Server2",
"type": "vless",
"server": "xxx.xxx.xxx.xxx",
"server_port": 8443,
"uuid": "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx",
"tls": {
"enabled": true,
"server_name": "xxxxxxxxxxxx",
"insecure": false,
"reality": {
"enabled": true,
"public_key": "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx",
"short_id": "xxxxxxxxxxxx"
},
"utls": {
"enabled": true
}
},
"flow": "xtls-rprx-vision"
},
{
"tag": "GLOBAL",
"type": "selector",
"outbounds": [
"Server1",
"Server2",
"direct"
]
},
{
"tag": "direct",
"type": "direct"
}
],
"route": {
"rules": [
{
"action": "sniff",
"sniffer": [
"http",
"tls",
"quic",
"dns"
]
},
{
"inbound": "dns-in",
"action": "hijack-dns"
},
{
"ip_is_private": true,
"outbound": "direct"
},
{
"rule_set": "geosite-cn",
"outbound": "direct"
},
{
"rule_set": "geoip-cn",
"outbound": "direct"
}
],
"rule_set": [
{
"tag": "geosite-cn",
"type": "remote",
"format": "binary",
"url": "https://gh-proxy.com/https://raw.githubusercontent.com/MetaCubeX/meta-rules-dat/sing/geo/geosite/cn.srs",
"download_detour": "direct"
},
{
"tag": "geoip-cn",
"type": "remote",
"format": "binary",
"url": "https://cdn.jsdelivr.net/gh/Loyalsoldier/geoip@release/srs/cn.srs",
"download_detour": "direct"
}
],
"final": "GLOBAL",
"default_domain_resolver": {
"server": "public"
}
},
"inbounds": [
{
"tag": "dns-in",
"type": "direct",
"listen": "0.0.0.0",
"listen_port": 1053
},
{
"tag": "redirect-in",
"type": "redirect",
"listen": "0.0.0.0",
"listen_port": 7890
},
{
"tag": "tproxy-in",
"type": "tproxy",
"listen": "0.0.0.0",
"listen_port": 7891
},
{
"tag": "tun-in",
"type": "tun",
"interface_name": "momo",
"address": [
"172.31.0.1/30"
],
"auto_route": false,
"auto_redirect": false
}
],
"experimental": {
"cache_file": {
"enabled": true,
"path": "/etc/momo/run/cache.db",
"store_fakeip": true
},
"clash_api": {
"external_controller": "0.0.0.0:9095",
"external_ui": "/etc/momo/run/ui",
"external_ui_download_url": "https://gh-proxy.com/https://github.com/Zephyruso/zashboard/archive/refs/heads/gh-pages.zip",
"external_ui_download_detour": "direct",
"secret": "",
"default_mode": "rule"
}
},
"log": {
"disabled": false,
"level": "info",
"timestamp": true
}
}

209
config/kernel/ipv4+6.json Normal file
View File

@@ -0,0 +1,209 @@
{
"dns": {
"servers": [
{
"tag": "local",
"type": "udp",
"server": "223.5.5.5"
},
{
"tag": "public",
"type": "https",
"server": "dns.alidns.com",
"domain_resolver": "local"
},
{
"tag": "foreign",
"type": "https",
"server": "8.8.8.8",
"detour": "Azure-JP"
},
{
"tag": "fakeip",
"type": "fakeip",
"inet4_range": "198.18.0.0/15",
"inet6_range": "fc00::/18"
}
],
"rules": [
{
"rule_set": "geosite-cn",
"server": "local"
},
{
"query_type": [
"A",
"AAAA"
],
"server": "fakeip",
"rewrite_ttl": 1
}
],
"final": "foreign",
"strategy": "prefer_ipv4",
"independent_cache": true,
"reverse_mapping": false
},
"outbounds": [
{
"tag": "Server1",
"type": "vless",
"server": "xxx.xxx.xxx.xxx",
"server_port": 8443,
"uuid": "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx",
"tls": {
"enabled": true,
"server_name": "xxxxxxxxxxxx",
"insecure": false,
"reality": {
"enabled": true,
"public_key": "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx",
"short_id": "xxxxxxxxxxxx"
},
"utls": {
"enabled": true,
"fingerprint": "firefox"
}
},
"flow": "xtls-rprx-vision"
},
{
"tag": "Server2",
"type": "vless",
"server": "xxx.xxx.xxx.xxx",
"server_port": 8443,
"uuid": "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx",
"tls": {
"enabled": true,
"server_name": "xxxxxxxxxxxx",
"insecure": false,
"reality": {
"enabled": true,
"public_key": "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx",
"short_id": "xxxxxxxxxxxx"
},
"utls": {
"enabled": true
}
},
"flow": "xtls-rprx-vision"
},
{
"tag": "GLOBAL",
"type": "selector",
"outbounds": [
"Server1",
"Server2",
"direct"
]
},
{
"tag": "direct",
"type": "direct"
}
],
"route": {
"rules": [
{
"inbound": "tun-in",
"port": 53,
"action": "hijack-dns"
},
{
"inbound": "dns-in",
"action": "hijack-dns"
},
{
"ip_is_private": true,
"outbound": "direct"
},
{
"rule_set": "geosite-cn",
"outbound": "direct"
},
{
"rule_set": "geoip-cn",
"outbound": "direct"
},
{
"action": "sniff",
"sniffer": [
"http",
"tls",
"quic",
"dns"
]
},
{
"outbound": "GLOBAL"
}
],
"rule_set": [
{
"tag": "geosite-cn",
"type": "remote",
"format": "binary",
"url": "https://gh-proxy.com/https://raw.githubusercontent.com/MetaCubeX/meta-rules-dat/sing/geo/geosite/cn.srs",
"download_detour": "direct"
},
{
"tag": "geoip-cn",
"type": "remote",
"format": "binary",
"url": "https://cdn.jsdelivr.net/gh/Loyalsoldier/geoip@release/srs/cn.srs",
"download_detour": "direct"
}
],
"final": "GLOBAL",
"auto_detect_interface": true,
"default_domain_resolver": {
"server": "public"
}
},
"inbounds": [
{
"tag": "dns-in",
"type": "direct",
"listen": "127.0.0.1",
"listen_port": 1053
},
{
"tag": "tun-in",
"type": "tun",
"interface_name": "stun",
"address": [
"172.19.0.1/30",
"fdfe:dcba:9876::1/126"
],
"mtu": 9000,
"auto_route": true,
"auto_redirect": true,
"strict_route": false
},
{
"type": "mixed",
"listen": "127.0.0.1",
"listen_port": 7890
}
],
"experimental": {
"cache_file": {
"enabled": true,
"path": "/var/lib/sing-box/cache.db",
"store_fakeip": true
},
"clash_api": {
"external_controller": "0.0.0.0:9191",
"external_ui": "/var/lib/sing-box/ui",
"external_ui_download_url": "https://gh-proxy.com/https://github.com/Zephyruso/zashboard/archive/refs/heads/gh-pages.zip",
"external_ui_download_detour": "direct",
"secret": "",
"default_mode": "rule"
}
},
"log": {
"disabled": false,
"level": "info",
"timestamp": true
}
}

208
config/kernel/ipv4only.json Normal file
View File

@@ -0,0 +1,208 @@
{
"dns": {
"servers": [
{
"tag": "local",
"type": "udp",
"server": "223.5.5.5"
},
{
"tag": "public",
"type": "https",
"server": "dns.alidns.com",
"domain_resolver": "local"
},
{
"tag": "foreign",
"type": "https",
"server": "8.8.8.8",
"detour": "Azure-JP"
},
{
"tag": "fakeip",
"type": "fakeip",
"inet4_range": "198.18.0.0/15",
"inet6_range": "fc00::/18"
}
],
"rules": [
{
"rule_set": "geosite-cn",
"server": "local"
},
{
"query_type": [
"A",
"AAAA"
],
"server": "fakeip",
"rewrite_ttl": 1
}
],
"final": "foreign",
"strategy": "ipv4_only",
"independent_cache": true,
"reverse_mapping": false
},
"outbounds": [
{
"tag": "Server1",
"type": "vless",
"server": "xxx.xxx.xxx.xxx",
"server_port": 8443,
"uuid": "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx",
"tls": {
"enabled": true,
"server_name": "xxxxxxxxxxxx",
"insecure": false,
"reality": {
"enabled": true,
"public_key": "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx",
"short_id": "xxxxxxxxxxxx"
},
"utls": {
"enabled": true,
"fingerprint": "firefox"
}
},
"flow": "xtls-rprx-vision"
},
{
"tag": "Server2",
"type": "vless",
"server": "xxx.xxx.xxx.xxx",
"server_port": 8443,
"uuid": "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx",
"tls": {
"enabled": true,
"server_name": "xxxxxxxxxxxx",
"insecure": false,
"reality": {
"enabled": true,
"public_key": "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx",
"short_id": "xxxxxxxxxxxx"
},
"utls": {
"enabled": true
}
},
"flow": "xtls-rprx-vision"
},
{
"tag": "GLOBAL",
"type": "selector",
"outbounds": [
"Server1",
"Server2",
"direct"
]
},
{
"tag": "direct",
"type": "direct"
}
],
"route": {
"rules": [
{
"inbound": "tun-in",
"port": 53,
"action": "hijack-dns"
},
{
"inbound": "dns-in",
"action": "hijack-dns"
},
{
"ip_is_private": true,
"outbound": "direct"
},
{
"rule_set": "geosite-cn",
"outbound": "direct"
},
{
"rule_set": "geoip-cn",
"outbound": "direct"
},
{
"action": "sniff",
"sniffer": [
"http",
"tls",
"quic",
"dns"
]
},
{
"outbound": "GLOBAL"
}
],
"rule_set": [
{
"tag": "geosite-cn",
"type": "remote",
"format": "binary",
"url": "https://gh-proxy.com/https://raw.githubusercontent.com/MetaCubeX/meta-rules-dat/sing/geo/geosite/cn.srs",
"download_detour": "direct"
},
{
"tag": "geoip-cn",
"type": "remote",
"format": "binary",
"url": "https://cdn.jsdelivr.net/gh/Loyalsoldier/geoip@release/srs/cn.srs",
"download_detour": "direct"
}
],
"final": "GLOBAL",
"auto_detect_interface": true,
"default_domain_resolver": {
"server": "public"
}
},
"inbounds": [
{
"tag": "dns-in",
"type": "direct",
"listen": "127.0.0.1",
"listen_port": 1053
},
{
"tag": "tun-in",
"type": "tun",
"interface_name": "stun",
"address": [
"172.19.0.1/30"
],
"mtu": 9000,
"auto_route": true,
"auto_redirect": true,
"strict_route": false
},
{
"type": "mixed",
"listen": "127.0.0.1",
"listen_port": 7890
}
],
"experimental": {
"cache_file": {
"enabled": true,
"path": "/var/lib/sing-box/cache.db",
"store_fakeip": true
},
"clash_api": {
"external_controller": "0.0.0.0:9191",
"external_ui": "/var/lib/sing-box/ui",
"external_ui_download_url": "https://gh-proxy.com/https://github.com/Zephyruso/zashboard/archive/refs/heads/gh-pages.zip",
"external_ui_download_detour": "direct",
"secret": "",
"default_mode": "rule"
}
},
"log": {
"disabled": false,
"level": "info",
"timestamp": true
}
}

Binary file not shown.

Binary file not shown.

Binary file not shown.

File diff suppressed because it is too large Load Diff

BIN
run.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 189 KiB

View File

@@ -1,7 +1,7 @@
#!/usr/bin/env bash
# install_singbox.sh
# 版本号
SCRIPT_VERSION="1.12.10-alapa"
SCRIPT_VERSION="1.12.12"
set -euo pipefail
# 颜色定义
@@ -24,33 +24,88 @@ CONFIG_DIR=/etc/sing-box
STATE_FILE="$CONFIG_DIR/state.env"
BIN_NAME=sing-box
# 检测网络类型
detect_network_type() {
local has_ipv4=false
local has_ipv6=false
# 检测IPv4
if ping -4 -c1 -W2 8.8.8.8 &>/dev/null || curl -4 -s --connect-timeout 3 https://api.ipify.org &>/dev/null; then
has_ipv4=true
fi
# 检测IPv6
if ping -6 -c1 -W2 2001:4860:4860::8888 &>/dev/null || curl -6 -s --connect-timeout 3 https://api64.ipify.org &>/dev/null; then
has_ipv6=true
fi
if $has_ipv4 && $has_ipv6; then
echo "dual"
elif $has_ipv6; then
echo "ipv6"
elif $has_ipv4; then
echo "ipv4"
else
echo "none"
fi
}
# 获取服务器IP地址
get_server_ip() {
local network_type=$(detect_network_type)
local ip=""
case "$network_type" in
"ipv6")
# 纯IPv6环境
ip=$(curl -6 -s --connect-timeout 5 https://api64.ipify.org 2>/dev/null || \
curl -6 -s --connect-timeout 5 https://ifconfig.co 2>/dev/null || \
ip -6 addr show scope global | grep inet6 | head -n1 | awk '{print $2}' | cut -d'/' -f1)
;;
"dual"|"ipv4")
# 双栈或IPv4环境
ip=$(curl -4 -s --connect-timeout 5 https://api.ipify.org 2>/dev/null || \
curl -4 -s --connect-timeout 5 https://ifconfig.me 2>/dev/null || \
ip -4 addr show scope global | grep inet | head -n1 | awk '{print $2}' | cut -d'/' -f1)
;;
*)
# 无法检测到网络
ip=$(ip addr show scope global | grep -oP '(?<=inet6?\s)\S+' | head -n1 | cut -d'/' -f1)
;;
esac
echo "$ip"
}
# 检查本地与远程版本,并提示
check_update() {
if command -v curl &>/dev/null && command -v grep &>/dev/null; then
LOCAL_VER=$($BIN_NAME version 2>/dev/null | head -n1 | awk '{print $NF}') || LOCAL_VER="未安装"
LATEST_VER=$(curl -s https://api.github.com/repos/SagerNet/sing-box/releases/latest |
local network_type=$(detect_network_type)
local curl_opts=""
[[ "$network_type" == "ipv6" ]] && curl_opts="-6"
LATEST_VER=$(curl $curl_opts -s --connect-timeout 10 https://api.github.com/repos/SagerNet/sing-box/releases/latest 2>/dev/null |
grep '"tag_name"' | head -n1 | cut -d '"' -f4 | sed 's/^v//') || LATEST_VER="未知"
if [[ "$LOCAL_VER" != "$LATEST_VER" ]]; then
printf "${YELLOW}检测到新版本:${LATEST_VER},当前版本:${LOCAL_VER}。请选择 6) 升级 Sing-box 二进制。${NC}\n"
if [[ "$LOCAL_VER" != "$LATEST_VER" && "$LATEST_VER" != "未知" ]]; then
printf "${YELLOW}检测到新版本:${LATEST_VER},当前版本:${LOCAL_VER}。请选择 8) 升级 Sing-box 二进制。${NC}\n"
fi
fi
}
# 安装 Sing-box 并生成配置
install_singbox() {
printf "${CYAN}===== 安装 Sing-box 并生成配置 =====${NC}\n"
printf "${YELLOW}请输入用户名称 (name 字段,例如 AK-JP-100G)${NC}"
read -r NAME
[[ -z "$NAME" ]] && {
printf "${RED}名称不能为空,退出。${NC}\n" >&2
exit 1
}
[[ -z "$NAME" ]] && { printf "${RED}名称不能为空,退出。${NC}\n" >&2; exit 1; }
printf "${YELLOW}请输入 SNI 域名 (默认: s0.awsstatic.com)${NC}"
read -r SNI
SNI=${SNI:-s0.awsstatic.com}
read -rp "请输入监听端口 (默认: 443) " PORT
PORT=${PORT:-443} # 如果用户没输入,则默认 443
PORT=${PORT:-443}
update_singbox
hash -r
@@ -68,11 +123,27 @@ install_singbox() {
PUB_KEY=$(echo "$KEY_OUTPUT" | awk -F': ' '/PublicKey/ {print $2}')
SHORT_ID=$(openssl rand -hex 8)
FP="firefox"
SERVER_IP=$(curl -4 -s https://api.ipify.org)
SERVER_IP=$(get_server_ip)
SPX="/"
mkdir -p "$CONFIG_DIR"
# 根据网络类型选择 DNS
NET_TYPE=$(detect_network_type)
if [[ "$NET_TYPE" == "ipv6" ]]; then
DNS_SERVER1="2606:4700:4700::1111" # Cloudflare IPv6
DNS_SERVER2="2620:fe::fe" # Quad9 IPv6
DNS_STRATEGY="prefer_ipv6"
elif [[ "$NET_TYPE" == "dual" || "$NET_TYPE" == "ipv4" ]]; then
DNS_SERVER1="8.8.8.8"
DNS_SERVER2="1.1.1.1"
DNS_STRATEGY="prefer_ipv4"
else
DNS_SERVER1="8.8.8.8"
DNS_SERVER2="1.1.1.1"
DNS_STRATEGY="prefer_ipv4"
fi
cat >"$CONFIG_DIR/config.json" <<EOF
{
"log": {
@@ -83,14 +154,18 @@ install_singbox() {
"servers": [
{
"type": "tls",
"server": "8.8.8.8",
"server": "$DNS_SERVER1",
"server_port": 853,
"tls": {
"min_version": "1.2"
}
"tls": { "min_version": "1.2" }
},
{
"type": "tls",
"server": "$DNS_SERVER2",
"server_port": 853,
"tls": { "min_version": "1.2" }
}
],
"strategy": "prefer_ipv4"
"strategy": "$DNS_STRATEGY"
},
"inbounds": [
{
@@ -122,17 +197,11 @@ install_singbox() {
],
"route": {
"rules": [
{
"type": "default",
"outbound": "direct"
}
{ "type": "default", "outbound": "direct" }
]
},
"outbounds": [
{
"type": "direct",
"tag": "direct"
}
{ "type": "direct", "tag": "direct" }
]
}
EOF
@@ -151,10 +220,9 @@ EOF
systemctl enable sing-box.service
systemctl restart sing-box.service
printf "${GREEN}安装并启动完成。${NC}\n"
printf "${GREEN}安装并启动完成DNS 已根据网络类型自动配置${NC}\n"
}
# 查看服务状态
status_singbox() {
printf "${CYAN}===== Sing-box 服务状态 =====${NC}\n"
@@ -192,8 +260,8 @@ show_link() {
PUB_KEY=$(grep -oP '"public_key"\s*:\s*"\K[^"]+' "$CONFIG_DIR/config.json")
SHORT_ID=$(grep -oP '"short_id"\s*:\s*"\K[^"]+' "$CONFIG_DIR/config.json")
FP="firefox"
SERVER_IP=$(curl -s https://ifconfig.me)
PORT=$(grep -oP '"listen_port"\s*:\s*"\K[^"]+' "$CONFIG_DIR/config.json")
SERVER_IP=$(get_server_ip)
PORT=$(grep -oP '"listen_port"\s*:\s*\K[^,}]+' "$CONFIG_DIR/config.json")
SPX="/"
# 保存新的 state.env
@@ -217,7 +285,13 @@ EOF
# 读取 state.env
source "$STATE_FILE"
LINK="vless://${UUID}@${SERVER_IP}:${PORT}?security=reality&sni=${SNI}&fp=${FP}&pbk=${PUB_KEY}&sid=${SHORT_ID}&spx=${SPX}&type=tcp&flow=xtls-rprx-vision&encryption=none#${NAME}"
local formatted_ip="$SERVER_IP"
if [[ "$SERVER_IP" =~ ":" ]]; then
formatted_ip="[$SERVER_IP]"
fi
LINK="vless://${UUID}@${formatted_ip}:${PORT}?security=reality&sni=${SNI}&fp=${FP}&pbk=${PUB_KEY}&sid=${SHORT_ID}&spx=${SPX}&type=tcp&flow=xtls-rprx-vision&encryption=none#${NAME}"
printf "${GREEN}%s${NC}\n\n" "$LINK"
@@ -266,25 +340,79 @@ reinstall_singbox() {
# 升级/安装 Sing-box 二进制
update_singbox() {
printf "${CYAN}===== 升级/安装 Sing-box 二进制 =====${NC}\n"
if command -v apt-get &>/dev/null; then
bash <(curl -fsSL https://sing-box.app/deb-install.sh)
elif command -v dnf &>/dev/null || command -v yum &>/dev/null; then
bash <(curl -fsSL https://sing-box.app/rpm-install.sh)
elif command -v pacman &>/dev/null; then
bash <(curl -fsSL https://sing-box.app/arch-install.sh)
else
printf "${RED}无法识别发行版,请手动升级 Sing-box 二进制${NC}\n" >&2
return 1
set -e -o pipefail
# 检测体系架构
ARCH_RAW=$(uname -m)
case "${ARCH_RAW}" in
'x86_64') ARCH='amd64';;
'x86' | 'i686' | 'i386') ARCH='386';;
'aarch64' | 'arm64') ARCH='arm64';;
'armv7l') ARCH='armv7';;
's390x') ARCH='s390x';;
*) echo "❌ 不支持的架构: ${ARCH_RAW}"; return 1;;
esac
# 检测网络类型
local network_type=$(detect_network_type)
echo "🌐 当前网络模式: $network_type"
local curl_opts=""
case "$network_type" in
"ipv6")
curl_opts="-6"
echo "📡 使用 IPv6 连接"
;;
"dual")
echo "📡 双栈网络,优先使用 IPv4"
;;
"ipv4")
curl_opts="-4"
echo "📡 使用 IPv4 连接"
;;
"none")
echo "⚠️ 无法检测到网络连接,尝试默认方式"
;;
esac
# 获取最新版本号
VERSION=$(curl $curl_opts -fsSL --connect-timeout 15 https://api.github.com/repos/SagerNet/sing-box/releases/latest 2>/dev/null |
grep '"tag_name"' | head -n1 | cut -d '"' -f4 | sed 's/^v//') || VERSION=""
if [[ -z "$VERSION" ]]; then
echo "⚠️ 获取版本失败,尝试备用源..."
VERSION=$(curl $curl_opts -fsSL --connect-timeout 15 https://fastly.jsdelivr.net/gh/SagerNet/sing-box@latest/version.txt 2>/dev/null || echo "")
fi
hash -r
NEW_VER=$($BIN_NAME version | head -n1 | awk '{print $NF}')
printf "${GREEN}Sing-box 已升级到版本:%s${NC}\n" "$NEW_VER"
printf "${CYAN}重启服务...${NC}\n"
[[ -z "$VERSION" ]] && { echo "❌ 无法获取最新版本号"; return 1; }
echo "🔖 最新版本v${VERSION}"
PKG_URL="https://github.com/SagerNet/sing-box/releases/download/v${VERSION}/sing-box_${VERSION}_linux_${ARCH}.deb"
echo "⬇️ 正在下载 ${PKG_URL}"
curl $curl_opts -fL --connect-timeout 30 -o /tmp/sing-box.deb "$PKG_URL" || {
echo "❌ 下载失败,请检查网络。"
return 1
}
sudo dpkg -i /tmp/sing-box.deb || {
echo "⚠️ dpkg 安装失败,尝试修复依赖..."
sudo apt-get install -f -y
sudo dpkg -i /tmp/sing-box.deb
}
rm -f /tmp/sing-box.deb
NEW_VER=$($BIN_NAME version 2>/dev/null | head -n1 | awk '{print $NF}')
echo "✅ Sing-box 已升级到版本:$NEW_VER"
echo "🔁 正在重启服务..."
if systemctl restart sing-box.service; then
systemctl daemon-reload
printf "${GREEN}服务已重启。${NC}\n"
echo "✅ 服务已重启。"
else
printf "${YELLOW}服务重启失败,请手动检查。${NC}\n"
echo "⚠️ 服务重启失败,请手动检查。"
fi
}
@@ -306,11 +434,9 @@ change_sni() {
return
}
# 替换 config.json 中的 SNI 字段
sed -i "s/\"server_name\":\s*\"[^\"]*\"/\"server_name\": \"$NEW_SNI\"/" "$CONFIG_DIR/config.json"
sed -i "s/\"server\":\s*\"[^\"]*\"/\"server\": \"$NEW_SNI\"/" "$CONFIG_DIR/config.json"
sed -i -E '/"reality": *\{/,/}/ s/"server_name": *"[^"]*"/"server_name": "'"$NEW_SNI"'"/' "$CONFIG_DIR/config.json"
sed -i -E '/"handshake": *\{/,/}/ s/"server": *"[^"]*"/"server": "'"$NEW_SNI"'"/' "$CONFIG_DIR/config.json"
# 替换 state.env 中的 SNI
sed -i "s/^SNI=.*/SNI=\"$NEW_SNI\"/" "$STATE_FILE"
systemctl restart sing-box.service &&
@@ -363,7 +489,13 @@ update_self() {
if command -v curl &>/dev/null; then
local url="https://raw.githubusercontent.com/Dichgrem/singbox-example/refs/heads/main/script/singbox.sh"
echo "$url 下载最新脚本..."
if curl -fsSL "$url" -o "$tmp_file"; then
# 根据网络类型选择curl参数
local network_type=$(detect_network_type)
local curl_opts=""
[[ "$network_type" == "ipv6" ]] && curl_opts="-6"
if curl $curl_opts -fsSL --connect-timeout 15 "$url" -o "$tmp_file"; then
echo "下载成功,准备替换本地脚本..."
chmod +x "$tmp_file"
mv "$tmp_file" "$script_path"
@@ -383,6 +515,10 @@ update_self() {
check_update
printf "${BLUE}当前脚本版本:${SCRIPT_VERSION}${NC}\n"
# 显示网络类型
NETWORK_TYPE=$(detect_network_type)
printf "${BLUE}检测到网络类型:${NETWORK_TYPE}${NC}\n"
# 显示 Sing-box 版本
if command -v sing-box >/dev/null 2>&1; then
SINGBOX_VERSION=$(sing-box version 2>/dev/null | head -n 1)