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-63934

Jake's questions

Martin Hope
Jake
Asked: 2019-07-12 20:35:02 +0800 CST

同一命名空间中的 veth 设备没有 ICMP 响应

  • 0

我在 Ubuntu 16.04 中创建了一个 veth 设备对,如下所示:

$ sudo ip link add veth1 type veth peer name veth2
$ sudo ip link set dev veth1 up
$ sudo ip link set dev veth2 up
$ sudo ip address add 10.0.10.50/24 dev veth1
$ sudo ip address add 10.0.10.51/24 dev veth2

veth 设备对在同一个命名空间中。我正在尝试测试从一个 veth 设备到另一个设备的 ping。所以我尝试ping如下:

$ ping -I veth1 10.0.10.51
PING 10.0.10.51 (10.0.10.51) from 10.0.10.50 veth1: 56(84) bytes of data.
From 10.0.10.50 icmp_seq=1 Destination Host Unreachable
From 10.0.10.50 icmp_seq=2 Destination Host Unreachable
From 10.0.10.50 icmp_seq=3 Destination Host Unreachable

当我检查 veth2 的 Wireshark 跟踪时,ARP 请求没有得到任何响应(对于 veth1 也观察到类似的跟踪):

 Broadcast  ARP 42  Who has 10.0.10.51? Tell 10.0.10.50

我想问为什么 veth2 与 veth1 在同一个命名空间时不能响应 ICMP 请求?

更新:如果我按如下方式尝试 ping,那么我会收到 ICMP 响应,但 wireshark 没有显示 veth1 和 veth2 设备的踪迹。

 $ ping -I 10.0.10.50 10.0.10.51
 PING 10.0.10.51 (10.0.10.51) from 10.0.10.50 : 56(84) bytes of data.
 64 bytes from 10.0.10.51: icmp_seq=1 ttl=64 time=0.016 ms
 64 bytes from 10.0.10.51: icmp_seq=2 ttl=64 time=0.022 ms

有人可以解释两个 ping 测试的结果差异吗?

networking veth
  • 1 个回答
  • 826 Views
Martin Hope
Jake
Asked: 2019-06-29 17:57:24 +0800 CST

解码用于在 Linux 中创建 veth 设备的 netlink 消息

  • 1

当我运行以下命令创建一对 veth 设备(我正在使用Ubuntu 16.04)时,我想了解与内核交换的 netlink 消息:

$ sudo ip link add veth1 type veth peer name veth2

我尝试按照此链接上的教程进行操作。我使用了 strace 并得到了以下与 netlink 相关的跟踪:

$ sudo strace -e trace=network -x -s 16384 -f -o out ip link add veth1 type veth peer name veth2
$ cat out 
socket(PF_NETLINK, SOCK_RAW|SOCK_CLOEXEC, NETLINK_ROUTE) = 3
setsockopt(3, SOL_SOCKET, SO_SNDBUF, [32768], 4) = 0
setsockopt(3, SOL_SOCKET, SO_RCVBUF, [1048576], 4) = 0
bind(3, {sa_family=AF_NETLINK, pid=0, groups=00000000}, 12) = 0
getsockname(3, {sa_family=AF_NETLINK, pid=6001, groups=00000000}, [12]) = 0
send(3, "\x20\x00\x00\x00\x10\x00\x05\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00", 32, 0) = 32
recvmsg(3, {msg_name(12)={sa_family=AF_NETLINK, pid=0, groups=00000000}, msg_iov(1)=[{"\x34\x00\x00\x00\x02\x00\x00\x00\x00\x00\x00\x00\x71\x17\x00\x00\xed\xff\xff\xff\x20\x00\x00\x00\x10\x00\x05\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00", 16384}], msg_controllen=0, msg_flags=0}, 0) = 52
socket(PF_LOCAL, SOCK_DGRAM|SOCK_CLOEXEC, 0) = 4
sendmsg(3, {msg_name(12)={sa_family=AF_NETLINK, pid=0, groups=00000000}, msg_iov(1)=[{"\x5c\x00\x00\x00\x10\x00\x05\x06\x38\xa2\x16\x5d\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x0a\x00\x03\x00\x76\x65\x74\x68\x31\x00\x00\x00\x30\x00\x12\x00\x08\x00\x01\x00\x76\x65\x74\x68\x24\x00\x02\x00\x20\x00\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x0a\x00\x03\x00\x76\x65\x74\x68\x32\x00\x00\x00", 92}], msg_controllen=0, msg_flags=0}, 0) = 92
recvmsg(3, {msg_name(12)={sa_family=AF_NETLINK, pid=0, groups=00000000}, msg_iov(1)=[{"\x24\x00\x00\x00\x02\x00\x00\x00\x38\xa2\x16\x5d\x71\x17\x00\x00\x00\x00\x00\x00\x5c\x00\x00\x00\x10\x00\x05\x06\x38\xa2\x16\x5d\x00\x00\x00\x00", 32768}], msg_controllen=0, msg_flags=0}, 0) = 36

例如,我尝试解码与发送相关的消息。

// my test did not have any line breaks
$ echo'\x20\x00\x00\x00\x10\x00\x05\x00\x00\x00\x00\x00\x00\x00\x00
\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00
\x00' >> message
$ python tests/decoder/decoder.py pyroute2.netlink.rtnl.rtmsg.rtmsg message
20:00:00:00:10:00:05:00:00:00:00:00:00:00:00:00:00:00:00:00:00:00
:00:00:00:00:00:00:00:00:00:00
{'attrs': [('RTA_UNSPEC', None)],
 'dst_len': 0,
 'family': 0,
 'flags': 0,
 'header': {'flags': 5,
            'length': 32,
            'pid': 0,
            'sequence_number': 0,
            'type': 16},
 'proto': 0,
 'scope': 0,
 'src_len': 0,
 'table': 0,
 'tos': 0,
 'type': 0}
........................................ 

$ echo '\x5c\x00\x00\x00\x10\x00\x05\x06\x38\xa2\x16\x5d\x00\x00
\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00
\x00\x00\x0a\x00\x03\x00\x76\x65\x74\x68\x31\x00\x00\x00\x30\x00
\x12\x00\x08\x00\x01\x00\x76\x65\x74\x68\x24\x00\x02\x00\x20\x00
\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00
\x00\x00\x0a\x00\x03\x00\x76\x65\x74\x68\x32\x00\x00\x00' >> 
message

 $ python tests/decoder/decoder.py pyroute2.netlink.rtnl.rtmsg.rtmsg message
 5c:00:00:00:10:00:05:06:38:a2:16:5d:00:00:00:00:00:00:00:00:00:00:
 00:00:00:00:00:00:00:00:00:00:0a:00:03:00:76:65:74:68:31:00:00:00:
 30:00:12:00:08:00:01:00:76:65:74:68:24:00:02:00:20:00:01:00:00:00:
 00:00:00:00:00:00:00:00:00:00:00:00:00:00:0a:00:03:00:76:65:74:68:
 32:00:00:00
 {'attrs': [('RTA_UNSPEC', None),
           ('RTA_IIF', 1752458614),
           ('RTA_VIA', {'addr': 
 '01:00:76:65:74:68:24:00:02:00:20:00:01:00:00:00:00:00:00:00:00:
  00:00:00:00:00:00:00:00:00:0a:00:03:00:76:65:74:68:32:00:00:00', 
 'family': 8})],
 'dst_len': 0,
 'family': 0,
 'flags': 0,
 'header': {'flags': 1541,
        'length': 92,
        'pid': 0,
        'sequence_number': 1561764408,
        'type': 16},
 'proto': 0,
 'scope': 0,
 'src_len': 0,
 'table': 0,
 'tos': 0,
 'type': 0}

我期待解码表明有关veth1or的内容veth2,但解码似乎与 veth 设备无关。我确实在相关教程中重复了解码,并且可以得到与教程中相同的结果。我想问一下上面的解码是否正确,如果是,如何解释?

networking netlink
  • 1 个回答
  • 616 Views
Martin Hope
Jake
Asked: 2019-06-19 10:05:32 +0800 CST

Linux 路由选择未采用预期规则

  • 0

我有以下路由规则(使用 显示route -n):

Kernel IP routing table
Destination  Gateway    Genmask         Flags Metric Ref Use Iface
0.0.0.0      10.0.2.1   0.0.0.0         UG    100    0     0 enp0s3
10.0.2.0     0.0.0.0    255.255.255.192 U     100    0     0 enp0s3.100
10.0.2.0     0.0.0.0    255.255.255.0   U     100    0     0 enp0s3
169.254.0.0  0.0.0.0    255.255.0.0     U     1000   0     0 enp0s3

该接口enp0s3.100是 VLAN id 为 100 的接口。

如果我尝试获取 10.0.2.70 的路由,我希望它使用 VLAN 接口,但它没有:

# ip route get 10.0.2.70
10.0.2.70 dev enp0s3  src 10.0.2.11 
    cache

有谁知道为什么这里没有使用最长的前缀匹配?

routing vlan
  • 1 个回答
  • 140 Views
Martin Hope
Jake
Asked: 2019-05-03 11:30:01 +0800 CST

/proc 中的命名空间编号

  • 1

我正在检查与 shell 进程关联的命名空间,如下所示:

# ll /proc/$$/ns
total 0
dr-x--x--x 2 root root 0 May  2 15:10 ./
dr-xr-xr-x 9 root root 0 May  1 18:39 ../
lrwxrwxrwx 1 root root 0 May  2 15:11 cgroup -> cgroup:[4026531835]
lrwxrwxrwx 1 root root 0 May  2 15:11 ipc -> ipc:[4026531839]
lrwxrwxrwx 1 root root 0 May  2 15:11 mnt -> mnt:[4026531840]
lrwxrwxrwx 1 root root 0 May  2 15:11 net -> net:[4026531957]
lrwxrwxrwx 1 root root 0 May  2 15:11 pid -> pid:[4026531836]
lrwxrwxrwx 1 root root 0 May  2 15:11 user -> user:[4026531837]
lrwxrwxrwx 1 root root 0 May  2 15:11 uts -> uts:[4026531838]

我了解这些条目表明进程与哪些名称空间相关联。我想问一下标识每个命名空间的数字来自哪里?

例如,上面的输出表明进程挂载命名空间是mnt:[4026531840]. 我检查了挂载命名空间结构:

 8  struct mnt_namespace {
 9      atomic_t        count;
10      struct ns_common    ns;
11      struct mount *  root;
12      struct list_head    list;
13      struct user_namespace   *user_ns;
14      struct ucounts      *ucounts;
15      u64         seq;    /* Sequence number to prevent loops */
16      wait_queue_head_t poll;
17      u64 event;
18      unsigned int        mounts; /* # of mounts in the namespace */
19      unsigned int        pending_mounts;
20  } __randomize_layout;

我没有看到用作/proc/PID/ns/条目中要使用的标识符的字段。那么这些标识符是如何生成的呢?

namespace
  • 1 个回答
  • 562 Views
Martin Hope
Jake
Asked: 2019-04-21 22:09:47 +0800 CST

为什么 /proc 中的 Linux 命名空间链接是红色的?

  • 0

我检查了 Ubuntu VM 中的符号链接,以查找/proc/PID/ns. 我看到所有链接都是红色的。

在此处输入图像描述

我什至尝试测试 usingunshare以查看是否可以创建新的命名空间。我使用 mount 命名空间进行了测试,并为新进程分配了一个新的命名空间。

root@VM:/# ll /proc/$$/ns
total 0
dr-x--x--x 2 root root 0 Apr 21 01:56 ./
dr-xr-xr-x 9 root root 0 Apr 21 01:56 ../
lrwxrwxrwx 1 root root 0 Apr 21 01:56 cgroup -> cgroup:[4026531835]
lrwxrwxrwx 1 root root 0 Apr 21 01:56 ipc -> ipc:[4026531839]
lrwxrwxrwx 1 root root 0 Apr 21 01:56 ** mnt -> mnt:[4026531840] **
lrwxrwxrwx 1 root root 0 Apr 21 01:56 net -> net:[4026531957]
lrwxrwxrwx 1 root root 0 Apr 21 01:56 pid -> pid:[4026531836]
lrwxrwxrwx 1 root root 0 Apr 21 01:56 user -> user:[4026531837]
lrwxrwxrwx 1 root root 0 Apr 21 01:56 uts -> uts:[4026531838]
root@VM:/# 
root@VM:/# unshare --mount
root@VM:/# 
root@VM:/# ll /proc/$$/ns
total 0
dr-x--x--x 2 root root 0 Apr 21 01:56 ./
dr-xr-xr-x 9 root root 0 Apr 21 01:56 ../
lrwxrwxrwx 1 root root 0 Apr 21 01:56 cgroup -> cgroup:[4026531835]
lrwxrwxrwx 1 root root 0 Apr 21 01:56 ipc -> ipc:[4026531839]
lrwxrwxrwx 1 root root 0 Apr 21 01:56 ** mnt -> mnt:[4026532226] **
lrwxrwxrwx 1 root root 0 Apr 21 01:56 net -> net:[4026531957]
lrwxrwxrwx 1 root root 0 Apr 21 01:56 pid -> pid:[4026531836]
lrwxrwxrwx 1 root root 0 Apr 21 01:56 user -> user:[4026531837]
lrwxrwxrwx 1 root root 0 Apr 21 01:56 uts -> uts:[4026531838]

谁能说出为什么符号链接是红色的?这是否意味着命名空间功能不起作用?

symlink proc
  • 1 个回答
  • 687 Views
Martin Hope
Jake
Asked: 2019-04-18 07:43:57 +0800 CST

LXC 如何设置它的根挂载点?

  • 3

我正在尝试在 Ubuntu 中使用挂载命名空间。到目前为止,我可以使用以下命令创建一个空的挂载命名空间:

# mkdir test
# unshare --mount
# mount none test -t tmpfs
# cd test
# pivot_root . . 
# cd / <--- test becomes /

当我检查LXCUbuntu 容器时,该mount命令显示以下内容:

在此处输入图像描述

由于挂载命名空间最初获取了挂载点的副本,因此我假设/dev/sda1容器内部是全局的/dev/sda1(因为/dev/sda1一旦启动,容器内部就没有了),但/容器内部的内容对应于它的 rootfs。熟悉 LXC 的人能否解释一下 LXCpivot_root在容器内执行之前会执行哪些挂载操作?

mount lxc
  • 1 个回答
  • 1238 Views
Martin Hope
Jake
Asked: 2019-04-11 14:04:09 +0800 CST

为什么 unshare 二进制调用 clone() 这么多次?

  • 0

我正在尝试unshare在 Linux 中测试该命令。我正在使用它来创建一个新的用户命名空间。我尝试了以下测试:

user1@myPC$ strace -e clone,unshare,fork,execve unshare --user
execve("/usr/bin/unshare", ["unshare", "--user"], [/* 71 vars */]) = 0
unshare(CLONE_NEWUSER)                  = 0
execve("/bin/bash", ["-bash"], [/* 71 vars */]) = 0
clone(child_stack=0, flags=CLONE_CHILD_CLEARTID|CLONE_CHILD_SETTID|SIGCHLD, child_tidptr=0xb7275768) = 9153
--- SIGCHLD {si_signo=SIGCHLD, si_code=CLD_EXITED, si_pid=9153, si_uid=65534, si_status=0, si_utime=0, si_stime=0} ---
clone(child_stack=0, flags=CLONE_CHILD_CLEARTID|CLONE_CHILD_SETTID|SIGCHLD, child_tidptr=0xb7275768) = 9155
--- SIGCHLD {si_signo=SIGCHLD, si_code=CLD_EXITED, si_pid=9155, si_uid=65534, si_status=0, si_utime=0, si_stime=0} ---
clone(child_stack=0, flags=CLONE_CHILD_CLEARTID|CLONE_CHILD_SETTID|SIGCHLD, child_tidptr=0xb7275768) = 9160
--- SIGCHLD {si_signo=SIGCHLD, si_code=CLD_EXITED, si_pid=9160, si_uid=65534, si_status=0, si_utime=0, si_stime=0} ---
clone(child_stack=0, flags=CLONE_CHILD_CLEARTID|CLONE_CHILD_SETTID|SIGCHLD, child_tidptr=0xb7275768) = 9162
--- SIGCHLD {si_signo=SIGCHLD, si_code=CLD_EXITED, si_pid=9162, si_uid=65534, si_status=0, si_utime=0, si_stime=0} ---
clone(child_stack=0, flags=CLONE_CHILD_CLEARTID|CLONE_CHILD_SETTID|SIGCHLD, child_tidptr=0xb7275768) = 9164
--- SIGCHLD {si_signo=SIGCHLD, si_code=CLD_EXITED, si_pid=9164, si_uid=65534, si_status=0, si_utime=0, si_stime=0} ---
clone(child_stack=0, flags=CLONE_CHILD_CLEARTID|CLONE_CHILD_SETTID|SIGCHLD, child_tidptr=0xb7275768) = 9167
--- SIGCHLD {si_signo=SIGCHLD, si_code=CLD_EXITED, si_pid=9167, si_uid=65534, si_status=0, si_utime=0, si_stime=0} ---
nobody@MyPC:~$

我想问为什么有这么多的电话clone()打?

namespace unshare
  • 1 个回答
  • 293 Views
Martin Hope
Jake
Asked: 2019-03-26 11:54:14 +0800 CST

使用 iptables 和 DNAT 更改目标 IP 地址

  • 0

我正在尝试在 PREROUTING 中使用 DNAT。我在这里找到了一个教程。它包含以下句子:

这是在 PREROUTING 链中完成的,就像数据包进来一样;这意味着 Linux 机器本身上的任何其他东西(路由、数据包过滤)都会看到数据包到达它的“真实”目的地。

我想问作者最后一部分是什么意思anything else on the Linux box itself will see the packet going to its 'real' destination?

我尝试了一个测试,其中我有一个虚拟设备(tap)并将传入的 ICMP 数据包重定向到该 tap 设备(我的 tap 设备地址是10.0.4.1/24并且有一个程序正在侦听 tap 设备,所以它的状态是 UP):

# iptables -t nat -A PREROUTING -i eth0 -p icmp -j DNAT --to-destination 10.0.4.2

当我 ping 一个外部 IP 时,这个规则永远不会被使用(这个规则pkts在 iptables 中的计数保持为 0)。这个观察与作者所说的有关吗?

iptables nat
  • 1 个回答
  • 5084 Views
Martin Hope
Jake
Asked: 2018-08-28 23:47:07 +0800 CST

Linux - 为什么 su 和 sudo 二进制文件需要设置 UID root?

  • 1

我正在尝试找到所述问题的正确原因。我的理解是:

  • sudo需要读取/etc/sudoers只能由root读取的文件,这就是为什么它需要设置-UID root
  • su将创建一个具有不同真实有效 UID 的新 shell,并且需要检查密码。要检查密码,它需要读取/etc/shadow,这就是为什么它需要设置 UID root。检查密码后,它需要调用setuid()分叉的进程,并且要使用任意 UID 参数,其父进程必须具有 root 作为有效 UID,所以这也是另一个原因。

以上理由正确吗?

sudo su
  • 1 个回答
  • 545 Views

Sidebar

Stats

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

    模块 i915 可能缺少固件 /lib/firmware/i915/*

    • 3 个回答
  • Marko Smith

    无法获取 jessie backports 存储库

    • 4 个回答
  • Marko Smith

    如何将 GPG 私钥和公钥导出到文件

    • 4 个回答
  • Marko Smith

    我们如何运行存储在变量中的命令?

    • 5 个回答
  • Marko Smith

    如何配置 systemd-resolved 和 systemd-networkd 以使用本地 DNS 服务器来解析本地域和远程 DNS 服务器来解析远程域?

    • 3 个回答
  • Marko Smith

    dist-upgrade 后 Kali Linux 中的 apt-get update 错误 [重复]

    • 2 个回答
  • Marko Smith

    如何从 systemctl 服务日志中查看最新的 x 行

    • 5 个回答
  • Marko Smith

    Nano - 跳转到文件末尾

    • 8 个回答
  • Marko Smith

    grub 错误:你需要先加载内核

    • 4 个回答
  • Marko Smith

    如何下载软件包而不是使用 apt-get 命令安装它?

    • 7 个回答
  • Martin Hope
    user12345 无法获取 jessie backports 存储库 2019-03-27 04:39:28 +0800 CST
  • Martin Hope
    Carl 为什么大多数 systemd 示例都包含 WantedBy=multi-user.target? 2019-03-15 11:49:25 +0800 CST
  • Martin Hope
    rocky 如何将 GPG 私钥和公钥导出到文件 2018-11-16 05:36:15 +0800 CST
  • Martin Hope
    Evan Carroll systemctl 状态显示:“状态:降级” 2018-06-03 18:48:17 +0800 CST
  • Martin Hope
    Tim 我们如何运行存储在变量中的命令? 2018-05-21 04:46:29 +0800 CST
  • Martin Hope
    Ankur S 为什么 /dev/null 是一个文件?为什么它的功能不作为一个简单的程序来实现? 2018-04-17 07:28:04 +0800 CST
  • Martin Hope
    user3191334 如何从 systemctl 服务日志中查看最新的 x 行 2018-02-07 00:14:16 +0800 CST
  • Martin Hope
    Marko Pacak Nano - 跳转到文件末尾 2018-02-01 01:53:03 +0800 CST
  • Martin Hope
    Kidburla 为什么真假这么大? 2018-01-26 12:14:47 +0800 CST
  • Martin Hope
    Christos Baziotis 在一个巨大的(70GB)、一行、文本文件中替换字符串 2017-12-30 06:58:33 +0800 CST

热门标签

linux bash debian shell-script text-processing ubuntu centos shell awk ssh

Explore

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

Footer

AskOverflow.Dev

关于我们

  • 关于我们
  • 联系我们

Legal Stuff

  • Privacy Policy

Language

  • Pt
  • Server
  • Unix

© 2023 AskOverflow.DEV All Rights Reserve