AskOverflow.Dev

AskOverflow.Dev Logo AskOverflow.Dev Logo

AskOverflow.Dev Navigation

  • 主页
  • 系统&网络
  • Ubuntu
  • Unix
  • DBA
  • Computer
  • Coding
  • LangChain

Mobile menu

Close
  • 主页
  • 系统&网络
    • 最新
    • 热门
    • 标签
  • Ubuntu
    • 最新
    • 热门
    • 标签
  • Unix
    • 最新
    • 标签
  • DBA
    • 最新
    • 标签
  • Computer
    • 最新
    • 标签
  • Coding
    • 最新
    • 标签
主页 / server / 问题 / 1068004
Accepted
Asmodean
Asmodean
Asked: 2021-06-28 10:08:31 +0800 CST2021-06-28 10:08:31 +0800 CST 2021-06-28 10:08:31 +0800 CST

带有 Wireguard 的防火墙转发功能

  • 772

我之前问过如何在运行带有 ufw 和 iptables 作为管理的 wireguard 服务的 VPS 上转发端口。

我不得不这样做:

(56000是我随机选择的端口)(10.66.66.2是wireguard的内部ip)

ufw route allow proto tcp to 10.66.66.2 port 56000

然后我会这样做以实际使用 iptables 转发端口:

iptables -t nat -A PREROUTING -i eth0 -p tcp --dport 56000 -j DNAT --to-destination 10.66.66.2

有没有办法让我实现这一目标firewalld?所以我不必将转发分成两个地方?

伪装在这里使用/是否需要?因为我不知道它的作用,也不知道它的用途。

VPS wireguard wg0 conf 供参考:

Address = 10.66.66.1/24,fd42:42:42::1/64
ListenPort = 49503
PrivateKey = ***


[Peer]
PublicKey = ***
PresharedKey = ***
AllowedIPs = 10.66.66.2/32,fd42:42:42::2/128
port-forwarding wireguard firewalld
  • 1 1 个回答
  • 2028 Views

1 个回答

  • Voted
  1. Best Answer
    Justin Ludwig
    2021-07-06T11:22:09+08:002021-07-06T11:22:09+08:00

    从您之前的 UFW 问题来看,听起来您将 WireGuard 用于两个目的?:1)将流量从您的 VPS 的 WireGuard 客户端转发到 Internet,以及 2)将一些公共端口从您的 VPS 转发回 WireGuard 客户端. 1)需要伪装(又名 SNAT),2)需要端口转发(又名 DNAT)。

    使用 firewalld 进行设置的最简单方法是将 VPS 的公共以太网接口(eth0在您的情况下)绑定到 firewalld 的预定义external区域,并将 VPS 的 WireGuard 接口(wg0在您的情况下)绑定到 firewalld 的预定义internal区域。该external区域预先配置了启用伪装;并且这两个区域也预先配置为接受 SSH 和其他一些服务。

    首先在区域上打开您的 VPS 的 WireGuard 侦听端口(49503在您的情况下)external:

    $ sudo firewall-cmd --zone=external --add-port=49503/udp
    

    56000并将区域上的端口 TCP 转发external到同一端口10.66.66.2:

    $ sudo firewall-cmd --zone=external --add-forward-port='port=56000:proto=tcp:toaddr=10.66.66.2'
    

    然后绑定eth0到external区域(将防火墙的external区域配置应用于所有eth0连接):

    $ sudo firewall-cmd --zone=external --add-interface=eth0
    

    并绑定wg0到internal区域:

    $ sudo firewall-cmd --zone=internal --add-interface=wg0
    

    检查您的活动区域:

    $ sudo firewall-cmd --get-active-zones
    external
      interfaces: eth0
    internal
      interfaces: wg0
    

    并检查您的external区域的配置:

    $ sudo firewall-cmd --info-zone=external
    external (active)
      target: default
      icmp-block-inversion: no
      interfaces: eth0
      sources:
      services: ssh
      ports: 49503/udp
      protocols:
      masquerade: yes
      forward-ports: port=56000:proto=tcp:toaddr=10.66.66.2
      source-ports:
      icmp-blocks:
      rich rules:
    

    如果一切正常,请保存您当前的 firewalld 设置:

    $ sudo firewall-cmd --runtime-to-permanent
    
    • 2

相关问题

  • 为 Cisco ASA 5510 上的端口 443/80 创建 NAT 规则和安全策略

  • 慢速路由问题

  • 通过其子网内的公共 IP 连接到默认主机是否会导致任何问题?

  • 端口镜像作为 Windows 服务

  • 使用 iptables 和 dhcpd 进行端口转发

Sidebar

Stats

  • 问题 205573
  • 回答 270741
  • 最佳答案 135370
  • 用户 68524
  • 热门
  • 回答
  • Marko Smith

    新安装后 postgres 的默认超级用户用户名/密码是什么?

    • 5 个回答
  • Marko Smith

    SFTP 使用什么端口?

    • 6 个回答
  • Marko Smith

    命令行列出 Windows Active Directory 组中的用户?

    • 9 个回答
  • Marko Smith

    什么是 Pem 文件,它与其他 OpenSSL 生成的密钥文件格式有何不同?

    • 3 个回答
  • Marko Smith

    如何确定bash变量是否为空?

    • 15 个回答
  • Martin Hope
    Tom Feiner 如何按大小对 du -h 输出进行排序 2009-02-26 05:42:42 +0800 CST
  • Martin Hope
    Noah Goodrich 什么是 Pem 文件,它与其他 OpenSSL 生成的密钥文件格式有何不同? 2009-05-19 18:24:42 +0800 CST
  • Martin Hope
    Brent 如何确定bash变量是否为空? 2009-05-13 09:54:48 +0800 CST
  • Martin Hope
    cletus 您如何找到在 Windows 中打开文件的进程? 2009-05-01 16:47:16 +0800 CST

热门标签

linux nginx windows networking ubuntu domain-name-system amazon-web-services active-directory apache-2.4 ssh

Explore

  • 主页
  • 问题
    • 最新
    • 热门
  • 标签
  • 帮助

Footer

AskOverflow.Dev

关于我们

  • 关于我们
  • 联系我们

Legal Stuff

  • Privacy Policy

Language

  • Pt
  • Server
  • Unix

© 2023 AskOverflow.DEV All Rights Reserve