# Clash + AdGuard

### 准备配置文件

```bash
echo "net.ipv4.ip_forward = 1" >> /etc/sysctl.conf
sysctl -p

mkdir -p /usr/local/clash
cd /usr/local/clash
wget https://feedneo.com/files/xHaeRNxG5f/clash.yml

mkdir -p /usr/local/AdGuard/conf
mkdir -p /usr/local/AdGuard/work
```

#### clash-premium.yml

<pre><code>cat > /usr/local/clash/clash-premium.yml &#x3C;&#x3C; EOF
mixed-port: 7890

allow-lan: true

mode: Rule

log-level: info

external-controller: 0.0.0.0:9090
secret: 'Will_D'

experimental:
  sniff-tls-sni: true

tun:
  enable: true
  stack: system
  dns-hijack:
    - 8.8.8.8:53
    - tcp://8.8.8.8:53
    - any:53
    - tcp://any:53
  auto-route: true
  auto-detect-interface: true
  
dns:
  enable: true
  listen: 0.0.0.0:553
  default-nameserver:
    # 192.168.1.2为本案例中AdGuard自建的DNS，可以按需修改
    - 192.168.1.2
    - 119.29.29.29
    - 223.5.5.5
  fake-ip-range: 198.18.0.1/16 # Fake IP addresses pool CIDR
  fake-ip-filter:
    - '*.lan'
    - localhost.ptlogin2.qq.com
  nameserver:
<strong>      - 192.168.1.2
</strong>      - 119.29.29.29
      - 114.114.114.114
      - 223.5.5.5
  fallback:
      - https://doh.pub/dns-query
      - https://cloudflare-dns.com/dns-query
      - https://1.12.12.12/dns-query
      - https://120.53.53.53/dns-query
  fallback-filter:
    geoip: true
    geoip-code: CN
    ipcidr:
      - 240.0.0.0/4
    domain:
      - '+.google.com'
      - '+.facebook.com'
      - '+.youtube.com'

EOF

sed -n '24,$p' clash.yml >> clash-premium.yml

</code></pre>

#### docker-compose.yml

```yaml
cat > /usr/local/clash/docker-compose.yml << EOF
services:
  clash:
    container_name: clash-premium
    image: registry.cn-chengdu.aliyuncs.com/yunwei361/clash-premium:latest
    cpus: '2'
    mem_limit: 1024M
    restart: always
    network_mode: host
    privileged: true
    devices:
      - /dev/net/tun
    volumes:
      - /usr/local/clash/clash-premium.yml:/root/.config/clash/config.yaml
    environment:
      - TZ=Asia/Shanghai
  clash-web:
    container_name: clash-web
    image: registry.cn-chengdu.aliyuncs.com/yunwei361/yacd:latest
    cpus: '2'
    mem_limit: 256M
    restart: always
    ports:
      - "1234:80"
    environment:
      - TZ=Asia/Shanghai
EOF
```

```yaml
cat > /usr/local/AdGuard/docker-compose.yml << EOF
services:
  adguard:
    container_name: Adguard
    image: registry.cn-chengdu.aliyuncs.com/yunwei361/adguardhome:latest
    cpus: '2'
    mem_limit: 1024M
    restart: always
    network_mode: host
    volumes:
      - /usr/local/AdGuard/conf:/opt/adguardhome/conf
      - /usr/local/AdGuard/work:/opt/adguardhome/work
    environment:
      - TZ=Asia/Shanghai
    ports:
      - "53:53/tcp"
      - "53:53/udp"
      - "67:67/udp"
      - "68:68/udp"
      - "80:80/tcp"
      - "443:443/tcp"
      - "443:443/udp"
      - "3000:3000/tcp"
      - "853:853/tcp"
      - "853:853/udp"
      - "8853:8853/udp"
      - "784:784/udp"
      - "5443:5443/tcp"
      - "5443:5443/udp"
EOF
```

### 用 Docker compose 启动容器

```bash
# 启动 AdGuard home
cd /usr/local/AdGuard/
docker compose up -d

# 启动 Clash
cd /usr/local/clash/
docker compose up -d

# 停止服务
docker compose down
```

### 浏览器访问

<pre><code># Clash-Web UI
192.168.1.2:1234

<strong># AdGuard UI:
</strong>192.168.1.2:3000
</code></pre>
