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 / 问题 / 1132890
Accepted
prototyp
prototyp
Asked: 2023-06-08 19:41:09 +0800 CST2023-06-08 19:41:09 +0800 CST 2023-06-08 19:41:09 +0800 CST

使用firewalld和wireguard在点到站点中限制与专用网络的连接

  • 772

我正在尝试限制对 Openstack 中运行的专用网络的 VPN 访问。wireguard 服务器位于专用网络内部,流量从 Openstack 路由到其专用 IP 地址。专用网络内部有一个所有客户端都需要访问的 Dns 服务器,并且每个客户端都有一个特定的服务器。客户端应该只到达其特定的服务器和 DNS 服务器。管理员还应通过wireguard 访问专用网络,不受限制地使用不同的wireguard 接口。

网络

Wireguard 服务器(Ubuntu 22.04):

  • net.ipv4.ip_forward=1设置在/etc/sysctl.conf
  • ens3:10.10.10.107
  • wg_admin:10.42.43.1/端口 51821
  • wg_clients:10.42.42.1 /端口51820

专用网络内的服务器:

  • DNS服务器:10.10.10.203
  • 客户端1服务器:10.10.10.133
  • 客户端2服务器:10.10.10.209

连接客户端/管理员:

  • 客户端1:10.42.42.3
  • 客户端2:10.42.42.2
  • 管理员1:10.42.43.2

Wireguard 服务器配置

我使用两个区域: public:处理传入流量

$ firewall-cmd --zone=public --list-all
public (active)
  target: default
  icmp-block-inversion: no
  interfaces: ens3
  sources: 
  services: dhcpv6-client ssh ssh-custom
  ports: 51821/udp 51820/udp
  protocols: 
  forward: yes
  masquerade: no
  forward-ports: 
  source-ports: 
  icmp-blocks: 
  rich rules: 

wireguard:处理wireguard流量;限制哪些流量转发

$ firewall-cmd --zone=wireguard --list-all
wireguard (active)
  target: default
  icmp-block-inversion: no
  interfaces: wg_admin wg_clients
  sources: 
  services: 
  ports: 
  protocols: 
  forward: yes
  masquerade: no
  forward-ports: 
  source-ports: 
  icmp-blocks: 
  rich rules: 
        rule family="ipv4" source address="10.42.42.2" destination address="10.10.10.209" masquerade
        rule family="ipv4" source address="10.42.42.2" destination address="10.10.10.203" masquerade
        rule family="ipv4" source address="10.42.42.3" destination address="10.10.10.203" masquerade
        rule family="ipv4" source address="10.42.43.0/24" masquerade log prefix="wg_admin_masq" level="warning"
        rule family="ipv4" source address="10.42.42.3" destination address="10.10.10.133" masquerade

问题

使用当前的firewalld设置,我假设进入wiregurad接口的数据包在wireguard区域中处理。当丰富的规则匹配时,源 ip 应更改为wireguard 服务器 ip 10.10.10.107,然后简单地路由到客户端。但不幸的是,这不是这样工作的。

当检查内核消息时,我看到:

[Thu Jun  8 13:32:18 2023] "filter_FWD_wireguard_REJECT: "IN=wg_admin OUT=ens3 MAC= SRC=10.42.43.2 DST=10.10.10.203 LEN=64 TOS=0x00 PREC=0x00 TTL=63 ID=31157 DF PROTO=TCP SPT=44920 DPT=53 WINDOW=64860 RES=0x00 SYN URGP=0 
[Thu Jun  8 13:32:20 2023] "filter_FWD_wireguard_REJECT: "IN=wg_clients OUT=ens3 MAC= SRC=10.42.42.2 DST=10.10.10.203 LEN=82 TOS=0x00 PREC=0x00 TTL=63 ID=9462 PROTO=UDP SPT=36905 DPT=53 LEN=62 
[Thu Jun  8 13:32:23 2023] "filter_FWD_wireguard_REJECT: "IN=wg_admin OUT=ens3 MAC= SRC=10.42.43.2 DST=10.10.10.203 LEN=64 TOS=0x00 PREC=0x00 TTL=63 ID=50271 DF PROTO=TCP SPT=55930 DPT=53 WINDOW=64860 RES=0x00 SYN URGP=0 
[Thu Jun  8 13:32:41 2023] "filter_FWD_wireguard_REJECT: "IN=wg_clients OUT=ens3 MAC= SRC=10.42.42.2 DST=10.10.10.203 LEN=92 TOS=0x00 PREC=0x00 TTL=63 ID=2910 PROTO=UDP SPT=45837 DPT=53 LEN=72 
[Thu Jun  8 13:32:41 2023] "filter_FWD_wireguard_REJECT: "IN=wg_clients OUT=ens3 MAC= SRC=10.42.42.2 DST=10.10.10.203 LEN=92 TOS=0x00 PREC=0x00 TTL=63 ID=58612 PROTO=UDP SPT=53142 DPT=53 LEN=72 

我的自定义日志前缀未显示,因此我假设我的丰富规则被忽略。当我尝试 ping dns 服务器时:

$ ping 10.10.10.203
PING 10.10.10.203 (10.10.10.203) 56(84) bytes of data.
From 10.42.43.1 icmp_seq=1 Packet filtered

当我尝试 ping Wireguard 服务器时:

$ ping 10.10.10.107
PING 10.10.10.107 (10.10.10.107) 56(84) bytes of data.
64 bytes from 10.10.10.107: icmp_seq=1 ttl=64 time=26.7 ms
$ ping 10.42.42.1  
PING 10.42.42.1 (10.42.42.1) 56(84) bytes of data.
64 bytes from 10.42.42.1: icmp_seq=1 ttl=64 time=28.5 ms

我究竟做错了什么?

ubuntu
  • 1 1 个回答
  • 119 Views

1 个回答

  • Voted
  1. Best Answer
    prototyp
    2023-07-20T16:58:05+08:002023-07-20T16:58:05+08:00

    最后我自己找到了答案。允许使用firewalld进行路由和过滤的功能称为策略,是后来引入的。Pro Custodibus 的这篇精彩文章还解释了使用wireguard 和firewalld 的不同场景。

    通过策略,可以将流量从一个区域路由到另一个区域,并为经过的流量设置特定的规则集。

    为了将管理员/客户端的wireguard接口/连接与wireguard服务器路由到专用网络之间的分离归档,我们:

    • 将wireguard接口分成单独的区域
    • 添加了转发流量的区域
    • 添加了两个连接wireguard区域和forward区域的策略
    • 在策略中添加了过滤wireguard流量的规则

    区域:

    $ firewall-cmd --info=zone=wg_clients
    wg_clients (active)
      target: DROP
      icmp-block-inversion: no
      interfaces: wg_clients
      sources: 
      services: 
      ports: 
      protocols: 
      forward: no
      masquerade: no
      forward-ports: 
      source-ports: 
      icmp-blocks: 
      rich rules:
    
    $ firewall-cmd --info=zone=wg_admins
    wg_admins (active)
      target: DROP
      icmp-block-inversion: no
      interfaces: wg_admins
      sources: 
      services: 
      ports: 
      protocols: 
      forward: no
      masquerade: no
      forward-ports: 
      source-ports: 
      icmp-blocks: 
      rich rules:
    
    $ firewall-cmd --info=zone=forward
    forward (active)
      target: ACCEPT
      icmp-block-inversion: no
      interfaces: 
      sources: 10.10.10.0/24
      services: 
      ports: 
      protocols: 
      forward: no
      masquerade: yes
      forward-ports: 
      source-ports: 
      icmp-blocks: 
      rich rules: 
    

    政策:

    $ firewall-cmd --info-policy=wg_clients2forward
    wg_clients2forward (active)
      priority: -1
      target: REJECT
      ingress-zones: wg_clients
      egress-zones: forward
      services: 
      ports: 
      protocols: 
      masquerade: no
      forward-ports: 
      source-ports: 
      icmp-blocks: 
      rich rules: 
            rule family="ipv4" destination address="10.10.10.203" service name="dns" accept
            rule family="ipv4" source address="10.42.42.3/32" destination address="10.10.10.133" service name="https" accept
            rule family="ipv4" source address="10.42.42.2/32" destination address="10.10.10.209" service name="https" accept
    
    $ firewall-cmd --info-policy=wg_admins2forward
    wg_admins2forward (active)
      priority: -1
      target: REJECT
      ingress-zones: wg_admins
      egress-zones: forward
      services: 
      ports: 
      protocols: 
      masquerade: no
      forward-ports: 
      source-ports: 
      icmp-blocks: 
      rich rules: 
            rule family="ipv4" destination address="10.10.10.0/24" accept
    
    • 0

相关问题

  • 无法通过 Ubuntu VPN 访问外部网络

  • ubuntu apt-get upgrade - 如何在 shell 中单击确定?

  • VirtualBox 上 Ubuntu 的访客优化技巧 [关闭]

  • 外部硬盘上的 virtualbox 虚拟硬盘驱动器(Vista 主机上的 ubuntu 客户机)

  • 如何在 Ubuntu 上挂载 LVM 分区?

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