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 / 问题 / 1002024
Accepted
Ror
Ror
Asked: 2020-02-07 03:10:35 +0800 CST2020-02-07 03:10:35 +0800 CST 2020-02-07 03:10:35 +0800 CST

Strongswan IPSEC 隧道以一种方式阻止流量

  • 772

我已经在 debian 9 机器上使用 strongswan 建立了一个有效的站点到站点 IPSEC 隧道。但是,我对流量应该如何工作有一个要求:站点 A 上的网络可以将数据包发送到站点 B 网络并接收确认。站点 B 只能在连接打开时与站点 A 通信。基本上,站点 A 可以访问站点 B,但站点 B 无法访问站点 A。基础架构架构如下:

        SITE A                                              SITE B
NetA--------------GatewayA------Internet------GatewayB-----------------NetB
A.A.A.A/24  A.A.A.254  pub.lic.ip.A   pub.lic.ip.B  B.B.B.254     B.B.B.B/24

我只能访问站点 A。站点 B 在客户端。

现在我需要限制从站点 B 到站点 A 的访问。我首先将 iptables 放在 GatewayA 上,以便基本上接受来自站点 B 的 ESTABLISHED 和 RELATED 数据包并丢弃其他所有数据包。这是我的 iptables :

sudo iptables -L FORWARD
Chain FORWARD (policy DROP)
target     prot opt source               destination
ACCEPT     all  --  B.B.B.B/24        A.A.A.A/24        state RELATED
ACCEPT     all  --  B.B.B.B/24        A.A.A.A/24        state ESTABLISHED
DROP       all  --  B.B.B.B/24        A.A.A.A/24        policy match dir in pol ipsec proto esp
ACCEPT     all  --  B.B.B.B/24        A.A.A.A/24        policy match dir in pol ipsec reqid 2 proto esp
ACCEPT     all  --  A.A.A.A/24        B.B.B.B/24        policy match dir out pol ipsec reqid 2 proto esp
sudo iptables -L INPUT
Chain INPUT (policy DROP)
target     prot opt source               destination
ACCEPT     all  --  B.B.B.B/24        A.A.A.A/24        state RELATED
ACCEPT     all  --  B.B.B.B/24        A.A.A.A/24        state ESTABLISHED
DROP       all  --  B.B.B.B/24        A.A.A.A/24        policy match dir in pol ipsec proto esp
ACCEPT     all  --  B.B.B.B/24        A.A.A.A/24        policy match dir in pol ipsec reqid 2 proto esp

在这里,每个表上的前 3 条规则是手动编辑的,接下来的规则是由 strongswan/ipsec 设置的。在测试环境中,我可以从站点 A ping 到站点 B,但不能从站点 B 到站点 A,这正是我想要的。

me@gatewayA:~$ ping A.A.A.1
PING A.A.A.1 (A.A.A.1) 56(84) bytes of data.
64 bytes from A.A.A.1: icmp_seq=1 ttl=63 time=2.25 ms
64 bytes from A.A.A.1: icmp_seq=2 ttl=63 time=1.32 ms
64 bytes from A.A.A.1: icmp_seq=3 ttl=63 time=1.28 ms
64 bytes from A.A.A.1: icmp_seq=4 ttl=63 time=1.56 ms
64 bytes from A.A.A.1: icmp_seq=5 ttl=63 time=1.45 ms
me@gatewayB:~$ ping B.B.B.1
PING B.B.B.1 (B.B.B.1) 56(84) bytes of data.

现在,出于某种原因,我需要重新启动 ipsec :

sudo ipsec restart

现在我检查我的 iptables :

sudo iptables -L FORWARD
Chain FORWARD (policy DROP)
target     prot opt source               destination
ACCEPT     all  --  B.B.B.B/24        A.A.A.A/24        policy match dir in pol ipsec reqid 2 proto esp
ACCEPT     all  --  A.A.A.A/24        B.B.B.B/24        policy match dir out pol ipsec reqid 2 proto esp
ACCEPT     all  --  B.B.B.B/24        A.A.A.A/24        state RELATED
ACCEPT     all  --  B.B.B.B/24        A.A.A.A/24        state ESTABLISHED
DROP       all  --  B.B.B.B/24        A.A.A.A/24        policy match dir in pol ipsec proto esp
sudo iptables -L INPUT
Chain INPUT (policy DROP)
target     prot opt source               destination
ACCEPT     all  --  B.B.B.B/24        A.A.A.A/24        policy match dir in pol ipsec reqid 2 proto esp
ACCEPT     all  --  B.B.B.B/24        A.A.A.A/24        state RELATED
ACCEPT     all  --  B.B.B.B/24        A.A.A.A/24        state ESTABLISHED
DROP       all  --  B.B.B.B/24        A.A.A.A/24        policy match dir in pol ipsec proto esp

如您所见,重新启动 ipsec 更改了 iptables,现在我可以双向 ping。

所以我想知道是否有任何方法可以实现我想要的,即限制从站点 B 到站点 A 的访问,而不影响从站点 A 到站点 B 的通信。也许有一种方法可以在 strongswan 配置中定义 iptables,或者可能更改 iptables 规则的优先级,以便它们在重新启动时保持顺序。

debian iptables ipsec strongswan
  • 1 1 个回答
  • 1439 Views

1 个回答

  • Voted
  1. Best Answer
    Ror
    2020-02-08T02:39:26+08:002020-02-08T02:39:26+08:00

    正如 ecdsa 所指出的,我只需要leftfirewall=no输入 ipsec.conf 以便 iptables 可以具有我想要的行为。

    • 1

相关问题

  • 关闭 FTP

  • 如何在同一台电脑上从 putty 连接 debian vmware

  • debian- 文件到包的映射

  • Debian Ubuntu 网络管理器错误 [关闭]

  • 为本地网络中的名称解析添加自定义 dns 条目

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