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
    • 最新
    • 标签
主页 / ubuntu / 问题 / 1376466
Accepted
keroles gamal
keroles gamal
Asked: 2021-11-20 00:15:37 +0800 CST2021-11-20 00:15:37 +0800 CST 2021-11-20 00:15:37 +0800 CST

桌面Ubuntu-20.04.3 iptables问题

  • 772

我想测试一些 iptables 规则,该规则是拒绝除 DNS 之外的所有出站流量。
所以我使用此命令将过滤表的 OUTPUT 默认规则更改为 DROP。

sudo iptables -t filter -P OUTPUT DROP

然后我将此规则附加到接受 DNS 流量。

sudo iptables -t filter -A OUTPUT -p udp --dport 53 -o ens33 -j ACCEPT

我运行这个命令来测试策略。

nslookup google.com

在运行这个命令之前,我在我的虚拟机和主机上运行了 wireshark。
然后 nslookup 命令花费了一些时间并给了我这个消息。

连接超时; 无法访问任何服务器

并且wireshark(在虚拟机和主机上)没有捕获任何数据包。

所以我删除了这条规则并添加了另一个。

sudo iptables -t filter -A OUTPUT -p udp --dport 53 -j ACCEPT

并做了和以前一样的事情。
再次出现相同的消息,但wireshark(在虚拟机和主机上)捕获数据包(请求和响应)。

然后我删除了这条规则并添加了下一条规则。

sudo iptables -t filter -A OUTPUT -p udp -j ACCEPT

并做了和以前一样的事情。
这次 nslookup 命令返回结果,并用wireshark 捕获数据包。

那么为什么会这样呢?

在这些测试之前,我安装了 snort(在不同的虚拟机上),我试图丢弃一些数据包,但它没有。
数据包被记录但不被丢弃。
我不知道这些案件是否相关。

iptables
  • 1 1 个回答
  • 154 Views

1 个回答

  • Voted
  1. Best Answer
    Doug Smythies
    2021-11-22T09:47:39+08:002021-11-22T09:47:39+08:00

    你的问题真的很好。没有错误消息,使用各种 iptables 查询工具一切看起来都是正确的。

    但是,您需要允许进出本地环回接口的流量,lo。所以你需要另一条规则。顺便说一句,你不需要这-t filter部分。因此,并针对我的测试计算机网络接口进行了修改,我使用 tcpdump 而不是 wireshark,我有两个事件正在运行,一个在 lo 上,一个在我的 NIC 上:

    sudo iptables -A OUTPUT -o lo -j ACCEPT
    sudo iptables -A OUTPUT -p udp --dport 53 -o br0 -j ACCEPT
    sudo iptables -P OUTPUT DROP
    nslookup google.com
    Server:         127.0.0.53     <<<<<<< NOTE:
    Address:        127.0.0.53#53
    
    Non-authoritative answer:
    Name:   google.com
    Address: 142.251.33.78
    Name:   google.com
    Address: 2607:f8b0:400a:806::200e
    

    和:

    doug@s19:~/iptables/tmp$ cat c06.txt
    2021-11-21 09:41:07.851723 IP 192.168.111.136.37847 > 192.168.111.1.53: 52661+ [1au] A? google.com. (39)
    2021-11-21 09:41:07.879409 IP 192.168.111.1.53 > 192.168.111.136.37847: 52661 1/0/1 A 142.251.33.78 (55)
    2021-11-21 09:41:07.884300 IP 192.168.111.136.52279 > 192.168.111.1.53: 58740+ [1au] AAAA? google.com. (39)
    2021-11-21 09:41:07.899157 IP 192.168.111.1.53 > 192.168.111.136.52279: 58740 1/0/1 AAAA 2607:f8b0:400a:806::200e (67)
    

    和:

    doug@s19:~/iptables/tmp$ cat l01.txt
    2021-11-21 09:41:07.850815 IP 127.0.0.1.51470 > 127.0.0.1.51470: UDP, length 1
    2021-11-21 09:41:07.851625 IP 127.0.0.1.46738 > 127.0.0.53.53: 31736+ A? google.com. (28)
    2021-11-21 09:41:07.879486 IP 127.0.0.53.53 > 127.0.0.1.46738: 31736 1/0/0 A 142.251.33.78 (44)
    2021-11-21 09:41:07.884223 IP 127.0.0.1.35841 > 127.0.0.53.53: 58878+ AAAA? google.com. (28)
    2021-11-21 09:41:07.899259 IP 127.0.0.53.53 > 127.0.0.1.35841: 58878 1/0/0 AAAA 2607:f8b0:400a:806::200e (56)
    

    那么为什么服务器看起来是本地的呢?默认情况下,Ubuntu 运行一个本地解析器来缓冲 dns 记录等:

    doug@s19:~$ sudo ss -tulpn | grep ":53"
    Netid  State  Recv-Q  Send-Q         Local Address:Port  Peer Address:Port                         Process
    udp    UNCONN  0       0              127.0.0.53%lo:53            0.0.0.0:*      users:(("systemd-resolve",pid=834,fd=12))
    tcp    LISTEN  0       4096           127.0.0.53%lo:53            0.0.0.0:*      users:(("systemd-resolve",pid=834,fd=13))
    

    另请参见相关手册页sudo systemctl status systemd-resolved的结果。

    • 0

相关问题

  • iptables 规则强制所有浏览器使用代理

  • iptables 重定向的奇怪问题

  • iptables 允许动态域名和自动更新规则

  • ubuntu 上的 iptables 和 nmap

  • iptables 的图形用户界面?

Sidebar

Stats

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

    如何运行 .sh 脚本?

    • 16 个回答
  • Marko Smith

    如何安装 .tar.gz(或 .tar.bz2)文件?

    • 14 个回答
  • Marko Smith

    如何列出所有已安装的软件包

    • 24 个回答
  • Marko Smith

    无法锁定管理目录 (/var/lib/dpkg/) 是另一个进程在使用它吗?

    • 25 个回答
  • Martin Hope
    Flimm 如何在没有 sudo 的情况下使用 docker? 2014-06-07 00:17:43 +0800 CST
  • Martin Hope
    Ivan 如何列出所有已安装的软件包 2010-12-17 18:08:49 +0800 CST
  • Martin Hope
    La Ode Adam Saputra 无法锁定管理目录 (/var/lib/dpkg/) 是另一个进程在使用它吗? 2010-11-30 18:12:48 +0800 CST
  • Martin Hope
    David Barry 如何从命令行确定目录(文件夹)的总大小? 2010-08-06 10:20:23 +0800 CST
  • Martin Hope
    jfoucher “以下软件包已被保留:”为什么以及如何解决? 2010-08-01 13:59:22 +0800 CST
  • Martin Hope
    David Ashford 如何删除 PPA? 2010-07-30 01:09:42 +0800 CST

热门标签

10.10 10.04 gnome networking server command-line package-management software-recommendation sound xorg

Explore

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

Footer

AskOverflow.Dev

关于我们

  • 关于我们
  • 联系我们

Legal Stuff

  • Privacy Policy

Language

  • Pt
  • Server
  • Unix

© 2023 AskOverflow.DEV All Rights Reserve