スクリプトのインストール#
VMESS/VLESS/TROJAN/SHADOWSOCKS
- 自用スクリプト。このスクリプトはトンネルまたは IPLC/IEPL の中継のために作成されており、偽装はありません。
- Trojan の tls は、カスタム証明書パスを指定しない限り、ローカルで生成された無効な証明書です。
- Trojan の非カスタム証明書パスでは、必ず次を有効にしてください: skip-cert-verify: true
ワンクリックスクリプト#
bash <(curl -fsSL https://raw.githubusercontent.com/Slotheve/SingBox/main/singbox.sh)
Docker のインストール#
設定例
{
"log": {
"level": "trace",
"output": "/data/sing-box.log",
"timestamp": true
},
"inbounds": [
{
"type": "shadowsocks",
"listen": "::",
"listen_port": 25550,
"method": "chacha20-ietf-poly1305",
"password": "IloveNekopara"
}
],
"outbounds": [
{
"type": "direct",
"tag": "direct"
},
{
"type": "block",
"tag": "block"
},
{
"type": "dns",
"tag": "dns-out"
}
],
"route": {
"geoip": {
"path": "/data/geoip.db",
"download_url": "https://github.com/SagerNet/sing-geoip/releases/latest/download/geoip.db",
"download_detour": "direct"
},
"geosite": {
"path": "/data/geosite.db",
"download_url": "https://github.com/SagerNet/sing-geosite/releases/latest/download/geosite.db",
"download_detour": "direct"
},
"rules": [
{
"protocol": "dns",
"outbound": "dns-out"
}
],
"final": "direct",
"auto_detect_interface": true
}
}
1. ファイルディレクトリ#
サーバーに以下のディレクトリ構造を構築する必要があります:
sing-box
├── data
├── config.json
├── entry.sh
└── tls
└── docker-compose.yml
ここで、data/config.json
はsing-box
の設定ファイルで、すべてのノードの設定情報が含まれています。
data/entry.sh
はコンテナ起動スクリプトです。
tls フォルダは tls 証明書を保存するために使用され、sing-box
は自動的に証明書を発行できます。既存の証明書を使用することもできます。自動発行の場合は、空のフォルダで構いません。実行後にこのディレクトリに証明書ファイルが生成されます。既存の証明書を使用する場合は、証明書を現在のフォルダにコピーしてください。
2. docker compose#
docker-compose.yml
の参考内容は以下の通りです:
version: '3'
services:
sing-box:
image: ghcr.io/sagernet/sing-box
container_name: sing-box
restart: unless-stopped
network_mode: "host"
# ports:
# - 80:80
# - 443:443
# - 8090:8090
# - 10080-10099:10080-10099/udp
volumes:
- ./data:/data
- ./tls:/tls
cap_add:
- NET_ADMIN
devices:
- /dev/net/tun
entrypoint: ["/bin/bash", "/data/entry.sh"]
ここで、ネットワークモードはnetwork_mode: "host"
を使用しており、ホストのネットワーク環境を直接使用しています。ホストのファイアウォールを無効にする必要があります。コマンドは以下の通りです:
# CentOS:
systemctl disable firewalld
# Debian/Ubuntu:
sudo ufw disable
hostモード
に問題がある場合は、指定されたポートモードに切り替えることもできます(network_mode
のコメントを外し、下のポートのコメントを削除します)。
3. entry.sh#
参考内容は以下の通りです:
#!/bin/bash
set -e
configFilePath="/data/config.json"
logFilePath="/data/sing-box.json"
echo "entry"
sing-box version
# https://sing-box.sagernet.org/configuration/
echo -e "\nconfig:"
sing-box check -c $configFilePath || cat $configFilePath
sing-box format -c /data/config.json -w
cat $configFilePath
echo -e "\nstarting"
sing-box run -c $configFilePath
tail -f $logFilePath
sing-box
のバージョンを出力し、設定ファイルをチェックしてフォーマットし、sing-box
を起動し、ログを追跡します。
4. config.json#
最も重要な設定ファイル、参考内容は以下の通りです:
{
"log": {
"level": "trace",
"output": "/data/sing-box.log",
"timestamp": true
},
"inbounds": [
{
"type": "hysteria",
"tag": "hysteria-in",
"listen": "0.0.0.0",
"listen_port": 10080,
"domain_strategy": "ipv4_only",
"up_mbps": 50,
"down_mbps": 50,
"obfs": "nicetofuckyou",
"users": [
{
"name": "<proxy_name>",
"auth_str": "<proxy_pwd>"
}
],
"tls": {
"enabled": true,
"server_name": "<domain>",
"acme": {
"domain": "<domain>",
"data_directory": "/tls",
"default_server_name": "<domain>",
"email": "<email>"
}
}
},
{
"type": "naive",
"tag": "naive-in",
"listen": "0.0.0.0",
"listen_port": 8090,
"domain_strategy": "ipv4_only",
"users": [
{
"username": "<proxy_name>",
"password": "<proxy_pwd>"
}
],
"network": "tcp",
"tls": {
"enabled": true,
"server_name": "<domain>",
"acme": {
"domain": "<domain>",
"data_directory": "/tls",
"default_server_name": "<domain>",
"email": "<email>"
}
}
}
],
"outbounds": [
{
"type": "direct",
"tag": "direct"
},
{
"type": "block",
"tag": "block"
},
{
"type": "dns",
"tag": "dns-out"
}
],
"route": {
"geoip": {
"path": "/data/geoip.db",
"download_url": "https://github.com/SagerNet/sing-geoip/releases/latest/download/geoip.db",
"download_detour": "direct"
},
"geosite": {
"path": "/data/geosite.db",
"download_url": "https://github.com/SagerNet/sing-geosite/releases/latest/download/geosite.db",
"download_detour": "direct"
},
"rules": [
{
"protocol": "dns",
"outbound": "dns-out"
}
],
"final": "direct",
"auto_detect_interface": true
}
}
ここで、いくつかの置き換えが必要な箇所があります:
<proxy_name>
はプロキシのユーザー名に置き換えてください。自分で決めてください(例:Ray
)。<proxy_pwd>
はプロキシのパスワードに置き換えてください。自分で決めてください(例:1234@qwer
)。<domain>
はドメインに置き換えてください。<email>
はメールアドレスに置き換えてください。obfs
はhysteria
の混淆文字列で、自分でカスタマイズできます。
このようにして、1 つのUDP ベースの 10080 ポートのhysteria
ノードと、1 つのTCP ベースの 8090 ポートのnaive
ノードが設定されます。
クラウド上にセキュリティポリシーがある場合は、これらの 2 つのポートが開放されていることを確認してください。
証明書については、tls ディレクトリに既存の証明書がない場合、自動的に発行されます。
その他の設定については、公式ドキュメントを参照してください。
5. 実行#
docker-compose.yml
と同じディレクトリで、次を実行します:
docker compose up -d
コンテナの起動を待ちます。
すべてが正常であれば、起動成功です。自分のクライアントを使って接続できます。(これだけ簡単です)
その他の参考コマンド:
# 現在実行中のコンテナを確認
docker ps
# コンテナの起動ログを確認
docker logs sing-box
# コンテナの実行ログを追跡(Ctrl Cで追跡を終了)
docker logs -f sing-box
# コンテナに入る
docker exec -it sing-box bash
完全手動インストール#
wget https://github.com/SagerNet/sing-box/releases/download/v1.7.2/sing-box-1.7.2-linux-amd64.tar.gz
tar -zxvf sing-box-1.7.2-linux-amd64.tar.gz
Reality#
root@xiaolv:~/singbox# ./sing-box generate reality-keypair
PrivateKey: GPqJLU6HiFGE4EnuRoj7PUR3Eb2yr0vVycZVwaoQXng
PublicKey: cE6e-BbY2zu-8TMEb6sWSh8PTemcd-hqVfaUFtAoAzI
{
"inbounds": [
{
"type": "vless",
"tag": "vless-in",
"listen": "::",
"listen_port": 25001,
"sniff": true,
"sniff_override_destination": true,
"users": [
{
"uuid": "3e8e5eae-6720-4668-8187-052840b385a7",
"flow": "xtls-rprx-vision"
}
],
"tls": {
"enabled": true,
"server_name": "oceanhero.today",
"reality": {
"enabled": true,
"handshake": {
"server": "oceanhero.today",
"server_port": 443
},
"private_key": "GPqJLU6HiFGE4EnuRoj7PUR3Eb2yr0vVycZVwaoQXng",
"short_id": [
"8535dfc6b2e73c78"
]
}
}
}
],
"outbounds": [
{
"type": "direct"
}
]
}
Config
{
"inbounds": [
{
"type": "shadowsocks",
"listen": "::",
"listen_port": 25565,
"method": "2022-blake3-aes-128-gcm",
"password": "LZ/4gLsyAbJQCWdT6iu1aQ==", // 実行 sing-box generate rand 16 --base64 生成
"multiplex": {
"enabled": true
}
}
],
"outbounds": [
{
"type": "direct"
}
]
}
{
"inbounds": [
{
"type": "shadowsocks",
"listen": "::",
"listen_port": 25565,
"method": "chacha20-ietf-poly1305",
"password": "LZ/4gLsyAbJQCWdT6iu1aQ==", // 実行 sing-box generate rand 16 --base64 生成
"multiplex": {
"enabled": true
}
}
],
"outbounds": [
{
"type": "direct"
}
]
}
システムサービス#
vim /etc/systemd/system/singbox.service
[Unit]
Description=singbox
After=network.target
[Service]
ExecStart=/root/singbox/sing-box run -C /root/singbox
Restart=always
User=root
[Install]
WantedBy=multi-user.target
分流ルールの例#
{
"inbounds": [
{
"type": "shadowsocks",
"listen": "::",
"listen_port": 2023,
"method": "chacha20-ietf-poly1305",
"password": "LZ/4gLsyAbJQCWdT6iu1aQ==",
"multiplex": {
"enabled": true
}
}
],
"outbounds": [
{
"type": "direct",
"tag": "direct"
},
{
"type": "socks",
"tag": "hosthijack",
"server": "74.48.100.149",
"server_port": 10800,
"version": "5",
"username": "neko",
"password": "Vzkjs&Cm4@#TT5"
},
{
"type": "block",
"tag": "block"
},
{
"type": "dns",
"tag": "dns-out"
}
],
"route": {
"geoip": {
"download_url": "https://github.com/soffchen/sing-geoip/releases/latest/download/geoip.db",
"download_detour": "proxy"
},
"geosite": {
"download_url": "https://github.com/soffchen/sing-geosite/releases/latest/download/geosite.db",
"download_detour": "proxy"
},
"rules": [
{
"protocol": "dns",
"outbound": "dns-out"
},
{
"protocol": [
"quic"
],
"outbound": "block"
},
{
"domain": [
"ip.sb",
"ai.com",
"claude.ai",
"geosite:openai",
"cdn.openai.com",
"chat.openai.com",
"pay.openai.com",
"challenges.cloudflare.com",
"auth0.openai.com",
"platform.openai.com",
"invoice.stripe.com",
"stripe.com"
],
"outbound": "hosthijack"
}
],
"auto_detect_interface": true
}
}