虚拟网卡接口在 ifconfig 命令中不可见

虚拟网卡接口在 ifconfig 命令中不可见

我想为enp1s0创建一个虚拟接口,这样我就可以拥有多个IP地址。我运行了以下命令:

# ifconfig enp1s0 192.168.0.2 netmask 255.255.255.0 up
# ifconfig enp1s0:0 192.168.0.3 netmask 255.255.255.240 up
# route add default gw 192.168.0.1 enp1s0

Ping 到两个 IP 地址都工作正常。

enp1s0    Link encap:Ethernet  HWaddr 3C:E1:A1:3F:21:3F  
          inet addr:192.168.0.2  Bcast:192.168.0.255  Mask:255.255.255.0
          inet6 addr: fe80::3ee1:a1ff:fe3f:213f/64 Scope:Link
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
          RX packets:118 errors:0 dropped:0 overruns:0 frame:0
          TX packets:97 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1000 
          RX bytes:13707 (13.3 KiB)  TX bytes:19818 (19.3 KiB)

enp1s0:0  Link encap:Ethernet  HWaddr 3C:E1:A1:3F:21:3F  
          inet addr:192.168.0.3  Bcast:192.168.0.15  Mask:255.255.255.240
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1

enp2s0    Link encap:Ethernet  HWaddr 3C:E1:A1:3F:F8:17  
          UP BROADCAST MULTICAST  MTU:1500  Metric:1
          RX packets:0 errors:0 dropped:0 overruns:0 frame:0
          TX packets:0 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1000 
          RX bytes:0 (0.0 B)  TX bytes:0 (0.0 B)

然后,我在 /etc/systemd/network 中创建了一个文件: enp1s0.network ,其中包含以下内容:

[Match]
Name=enp1s0

[Network]
Address=192.168.0.2/24
Address=192.168.0.3/28
Gateway=192.168.0.1

两个 IP 地址上的 Ping 工作正常,但我在运行 ifconfig 命令时看不到虚拟接口。当我运行上述一系列 ifconfig 命令时,我可以看到它们。如何实现类似的输出

ifconfig 
enp1s0    Link encap:Ethernet  HWaddr 3C:E1:A1:3F:21:3F  
          inet addr:192.168.0.2  Bcast:192.168.0.255  Mask:255.255.255.0
          inet6 addr: fe80::3ee1:a1ff:fe3f:213f/64 Scope:Link
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
          RX packets:264 errors:0 dropped:3 overruns:0 frame:0
          TX packets:155 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1000 
          RX bytes:29991 (29.2 KiB)  TX bytes:27216 (26.5 KiB)

enp2s0    Link encap:Ethernet  HWaddr 3C:E1:A1:3F:F8:17  
          UP BROADCAST MULTICAST  MTU:1500  Metric:1
          RX packets:0 errors:0 dropped:0 overruns:0 frame:0
          TX packets:0 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1000 
          RX bytes:0 (0.0 B)  TX bytes:0 (0.0 B)

lo        Link encap:Local Loopback  
          inet addr:127.0.0.1  Mask:255.0.0.0
          inet6 addr: ::1/128 Scope:Host
          UP LOOPBACK RUNNING  MTU:65536  Metric:1
          RX packets:128 errors:0 dropped:0 overruns:0 frame:0
          TX packets:128 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1000 
          RX bytes:8528 (8.3 KiB)  TX bytes:8528 (8.3 KiB)

相关内容