V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
Distributions
Ubuntu
Fedora
CentOS
中文资源站
网易开源镜像站
qsnow6
V2EX  ›  Linux

如何在 Linux 上设置全局代理?

  •  
  •   qsnow6 · 136 天前 · 1742 次点击
    这是一个创建于 136 天前的主题,其中的信息可能已经有所发展或是发生改变。

    在服务器上搭了 clash_premium ,并且开启了 TUN 模式,希望服务器上所有的软件都能走代理,但是发现并没有生效,以下是我的代理,配置有问题吗

    docker-compose.yml

    services:
      clash:
        # ghcr.io/dreamacro/clash
        # ghcr.io/dreamacro/clash-premium
        # dreamacro/clash
        # dreamacro/clash-premium
        image: dreamacro/clash-premium
        container_name: clash
        volumes:
          - ./config.yaml:/root/.config/clash/config.yaml
          - ./profiles:/root/.config/clash/profiles
          - ./ui:/ui # dashboard volume
        ports:
          - "7890:7890"
          - "1081:1081"
          - "9090:9090" # external controller (Restful API)
        # TUN
        cap_add:
          - NET_ADMIN
        devices:
          - /dev/net/tun
        restart: unless-stopped
        network_mode: "bridge" # or "host" on Linux
    

    config.yaml

    
    port: 7890
    socks-port: 1081
    allow-lan: true
    mode: rule
    log-level: info
    ipv6: true
    # external-controller 也可以为 0.0.0.0:9090
    # 参考 https://github.com/Dreamacro/clash/wiki/Configuration
    external-controller: 0.0.0.0:9090
    external-ui: /ui
    tun:
      enable: true
      stack: system
      auto-detect-interface: true
    ...
    
    12 条回复    2023-12-14 12:01:38 +08:00
    Lemonad3
        1
    Lemonad3  
       136 天前
    下面是我瞎说的
    vim /etc/profile
    export http_proxy=“http://ip:port”
    export https_proxy=“http://ip:port”
    source /etc/profile
    YaD2x
        2
    YaD2x  
       136 天前
    没用过 clash 有啥全局代理,他的 tun 模式和全局代理等同吗? 我知道一个有透明代理的几乎可以实现全局代理
    Puteulanus
        3
    Puteulanus  
       136 天前
    docker 运行的 tun 模式,应该只能创建网卡吧,宿主机还得手动设置一下路由表的默认网关才行?
    没用过 clash_premium ,按 VPN 来猜的
    4Qd5zQCm26
        4
    4Qd5zQCm26  
       136 天前
    一楼 那样设置后
    # 设置系统代理
    cat <<EOL > /etc/profile.d/proxy.sh
    export http_proxy="http://127.0.0.1:7890"
    export https_proxy="http://127.0.0.1:7890"
    export no_proxy="localhost, 127.0.0.1"
    EOL

    source /etc/profile

    Docker 具体容器 在启动的时候,还是要 指定 类似的 proxy
    ysc3839
        5
    ysc3839  
       136 天前 via Android
    首先 clash 没有外部依赖,没必要用 Docker 。
    其次要用 Docker 的话,network_mode 需要设置成 host 。
    roding
        6
    roding  
       136 天前   ❤️ 1
    V2raya, 全局透明代理,装了都不用配
    zhangyichent
        7
    zhangyichent  
       136 天前
    clash 我之前在服务器上也试了一下,不知道咋搞的不管用,我干脆就把 http_proxy 全都指向我的 windows 机器,在 windows 机器开局域网模式。。。省的 linux 上配的太麻烦了。
    676529483
        8
    676529483  
       136 天前
    走全局的话要改 iptables
    Corybyte
        9
    Corybyte  
       136 天前
    proxychains
    lijiangang886
        10
    lijiangang886  
       136 天前
    这是 clash 装在 docker 里了?那这个 tun 只对 docker 内部生效啊
    EVANGELIONAir
        11
    EVANGELIONAir  
       136 天前
    v2raya 全局透明代理,clash 开 tun ,两者都行
    cyp0633
        12
    cyp0633  
       135 天前
    建议 nftables tproxy
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   1120 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 26ms · UTC 18:12 · PVG 02:12 · LAX 11:12 · JFK 14:12
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.