侧边栏壁纸
博主头像
咕咕鸡博主等级

行动起来,活在当下

  • 累计撰写 17 篇文章
  • 累计创建 27 个标签
  • 累计收到 0 条评论

目 录CONTENT

文章目录

CentOS 6使用V2Ray+iptables进行透明代理

咕咕鸡
2024-03-24 / 0 评论 / 0 点赞 / 52 阅读 / 1944 字 / 正在检测是否收录...

CentOS 6使用V2Ray+iptables进行透明代理

V2Ray配置
修改V2Ray客户端配置文件
在inbounds标签下面增加以下内容

{
      "port": 12315, //透明代理开放的端口号
      "protocol": "dokodemo-door",
      "settings": {
        "followRedirect": true //这里要为true才能接受来自iptables的流量
      },
      "sniffing": {
        "enabled": true,
        "destOverride": ["http", "tls"]
      }
    }

在outbounds/streamSettings标签下面增加以下内容

 "sockopt": {
          "mark": 255
        }

然后启动V2Ray,查看TCP 12315端口是否正常

iptables配置
为iptables增加以下规则(其中192.168.0.0/16用于跳过对本地网段访问时的代理)

iptables -t nat -N V2RAY
iptables -t nat -A V2RAY -d 192.168.0.0/16 -j RETURN
iptables -t nat -A V2RAY -p tcp -j RETURN -m mark --mark 0xff
iptables -t nat -A V2RAY -p tcp -j REDIRECT --to-ports 12315
iptables -t nat -A PREROUTING -p tcp -j V2RAY
iptables -t nat -A OUTPUT -p tcp -j V2RAY

ip rule add fwmark 1 table 100
ip route add local 0.0.0.0/0 dev lo table 100
iptables -t mangle -N V2RAY_MASK
iptables -t mangle -A V2RAY_MASK -d 192.168.0.0/16 -j RETURN
iptables -t mangle -A V2RAY_MASK -p udp -j TPROXY --on-port 12315 --tproxy-mark 1
iptables -t mangle -A PREROUTING -p udp -j V2RAY_MASK

然后service iptables save保存规则

开启IPv4转发
修改/etc/sysctl.conf
net.ipv4.ip_forward = 0改为net.ipv4.ip_forward = 1
然后执行sysctl -p生效

0

评论区