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
    • 最新
    • 标签
主页 / user-371793

user371793's questions

Martin Hope
user371793
Asked: 2021-12-14 11:46:52 +0800 CST

Firewalld 阻止 WireGuard LAN 上客户端之间的 SSH

  • 0

firewalld 中需要允许什么,以便 WireGuard 客户端可以通过 SSH 相互连接?


设置

我在 WireGuard VPN 网络上有两个客户端和一个服务器。他们都在运行 Debian 11。

CLIENT A -------- SERVER -------- CLIENT B
10.0.1.2         10.0.1.1         10.0.1.3

可以做什么

  • 我可以从任一客户端通过 SSH 连接到服务器。
  • 我可以从服务器通过 SSH 连接到任一客户端。

问题: 但是当我尝试 SSH 客户端到客户端时,我得到“ssh:连接到主机 10.0.1.2 端口 22:没有到主机的路由”


故障排除

  1. 机器之间的路径已启动,因为我可以 ping...
    • 客户端到服务器,
    • 服务器到客户端,
    • 和客户对客户。
  2. 这些端口是可访问的,因为我可以远程登录...
    • 从服务器到端口 22 上的任一客户端。
    • 从任一客户端到端口 22 上的服务器。

问题: 但是当我尝试 telnet 客户端到客户端时,我得到“telnet:无法连接到远程主机:没有到主机的路由”


已确认的内容

  • SSH 是 firewalld 上列出的服务:firewall-cmd --list-services返回ssh
  • ip-foward 在内核上设置:sysctl -a返回net.ipv4.ip_forward = 1
  • 在 iptables 上设置转发:iptables-save返回-A FORWARD -i wg0 -o wg0 -j ACCEPT
  • 在服务器上禁用 firewalld 确实允许两个 WireGuard 客户端之间的 SSH 连接。

感谢您的帮助和指点。

debian wireguard firewalld
  • 1 个回答
  • 640 Views
Martin Hope
user371793
Asked: 2021-09-03 09:07:59 +0800 CST

如何使用 firewalld 将特权子 1024 端口转发到非特权 1024+ 端口?

  • 2

问题

如何使用 firewalld 将特权子 1024 端口转发到非特权 1024+ 端口?

原因

我们为什么要这样做?我们希望能够切换网关上的非特权 1050 端口并使用不同的上游邮件服务器。例如,要测试不同的垃圾邮件解决方案,请使用端口 1051 将邮件发送到具有不同垃圾邮件过滤解决方案的不同邮件服务器。

邮件服务器在启动时会自动连接到网关。自动连接只能发生在 1024+ 的非特权端口上。

布局和设置

布局

+--------+         +---------------------+         +----------------+
|  WAN   |         |                1050 | <-      |                |
| Client |         |       Gateway       |    \    |   Mail Server  |
|        |  <--->  | 25                  |      -> | 25             |
+--------+         +---------------------+         +----------------+

设置防火墙

清除防火墙,打开端口,设置端口转发,添加几个服务。

root@gateway:~# firewall-cmd --reload
root@gateway:~# firewall-cmd --zone=public --add-port=25/tcp
root@gateway:~# firewall-cmd --zone=public --add-forward-port=port=25:proto=tcp:toport=1050
root@gateway:~# firewall-cmd --add-service={http,https,smtp}

验证防火墙

确认防火墙设置...

root@gateway:~# firewall-cmd --list-all
public (active)
  target: default
  icmp-block-inversion: no
  interfaces: etho0
  sources: 
  services: dhcpv6-client http https smtp ssh
  ports: 25/tcp
  protocols: 
  masquerade: no
  forward-ports: port=25:proto=tcp:toport=1050:toaddr=
  source-ports: 
  icmp-blocks: 
  rich rules: 

这是我们期望在防火墙规则中看到的。

结果

这是我们在网关上远程登录上游邮件服务器时得到的...

root@gateway:~# telnet localhost 1050
Trying 127.0.0.1...
Connected to localhost.
Escape character is '^]'.
220 debian10email.debian10email ESMTP Postfix (Debian/GNU)

这是我们从远程客户端机器上得到的......

client@client123:~$ telnet gateway.example.org 25
Trying <IP_of_gateway>...
Connected to gateway.example.org.
Escape character is '^]'.

我们期望也能看到这220 debian10email.debian10email ESMTP Postfix (Debian/GNU)条线,但没有。

完整性检查...

考试

只是为了确认正确编写了端口转发规则,我们...

  • 在防火墙上打开端口 1025。
  • 端口转发 1025 到 1050
  • 然后检查我们在远程客户端上看到的内容。

调整防火墙

清除防火墙,打开端口,设置端口转发,以及一些服务。

root@gateway:~# firewall-cmd --reload
root@gateway:~# firewall-cmd --zone=public --add-port=1025/tcp
root@gateway:~# firewall-cmd --zone=public --add-forward-port=port=1025:proto=tcp:toport=1050
root@gateway:~# firewall-cmd --add-service={http,https,smtp}

验证防火墙

root@gateway:~# firewall-cmd --list-all
public (active)
  target: default
  icmp-block-inversion: no
  interfaces: etho0
  sources: 
  services: dhcpv6-client http https smtp ssh
  ports: 1025/tcp
  protocols: 
  masquerade: no
  forward-ports: port=1025:proto=tcp:toport=1050:toaddr=
  source-ports: 
  icmp-blocks: 
  rich rules: 

结果

client@client123:~$ telnet gateway.example.org 1025
Trying <IP_of_gateway>...
Connected to gateway.example.org.
Escape character is '^]'.
220 debian10email.debian10email ESMTP Postfix (Debian/GNU)

我们有预期的220 debian10email.debian10email ESMTP Postfix (Debian/GNU)线路,所以防火墙按预期进行端口转发。

结论

特权端口和非特权端口之间的转发不同于非特权端口之间的转发。

我们如何在 Debian 10 Buster 上使用 firewalld 将特权子 1024 端口转发到非特权 1024+ 端口?如果某处有答案,请指出。我们一直没能找到它。

port-forwarding firewalld debian-buster
  • 1 个回答
  • 116 Views
Martin Hope
user371793
Asked: 2021-08-21 13:07:51 +0800 CST

如何将到达给定端口的所有流量转发到另一个端口?

  • 0

如何将到达给定端口的所有流量转发到另一个端口?

定义布局和问题

布局

这是我正在尝试做的布局......

+--------+         +---------------------+         +----------------+
|  WAN   |  <--->  | 6789                |         |                |
| Client |         |       Gateway       |         |      Host      |
|        |         |                4567 |  <--->  |  2345 Service  |
+--------+         +---------------------+         +----------------+

我想透明地将所有到达端口 6789 的流量转发到端口 4567。WAN 上的客户端和主机上的服务应该对网关一无所知。

网关是带有 firewalld 的 Debian 10。

问题

我无法让流量到达网关上的端口 6789 以转发到端口 4567。


目前的设置

步骤 01 - 在防火墙上公开端口并确认端口已打开。

打开网关上的端口

  1. 运行firewall-cmd命令:firewall-cmd --add-port=6789

  2. 检查防火墙状态...

root@gateway:~# firewall-cmd --list-all
public (active)
  target: default
  icmp-block-inversion: no
  interfaces: etho0
  sources: 
  services: dhcpv6-client http https ssh
  ports: 6789/tcp
  protocols: 
  masquerade: yes
  forward-ports: 
  source-ports: 
  icmp-blocks: 
  rich rules:
  1. 确认端口已打开。
  • 在网关上,启动一个监听器:nc -vvlp 6789 &
  • 确认监听器已启动...
root@gateway:~# netstat -tulnp | grep 6789
tcp        0      0 0.0.0.0:6789              0.0.0.0:*               LISTEN      2274/nc
  • 从客户端,尝试到达网关:
client@client123:~$ nc -vvN gateway.example.org 6789
Connection to gateway.example.org 6789 port [tcp/*] succeeded!

结论:防火墙上的 6789 端口是开放的。

nc通过终止客户端和网关上的进程进行清理。

步骤 02 - 确认网关和主机上的服务之间的连接

root@gateway:~# telnet localhost 4567
Trying 127.0.0.1...
Connected to localhost.
Escape character is '^]'.
220 backendhost.backendhost MyService (Debian/GNU)

结论:网关和主机上的服务之间的隧道是up的。

步骤 03 - 在网关上添加端口转发并检查防火墙状态

root@gateway:~# firewall-cmd --add-forward-port=port=6789:proto=tcp:toport=4567`
root@gateway:~# firewall-cmd --list-all
public (active)
  target: default
  icmp-block-inversion: no
  interfaces: etho0
  sources: 
  services: dhcpv6-client ssh
  ports: 6789/tcp
  protocols: 
  masquerade: no
  forward-ports: port=6789:proto=tcp:toport=4567:toaddr=
  source-ports: 
  icmp-blocks: 
  rich rules: 

结论:端口转发在防火墙中。


此时,如果我尝试从客户端远程登录主机,我会得到......

client@client123:~$ telnet gateway.example.org 6789
Trying <IP_of_gateway>...
telnet: Unable to connect to remote host: Connection refused

在这一点上,我想看看我在上面的步骤 02 中看到了什么。

问题

这是我不确定的地方...

当我netstat -tulnp在网关上运行时,它不会显示任何正在侦听端口 6789 的内容。我不希望它出现,因为我没有运行任何侦听端口 6789 的服务。

我需要某种服务来监听 6789 端口吗?如果是这样,是什么?还是我在防火墙设置中遗漏了什么?我需要这里提到的某种透明代理吗?

我不会在这篇文章中加上我在过去几周读过的所有内容的链接,但如果有一篇文章有​​答案,请随时指出。

编辑

回应@AB

主机在防火墙后面运行。当主机启动时,它会使用 SSH 端口转发自动创建到网关的隧道。

这是主机在启动时运行的命令:ssh -N -R 4567:localhost:2345 tunnel@gateway.example.org

该隧道已在步骤 02 中确认。虽然我之前没有提到,但客户端在与主机位于同一 LAN 时工作。

我正在努力使到达网关的流量成功传递到主机。网关是“透明的”。安全证书由主机持有,客户端应该认为它直接与主机对话。

我仍在努力学习这些术语,所以如果有更正确的方法来问这个问题,我当然愿意知道它是什么。

port-forwarding firewalld debian-buster
  • 1 个回答
  • 550 Views

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