大网数据广告活动
服务器运维问答

the wireguard not listening on port after started

· 52CE 我爱测

I am starting the wireguard using this command: wg-quick up wg0 this is whe wireguard status: and using this command to see the listening port: lsof -i:7456 why the wireguard not listening on port? Is wireguard successful config?

问题原文

原帖链接 · Dolphin · CC BY-SA 4.0

I am starting the wireguard using this command:

wg-quick up wg0

this is whe wireguard status:

and using this command to see the listening port:

lsof -i:7456

why the wireguard not listening on port? Is wireguard successful config?

已采纳解答

原帖链接 · A.B · CC BY-SA 4.0

I will assume that this is done on Linux, since not told otherwise and because of container context.

The description of lsof tells:

DESCRIPTION

Lsof revision 4.91 lists on its standard output file information about files opened by processes for the following UNIX dialects:

  • Apple Darwin 9 and Mac OS X 10.[567]
  • FreeBSD 8.[234], 9.0 and 1[012].0 for AMD64-based systems
  • Linux 2.1.72 and above for x86-based systems
  • Solaris 9, 10 and 11

On Linux, WireGuard is not a standard process, but a network driver handled by the kernel. Even if in the end this might create a kernel thread appearing in the process list, this "process" would be special and would not give any information available about its open file descriptors (if such concept makes any sense for a kernel thread anyway).

Thus lsof cannot find such information and will always return an empty result.

Yet a command like netstat -nul | grep -w 7456 or ss -nul sport = :7456 would still display it, where it was created (see later), because it's only querying kernel network APIs (resp. /proc/net/udp{,6} or netlink/sock_diag) to know about listening ports, rather than cross referencing informations from the kernel process API with thsoe from the network API.

That being said, this is only valid if the command wg-quick up wg0 was run in the specific container the interface is used in after. If it was run on the host, and after this the creation of a container "stole" it, all bets are off. That's because WireGuard is designed to work along network namespaces (ie containers). It's completely possible, and documented, to create the WireGuard interface in a network namespace (eg the initial host namespace), and move it to an other network namespace:

Ready for Containers

WireGuard sends and receives encrypted packets using the network namespace in which the WireGuard interface was originally created. This means that you can create the WireGuard interface in your main network namespace, which has access to the Internet, and then move it into a network namespace belonging to a Docker container as that container's only interface. This ensures that the only possible way that container is able to access the network is through a secure encrypted WireGuard tunnel.

That means if the interface is moved, the listening port will stay in the previous (probably initial host's) network namespace and will be invisible in the network namespace where the interface arrives. In such case the listening port 7456/UDP wouldn't be visible in the container, but would be on the host (or wherever it was initially created). Note also that WireGuard will listen (still only in the original network namespace) only if the interface is administratively up (ip link set wg0 up). Bringing it down removes temporarily the listening port.

摘自公开归档,保留原文语言,版式经整理,外部媒体与邮箱地址已移除。

资料来源与适用范围

资料来源
Server Fault
适用范围
以原帖系统、软件版本与发布日期为准(2020-05-02)
内容语言
中文;命令、路径和错误标识保留技术原文
本地收录日期
2026-11-15
授权说明
CC BY-SA 4.0

正文与所需资源由本站本地存储。查看来源及更新记录 ↗

请按适用版本和实际日志确认原因;本站没有对每一种系统或设备逐项执行文中的操作。