为什么根据重启接口会被重命名?!同样的卡,同样的 PCIe 连接器,网络接口毫无理由地enp3s0f0
变成了现在的样子。enp3s0f0np0
如何停止这种荒唐事?
RHEL 8
为什么根据重启接口会被重命名?!同样的卡,同样的 PCIe 连接器,网络接口毫无理由地enp3s0f0
变成了现在的样子。enp3s0f0np0
如何停止这种荒唐事?
RHEL 8
我在 Pardus 23.2(基于 Debian 12)上使用 Veyon(本地网络中的客户端计算机控制软件)软件。必须打开网络连接才能使此程序运行。但是,有些学生会关闭网络连接。我该如何防止这种情况发生?
我正在使用全新安装的 Ubuntu 服务器 24.04.1 LTS。我以 root 身份运行以下命令来设置网络并进行一些实验:
apt install -y netcat-traditional tcpdump inetutils-ping
ip netns add ns1
ip netns add ns2
ip link add my_veth1 type veth peer name my_veth2
ip link set my_veth1 up netns ns1
ip link set my_veth2 up netns ns2
ip -n ns1 address add 1.2.3.4 dev my_veth1
ip -n ns1 route add 2.3.4.0/24 dev my_veth1
ip -n ns2 address add 2.3.4.5 dev my_veth2
然后我在不同的终端运行这些命令:
# Terminal 1
ip netns exec ns1 tcpdump -l -i my_veth1
# Terminal 2
ip netns exec ns2 tcpdump -l -i my_veth2
# Terminal 3
ip netns exec ns1 ping 2.3.4.5
我在终端 1 和 2 上得到了相同的输出:
02:40:27.511438 ARP, Request who-has 2.3.4.5 tell 1.2.3.4, length 28
02:40:27.511438 ARP, Request who-has 2.3.4.5 tell 1.2.3.4, length 28
02:40:27.511438 ARP, Request who-has 2.3.4.5 tell 1.2.3.4, length 28
...
veth2
具有 IP 地址 2.3.4.5 并正在接收 ARP 请求。为什么它不发送答复?只有当我配置路由表条目时它才会应答:
ip -n ns2 route add 1.2.3.0/24 dev my_veth2
但这不是必需的,因为veth2
应该响应的网络接口的 MAC 地址已经在其响应的请求中编码了。
我有一台装有 Debian 12 的笔记本电脑,根据 powertop 显示,Realtek 以太网控制器的功耗约为 10W:
Power est. Usage Events/s Category Description
11.9 W 0.0 pkts/s Device Network interface: enp4s0 (r8168)
92.7 mW 97.5 ms/s 191.0 Process [PID 35665] /usr/lib/xorg/Xorg vt3 -displayfd 3 -auth /run/user/1000/gdm/Xauthority -nolisten tcp -background none -noreset -ke
84.2 mW 88.6 ms/s 15.4 Process [PID 36881] /usr/libexec/gnome-terminal-server
即使设备已关闭,仍会消耗电力:
$ ip a
2: enp4s0: <NO-CARRIER,BROADCAST,MULTICAST,UP> mtu 1500 qdisc fq_codel state DOWN group default qlen 1000
link/ether a8:3e:43:5d:a5:1a brd ff:ff:ff:ff:ff:ff
有什么方法可以完全禁用该设备或至少降低功耗?
一些额外的诊断:
$ lspci | grep -i "Ethernet"
04:00.0 Ethernet controller: Realtek Semiconductor Co., Ltd. RTL8111/8168/8411 PCI Express Gigabit Ethernet Controller (rev 15)
$ nmcli device show enp4s0
GENERAL.DEVICE: enp4s0
GENERAL.TYPE: ethernet
GENERAL.HWADDR: A8:3E:43:5D:A5:1A
GENERAL.MTU: 1500
GENERAL.STATE: 20 (unavailable)
GENERAL.CONNECTION: --
GENERAL.CON-PATH: --
WIRED-PROPERTIES.CARRIER: off
IP4.GATEWAY: --
IP6.GATEWAY: --
我想在网络接口上配置单个 SR-IOV VF。我使用下面列出的配置让它工作,但是如果我尝试在 PF 之后过早启动 VF,我会收到错误,因为 VF 尚未准备好。我可以创建一个 shell 脚本来循环并等待 VF 准备就绪,但这感觉有点像 hack。有没有办法以更规范的方式处理这种设备相互依赖性?
以下是我正在使用的 NetworkManager 配置:
SR-IOV PV:/etc/NetworkManager/system-connections/sriovPF.nmconnection
[connection]
id=sriovPF
uuid=da82bf14-4af6-4cf6-a091-00d5ea1e73bc
type=ethernet
interface-name=enp216s0f1
[ethernet]
[sriov]
total-vfs=64
vf.0=spoof-check=true vlans=100
[ipv4]
method=disabled
[ipv6]
addr-gen-mode=default
method=disabled
[proxy]
SR-IOV VF:/etc/NetworkManager/system-connections/sriovPFv0.nmconnection
[connection]
id=sriovPFv0
uuid=0f0876aa-0aae-44e3-8360-acfc3ba194ce
type=ethernet
autoconnect=false
interface-name=enp216s0f1v0
[ethernet]
[ipv4]
address1=192.168.2.10/30
method=manual
[ipv6]
addr-gen-mode=default
method=disabled
[proxy]
如果我尝试在 PF 之后过早启动 VF,则会出现以下错误:
$ nmcli con up sriovPF
Connection successfully activated (D-Bus active path: /org/freedesktop/NetworkManager/ActiveConnection/14)
$ sudo nmcli con up sriovPFv0
Error: Connection activation failed: No suitable device found for this connection (device br0 not available because profile is not compatible with device (mismatching interface name)).
(wait 1 min)
$ nmcli con up sriovPFv0
Connection successfully activated (D-Bus active path: /org/freedesktop/NetworkManager/ActiveConnection/16)
这是一个奇怪的错误,br0
与 SR-IOV 接口无关!如果我等一分钟再试,VF 接口就会出现,不会出现错误。
给出的任何解决方案都不需要使用 NetworkManager。我很乐意考虑使用其他东西来配置网络(例如 systemd-networkd)。
我ap0
配置了一个接口,该接口systemd-networkd
旨在由应用程序动态启用/禁用。我希望这个应用程序ap0
也能绑定到与之关联的 IP 地址。但是,如果应用程序禁用该ap0
接口,则其绑定自然会失败。
ap0
有没有一种方法可以让我的应用程序保持与其地址的绑定,并且该地址在启动和关闭时保持可绑定,但在ap0
启动时可用?我一直在尝试网络绑定和桥接,但效果并不理想。
我最近从运行 Runit 的 Artix Linux 系统中删除了 NetworkManager,现在我无法连接到互联网。我尝试了几种解决方案,但都没有成功。到目前为止,这是我尝试过的:
我被困在这一点上,不知道如何继续。有关解决此问题的任何指导。谢谢
在 WSL2 之上运行 Ubuntu 22.04.3 LTS
输出ifconfig
:
eth0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1492
inet 172.28.193.11 netmask 255.255.240.0 broadcast 172.28.207.255
inet6 fe80::215:5dff:fe3e:7ffa prefixlen 64 scopeid 0x20<link>
ether 00:15:5d:3e:7f:fa txqueuelen 1000 (Ethernet)
RX packets 1402 bytes 590609 (590.6 KB)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 163 bytes 52446 (52.4 KB)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
lo: flags=73<UP,LOOPBACK,RUNNING> mtu 65536
inet 127.0.0.1 netmask 255.0.0.0
inet6 ::1 prefixlen 128 scopeid 0x10<host>
loop txqueuelen 1000 (Local Loopback)
RX packets 0 bytes 0 (0.0 B)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 0 bytes 0 (0.0 B)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
ipconfig /all
PowerShell的输出(请原谅我的机器是法语):
Configuration IP de Windows
Nom de l’hôte . . . . . . . . . . : Zenbook-OZ
Suffixe DNS principal . . . . . . :
Type de noeud. . . . . . . . . . : Hybride
Routage IP activé . . . . . . . . : Non
Proxy WINS activé . . . . . . . . : Non
Liste de recherche du suffixe DNS.: Speedport_W_724V_01011603_07_008
Carte réseau sans fil Connexion au réseau local* 1 :
Statut du média. . . . . . . . . . . . : Média déconnecté
Suffixe DNS propre à la connexion. . . :
Description. . . . . . . . . . . . . . : Microsoft Wi-Fi Direct Virtual Adapter
Adresse physique . . . . . . . . . . . : 3E-55-76-BE-66-95
DHCP activé. . . . . . . . . . . . . . : Oui
Configuration automatique activée. . . : Oui
Carte réseau sans fil Connexion au réseau local* 2 :
Statut du média. . . . . . . . . . . . : Média déconnecté
Suffixe DNS propre à la connexion. . . :
Description. . . . . . . . . . . . . . : Microsoft Wi-Fi Direct Virtual Adapter #2
Adresse physique . . . . . . . . . . . : 3E-55-76-BE-76-85
DHCP activé. . . . . . . . . . . . . . : Oui
Configuration automatique activée. . . : Oui
Carte réseau sans fil Wi-Fi :
Suffixe DNS propre à la connexion. . . : Speedport_W_724V_01011603_07_008
Description. . . . . . . . . . . . . . : MediaTek Wi-Fi 6E MT7922 (RZ616) 160MHz Wireless LAN Card
Adresse physique . . . . . . . . . . . : 3C-55-76-BE-46-B5
DHCP activé. . . . . . . . . . . . . . : Oui
Configuration automatique activée. . . : Oui
Adresse IPv6. . . . . . . . . . . . . .: 2003:c5:c715:bad9:aa0e:5e09:f399:6903(préféré)
Adresse IPv6 temporaire . . . . . . . .: 2003:c5:c715:bad9:fc98:b63c:31e6:1374(préféré)
Adresse IPv6. . . . . . . . . . . . . .: 2003:c5:c715:badb:904b:d90b:7543:f858(déprécié)
Adresse IPv6 de liaison locale. . . . .: fe80::f215:b016:e094:6711%13(préféré)
Adresse IPv4. . . . . . . . . . . . . .: 192.168.2.106(préféré)
Masque de sous-réseau. . . . . . . . . : 255.255.255.0
Bail obtenu. . . . . . . . . . . . . . : mercredi 13 mars 2024 01:52:12
Bail expirant. . . . . . . . . . . . . : jeudi 4 avril 2024 00:38:51
Passerelle par défaut. . . . . . . . . : fe80::1%13
192.168.2.1
Serveur DHCP . . . . . . . . . . . . . : 192.168.2.1
IAID DHCPv6 . . . . . . . . . . . : 121394550
DUID de client DHCPv6. . . . . . . . : 00-01-00-01-2C-2A-D6-E9-00-4C-E0-86-43-54
Serveurs DNS. . . . . . . . . . . . . : fe80::1%13
192.168.2.1
NetBIOS sur Tcpip. . . . . . . . . . . : Activé
Carte Ethernet Connexion réseau Bluetooth :
Statut du média. . . . . . . . . . . . : Média déconnecté
Suffixe DNS propre à la connexion. . . :
Description. . . . . . . . . . . . . . : Bluetooth Device (Personal Area Network)
Adresse physique . . . . . . . . . . . : 3C-55-76-BE-46-B6
DHCP activé. . . . . . . . . . . . . . : Oui
Configuration automatique activée. . . : Oui
Carte Ethernet vEthernet (WSL (Hyper-V firewall)) :
Suffixe DNS propre à la connexion. . . :
Description. . . . . . . . . . . . . . : Hyper-V Virtual Ethernet Adapter
Adresse physique . . . . . . . . . . . : 00-15-5D-AE-85-70
DHCP activé. . . . . . . . . . . . . . : Non
Configuration automatique activée. . . : Oui
Adresse IPv6 de liaison locale. . . . .: fe80::5516:60d0:65b2:eb67%35(préféré)
Adresse IPv4. . . . . . . . . . . . . .: 172.28.192.1(préféré)
Masque de sous-réseau. . . . . . . . . : 255.255.240.0
Passerelle par défaut. . . . . . . . . :
IAID DHCPv6 . . . . . . . . . . . : 587208029
DUID de client DHCPv6. . . . . . . . : 00-01-00-01-2C-2A-D6-E9-00-4C-E0-86-43-54
NetBIOS sur Tcpip. . . . . . . . . . . : Activé
我的问题:
我不明白 IP 地址172.28.193.11
(在输出 ifconfig 中分配给 eth0)来自哪里。00:15:5d:3e:7f:fa
与eth0
in关联的MAC 地址ifconfig
不会出现在ipconfig /all
PowerShell 输出中的任何位置。
MAC 地址对应哪个网络接口00:15:5d:3e:7f:fa
?
在 Red Hat Enterprise Linux (RHEL) 8 中,如果有人这样做ifconfig eth0 hw ether abcd12341234
,
我所知道ifconfig
的是ip -a
,
那么有没有一种方法可以可靠地获取 eth0 接口的真实 MAC 地址,如果可以的话如何获取?...除了重新启动到来自可靠来源的 Linux Live CD 以外,以确保接口的 MAC 地址没有更改。
我有两个正在运行的 Docker 容器(Ubuntu 22.04)。他们位于同一网络上,因此可以互相交谈(我已经用 验证了这一点nc
)。在第一个容器中,我运行了一个程序,该程序创建了一个 tun 设备,为其指定了 IPv4 地址,然后将其启动。 ip addr
节目
4: tun0: <POINTOPOINT,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UNKNOWN group default qlen 500
link/none
inet 5.6.7.8/32 scope global tun0
valid_lft forever preferred_lft forever
89: eth0@if90: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc noqueue state UP group default
link/ether 02:42:c0:a8:30:02 brd ff:ff:ff:ff:ff:ff link-netnsid 0
inet 192.168.48.2/20 brd 192.168.63.255 scope global eth0
valid_lft forever preferred_lft forever
然后,我的程序将 TCP SYN 数据包写入 tun 设备,源 IP 为 5.6.7.8,目标 IP 为 192.168.48.3(另一个容器)。然而,数据包永远不会到达另一个容器。我已经运行tcpdump
,数据包出现在tun0
界面上,但没有出现在eth0
. tcpdump
另一个容器上显示没有数据包到达。
为什么数据包不会被路由通过eth0
?
当我通过启动容器时docker-compose
,我设置了
sysctls:
- net.ipv4.ip_forward=1
对于第一个容器。
我还设置了 NAT:
iptables -I FORWARD -i tun0 -o eth0 -j ACCEPT
iptables -I FORWARD -i eth0 -o tun0 -m state --state RELATED,ESTABLISHED -j ACCEPT
iptables -t nat -I POSTROUTING -o eth0 -j MASQUERADE
以下是重新创建我正在做的事情的方法:
Dockerfile:
FROM ubuntu:22.04
RUN apt -y update && \
apt -y install build-essential iptables tcpdump
WORKDIR /app
发射.c:
#include <arpa/inet.h>
#include <fcntl.h>
#include <linux/if_tun.h>
#include <net/if.h>
#include <netinet/in.h>
#include <signal.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/ioctl.h>
#include <sys/socket.h>
#include <sys/types.h>
#include <unistd.h>
#define TUN_DEVICE "tun0"
#define SOURCE_IP "5.6.7.8"
#define DESTINATION_IP "192.168.48.3" // change to the actual address
unsigned char packet[] = {
0x45, 0x00, 0x00, 0x54, 0x3a, 0x58, 0x40, 0x00, 0x40, 0x01, 0x03, 0x9d,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x08, 0x00, 0x48, 0xc1,
0x00, 0x03, 0x00, 0x01, 0xa1, 0x81, 0x3a, 0x65, 0x00, 0x00, 0x00, 0x00,
0x0d, 0x81, 0x07, 0x00, 0x00, 0x00, 0x00, 0x00, 0x10, 0x11, 0x12, 0x13,
0x14, 0x15, 0x16, 0x17, 0x18, 0x19, 0x1a, 0x1b, 0x1c, 0x1d, 0x1e, 0x1f,
0x20, 0x21, 0x22, 0x23, 0x24, 0x25, 0x26, 0x27, 0x28, 0x29, 0x2a, 0x2b,
0x2c, 0x2d, 0x2e, 0x2f, 0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37
};
/*
Note: The IPv4 checksum will be wrong. Run this program once and cause it to emit
the packet by sending the process SIGUSR1. Capture the packet with tcpdump which
will tell you that the checksum is wrong and what it should be. The result goes
at offset 10 in the packet.
*/
int tun_fd = -1;
void signal_handler(int signum)
{
(void)signum;
dprintf(STDOUT_FILENO, "Emitting packet\n");
if ( write(tun_fd, packet, sizeof(packet)) < 0 ) {
_exit(1);
}
}
int set_address_and_bring_up(void)
{
int ret = -1, sock;
struct ifreq ifr = {.ifr_name = TUN_DEVICE};
struct sockaddr_in addr = {.sin_family = AF_INET};
inet_pton(AF_INET, SOURCE_IP, &addr.sin_addr);
memcpy(&ifr.ifr_addr, &addr, sizeof(addr));
sock = socket(AF_INET, SOCK_DGRAM, 0);
if ( sock < 0 ) {
perror("socket");
return -1;
}
if ( ioctl(sock, SIOCSIFADDR, &ifr) == -1 ) {
perror("ioctl (SIOCSIFADDR)");
goto done;
}
ifr.ifr_flags = IFF_UP;
if ( ioctl(sock, SIOCSIFFLAGS, &ifr) == -1 ) {
perror("ioctl (SIOCSIFFLAGS)");
goto done;
}
ret = 0;
done:
close(sock);
return ret;
}
int tun_device_create(void) {
int fd;
struct ifreq ifr = {.ifr_name = TUN_DEVICE, .ifr_flags = IFF_TUN | IFF_NO_PI};
fd = open("/dev/net/tun", O_RDWR);
if ( fd < 0 ) {
perror("open");
return -1;
}
if ( ioctl(fd, TUNSETIFF, &ifr) == -1 ) {
perror("ioctl (TUNSETIFF)");
goto error;
}
if ( set_address_and_bring_up() != 0 ) {
goto error;
}
return fd;
error:
close(fd);
return -1;
}
int main() {
struct sigaction action = {.sa_handler = signal_handler};
inet_pton(AF_INET, SOURCE_IP, packet + 12);
inet_pton(AF_INET, DESTINATION_IP, packet + 16);
tun_fd = tun_device_create();
if ( tun_fd < 0 ) {
return 1;
}
sigaction(SIGUSR1, &action, NULL);
while (1) {
pause();
}
return 0;
}
iptables_script.sh:
#!/bin/sh -ex
iptables -I FORWARD -i tun0 -o eth0 -j ACCEPT
iptables -I FORWARD -i eth0 -o tun0 -m state --state RELATED,ESTABLISHED -j ACCEPT
iptables -t nat -I POSTROUTING -o eth0 -j MASQUERADE
启动容器:
# First container
docker run --rm -it --cap-add NET_ADMIN -v $PWD:/app --device=/dev/net/tun my_image bash
# Second container
docker run --rm -it ubuntu:22.04 bash
在第一个容器中运行:
test "`cat /proc/sys/net/ipv4/ip_forward`" -eq 1
gcc emit.c
./a.out &
./iptables_script.sh
kill -s USR1 `pgrep a.out`