【问题标题】:Offer Wireguard to DHCP Clients via dnsmasq通过 dnsmasq 向 DHCP 客户端提供 Wireguard
【发布时间】:2020-11-08 19:07:50
【问题描述】:

我正在尝试构建一个wireguard 设置,我可以在其中通过dnsmasq 将wireguard VPN 分发给DHCP 客户端,以便他们的dhcp 客户端只能通过VPN 访问互联网。

但是,正确的路由似乎仍然存在问题,但我找不到。

结构: eth0:互联网 wg0:护线 eth1:这里附加了 dhcp 客户端

eth1 初始化

/usr/bin/ip link set eth1 up
/usr/bin/ip addr add 10.10.1.1/24 dev eth1

wg0.conf

[Interface]
PrivateKey = $PRIVATE_KEY
Address = 10.20.40.11
Table = off
DNS = $DNS_SRV_ON_WG_SRV

[Peer]
PublicKey = $PUBLIC_KEY
AllowedIPs = 0.0.0.0/0
Endpoint = $WG_SERVER:51820

iptables

/usr/sbin/sysctl -w net.ipv4.ip_forward=1
iptables -A FORWARD -i eth1 -o wg0 -j ACCEPT
iptables -A FORWARD -i wg0 -o eth1 -m state --state ESTABLISHED,RELATED -j ACCEPT
iptables  -t nat -A POSTROUTING -o wg0 -j MASQUERADE

dnsmasq 配置

$(which dnsmasq)    --interface eth1 \
                    --bind-interfaces \
                    --dhcp-authoritative \
                    --dhcp-range=10.10.1.100,10.10.1.200,72h \
                    --resolv-file=$(dirname "$0")/dnsmasq_resolv.conf

DHCP客户端可以ping通eth1和wg0的IP,eth0不能ping通(应该是正确的)

但是我在wg0上看不到任何流量,所以我认为是路由的问题:

希望任何人都可以提供帮助

【问题讨论】:

    标签: iptables dhcp dnsmasq wireguard


    【解决方案1】:

    找到解决办法

    ip rule add from 10.10.1.0/24 lookup 200
    ip route add default dev wg0 table 200
    

    【讨论】:

      猜你喜欢
      • 2016-10-26
      • 2019-07-13
      • 1970-01-01
      • 2022-06-23
      • 1970-01-01
      • 2010-12-19
      • 2017-10-29
      • 2016-11-25
      • 1970-01-01
      相关资源
      最近更新 更多