V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
OpenWrt 是一个专门面向嵌入式设备的 Linux 发行版。你可以将 OpenWrt 支持的型号的嵌入式设备,比如各种路由器上的系统,换成一个有更多可能性可以折腾的 Linux 系统。
OpenWrt 官方网站
DopaminePlz
V2EX  ›  OpenWrt

这种情况如何配置网络?(Wireguard, OpenWrt)

  •  
  •   DopaminePlz · 2019-02-16 23:22:57 +08:00 · 186 次点击
    这是一个创建于 1894 天前的主题,其中的信息可能已经有所发展或是发生改变。
    鄙人的路由器利用 Wireguard ( wg0 客户端)科学上网,家里实现的透明科学上网。
    另外路由器还开设了 wg10 服务端,家中的电脑和手机用 Wireguard 客户端连接至路由器后,手机在外可访问家中电脑的共享文件;有一天突发想法,能否通过 WG 连接至家中的路由器,进而科学上网?结果墙内的网站可以,墙外的无法访问。
    请问如何配置网络?

    以下是配置:
    1. wg0:
    #!/bin/sh
    if [ $ACTION = "ifup" -a $INTERFACE = "wg0" ]
    then

    ip route add 8.8.8.8 dev wg0
    ipset list gfwlist || ipset create gfwlist hash:ip
    ## Needed for dhcp client who gets IP dynamically:
    /etc/init.d/dnsmasq restart

    for ip in $(cat '/etc/customed_proxy_ip.txt'); do
    ipset add gfwlist $ip
    done

    cat /etc/iproute2/rt_tables | grep gfwtable
    if [ $? -eq 0 ];then
    echo "gfwtable has already exsisted!"
    else
    echo "200 gfwtable" >> /etc/iproute2/rt_tables
    fi

    iptables -t mangle -N fwmark
    iptables -t mangle -C OUTPUT -j fwmark || iptables -t mangle -A OUTPUT -j fwmark
    iptables -t mangle -C PREROUTING -j fwmark || iptables -t mangle -A PREROUTING -j fwmark
    iptables -t mangle -C fwmark -m set --match-set gfwlist dst -j MARK --set-mark 0xffff || iptables -t mangle -A fwmark -m set --match-set gfwlist dst -j MARK --set-mark 0xffff

    #ip rule show fwmark 0xffff table gfwtable || ip rule add fwmark 0xffff table gfwtable
    ip rule add fwmark 0xffff table gfwtable
    ip route add default dev wg0 table gfwtable
    iptables -C FORWARD -o wg0 -j ACCEPT || iptables -I FORWARD -o wg0 -j ACCEPT
    iptables -t nat -C POSTROUTING -o wg0 -j MASQUERADE || iptables -t nat -I POSTROUTING -o wg0 -j MASQUERADE

    fi

    if [ $ACTION = "ifdown" -a $INTERFACE = "wg0" ]
    then
    ##不写了.
    fi

    2. wg10:
    #!/bin/sh
    if [ $ACTION = "ifup" -a $INTERFACE = "wg10" ]
    then
    ip route add 10.20.0.0/16 dev wg10 src 10.20.0.1
    ## iptables:
    iptables -I INPUT -p udp --dport 1380 -j ACCEPT
    iptables -C FORWARD -i wg10 -j ACCEPT || iptables -I FORWARD -i wg10 -j ACCEPT
    #iptables -I FORWARD -o wg10 -m state --state RELATED,ESTABLISHED -j ACCEPT
    iptables -C FORWARD -o wg10 -j ACCEPT || iptables -I FORWARD -o wg10 -j ACCEPT
    iptables -t nat -C POSTROUTING -o wg10 -j MASQUERADE || iptables -t nat -I POSTROUTING -o wg10 -j MASQUERADE
    fi
    目前尚无回复
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   5282 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 28ms · UTC 08:20 · PVG 16:20 · LAX 01:20 · JFK 04:20
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.