Skip to content

Commit

Permalink
add sniff=dns feature
Browse files Browse the repository at this point in the history
  • Loading branch information
kkkgo committed Aug 5, 2023
1 parent 9221b56 commit 2580f16
Show file tree
Hide file tree
Showing 3 changed files with 108 additions and 1 deletion.
8 changes: 8 additions & 0 deletions FILES/usr/bin/ppg.sh
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,14 @@ load_clash() {
if ps | grep -v "grep" | grep "/etc/config/v2ray"; then
log "[OK] SNIFF OK." succ
else
if [ -z "$dns_ip" ]; then
dns_ip="1.0.0.1"
fi
if [ -z "$dns_port" ]; then
dns_port="53"
fi
sed "s/{dns_ip}/$dns_ip" /etc/config/v2ray/sniff.json >/tmp/sniff.json
sed -i "s/{dns_port}/$dns_port" /tmp/sniff.json
/usr/bin/v2ray run -c /etc/config/v2ray/sniff.json >/dev/tty0 2>&1 &
fi
fi
Expand Down
8 changes: 7 additions & 1 deletion ReadMe.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ PaoPao GateWay是一个体积小巧、稳定强大的FakeIP网关,核心由cla
网卡|1
光驱|1

*注意:如果节点数量很多(比如200+)或者你的配置文件比较复杂的话,建议适当增加内存和CPU核心数*
*注意:如果节点数量很多或者连接数很多或者你的配置文件比较复杂的话,建议适当增加内存和CPU核心数*

#### 方式一:使用docker内嵌配置
你可以使用Docker一键定制ISO镜像,其中包括为ISO**配置静态IP**、替换Clash核心、替换Country.mmdb、内嵌ppgw.ini等功能,**详情见使用Docker定制ISO镜像一节**
Expand Down Expand Up @@ -196,6 +196,11 @@ docker run --rm -v .:/data sliamb/ppgwiso
docker pull sliamb/ppgwiso
docker run --rm -e SNIFF=yes -v .:/data sliamb/ppgwiso
```
此外,有时候节点远程解析的DNS存在问题或者存在审计,而又没有节点服务器的控制权,出于避免DNS请求泄漏到节点或者节点服务器DNS不正常等场景,如果你想在嗅探的基础上,使用本地可信任DNS(ppgw.ini中所配置的)来解析所有请求来代替远程解析,可以使用`SNIFF=dns`
```shell
docker pull sliamb/ppgwiso
docker run --rm -e SNIFF=dns -v .:/data sliamb/ppgwiso
```
## 与DNS服务器配合完成分流
PaoPao GateWay启动后会监听53端口作为FAKEIP的DNS服务器,所有域名的查询到达的话这里都会解析成`fake_cidr`内的IP。当你在主路由添加`fake_cidr`段到PaoPao GateWay的静态路由后,你只需要把需要走网关的域名解析转发到PaoPao GateWay的53端口即可,能实现这个功能的DNS软件很多,比如有些系统自带的dnsmasq就可以指定某个域名使用某个DNS服务器。
配合[PaoPaoDNS](https://github.com/kkkgo/PaoPaoDNS)`CUSTOM_FORWARD`功能就可以完成简单精巧的分流,以下是一个简单的非CN IP的域名转发到PaoPao GateWay的docker compose配置:
Expand Down Expand Up @@ -235,6 +240,7 @@ services:
- "7889:7889/tcp"
```
需要注意的是,一小部分应用不走域名而是IP直连,比如某些聊天软件应用(比如[tg](https://core.telegram.org/resources/cidr.txt)),你只需要网上搜索一下对应的IP段,添加少量对应的的静态路由即可。
***如果配合`PaoPaoDNS`使用,强烈建议开启`PaoPaoDNS`的`USE_MARK_DATA`功能,提升分流精准度。***

## 构建说明
`PaoPao GateWay`iso镜像由Github Actions自动构建仓库代码构建推送,你可以在[Actions](https://github.com/kkkgo/PaoPaoGateWay/actions)查看构建日志并对比下载的镜像sha256值。
Expand Down
93 changes: 93 additions & 0 deletions remakeiso.sh
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,90 @@ json='{
}
}'

dnsjson='{
"log": {
"loglevel": "error"
},
"dns": {
"servers": [
{
"address": "{dns_ip}",
"port": {dns_port}
}
]
},
"inbounds": [
{
"port": 1081,
"protocol": "dokodemo-door",
"address": "127.0.0.1",
"settings": {
"network": "tcp,udp",
"followRedirect": true
},
"streamSettings": {
"sockopt": {
"tproxy": "tproxy"
}
},
"sniffing": {
"enabled": true,
"destOverride": [
"http",
"tls",
"quic"
],
"metadataOnly": false
}
}
],
"outbounds": [
{
"protocol": "freedom",
"settings": {
"domainStrategy": "UseIPv4"
},
"proxySettings": {
"tag": "proxy"
},
"tag": "free"
},
{
"protocol": "socks",
"tag": "proxy",
"settings": {
"servers": [
{
"address": "127.0.0.1",
"port": 1080
}
]
}
},
{
"protocol": "blackhole",
"tag": "blocked"
}
],
"routing": {
"rules": [
{
"type": "field",
"outboundTag": "blocked",
"network": "udp",
"port": 443
},
{
"type": "field",
"outboundTag": "blocked",
"protocol": [
"bittorrent"
]
}
]
}
}'

echo Patching new iso ...
7z x -p"$sha" -o"/tmp/" /root.7z >/dev/null
root=/tmp/remakeroot
Expand All @@ -87,6 +171,15 @@ if [ "$SNIFF" = "yes" ]; then
cp /v2ray $root"/usr/bin/"
fi

if [ "$SNIFF" = "dns" ]; then
echo Patching sniff with dns...
mkdir -p $root"/etc/config/v2ray"
echo "$dnsjson" >$root"/etc/config/v2ray/sniff.json"
sed -i 's/1082/1081/g' $root"/usr/bin/nft.sh"
sed -i 's/1082/1081/g' $root"/usr/bin/nft_tcp.sh"
cp /v2ray $root"/usr/bin/"
fi

if [ -f /data/clash ]; then
ls -lah /data/clash
echo Patching clash...
Expand Down

0 comments on commit 2580f16

Please sign in to comment.