V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
peasant
V2EX  ›  宽带症候群

尝试各种组网工具都无法访问局域网的原因终于被找到了

  •  
  •   peasant · 37 天前 · 1473 次点击
    这是一个创建于 37 天前的主题,其中的信息可能已经有所发展或是发生改变。

    以前一直用的 CentOS7 ,感觉 iptables 太复杂用着不方便就一直用的 firewalld ,后来换了 Debian 系统,习惯性的依然安装 firewalld 使用。

    firewalld 开启包转发也很简单,一条命令即可
    firewall-cmd --permanent --add-masquerade

    使用 firewall-cmd --list-all 可以看到当前的设置
    public (active)
      target: default
      icmp-block-inversion: no
      interfaces:
      sources:   services: dhcpv6-client dns http https ssh
      ports: 1080/tcp
      protocols:
      forward: yes
      masquerade: yes
      forward-ports:
      source-ports:
      icmp-blocks:
      rich rules:

    看上去一切都很好,开放端口确实是都生效了,按我的理解开启的包转发也应该是生效的,但是组网后就是访问不了局域网,折腾放弃好几次,今天终于发现问题在哪了。
    interfaces:
    问题就是这一条,没有指定网卡名称……,放行端口可以不指定网卡,但是开启包转发必须指定网卡。
    使用下面的命令把 ens3 网卡加入到 public 的 interface 里就能正常转发了,这时候只要组网工具的路由配置正确就能正常访问网络了。
    firewall-cmd --zone=public --change-interface=ens3 --permanent

    当然修改以后需要执行一下 firewall-cmd --reload 来让修改生效

    2 条回复    2024-03-21 14:19:50 +08:00
    jasonyang9
        1
    jasonyang9  
       37 天前 via Android
    从 firewalld 切到 nftables 美滋滋
    billlee
        2
    billlee  
       37 天前 via Android   ❤️ 2
    masquerade 不是包转发,是 SNAT. 所以必须指定一个网卡才知道要转换成什么地址
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   922 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 23ms · UTC 19:56 · PVG 03:56 · LAX 12:56 · JFK 15:56
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.