我试图找出如何在Linux机器上设置两个逻辑网络接口(在一个物理接口上),其中包含不同的MAC地址。
我的第一次尝试是使用看来一开始起作用的macvlan:
[root@localhost ~]# ip link add link enp0s3 name veth0 type macvlan
[root@localhost ~]# ip link set veth0 up
[root@localhost ~]# dhclient veth0
[root@localhost ~]# ifconfig
enp0s3: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500
inet 192.168.1.6 netmask 255.255.255.0 broadcast 192.168.1.255
inet6 fe80::a00:27ff:fe3b:d08b prefixlen 64 scopeid 0x20<link>
ether 08:00:27:3b:d0:8b txqueuelen 1000 (Ethernet)
RX packets 356 bytes 58787 (57.4 KiB)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 210 bytes 24203 (23.6 KiB)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
veth0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500
inet 192.168.1.11 netmask 255.255.255.0 broadcast 192.168.1.255
inet6 fe80::2462:42ff:fecb:5090 prefixlen 64 scopeid 0x20<link>
ether 26:62:42:cb:50:90 txqueuelen 0 (Ethernet)
RX packets 83 bytes 9099 (8.8 KiB)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 34 bytes 3871 (3.7 KiB)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0但是,当从另一台计算机扫描本地网络时,两个接口(192.168.1.6和192.168.1.11)显示具有相同的MAC地址08:00:27:3b:d0:8b。
如果可能的话有什么想法吗?如果我不能为此目的使用macvlan又有什么用呢?
谢谢。
编辑:
按照Otheus的建议,我和以前一样尝试了这些设置。
sysctl -w net.ipv4.conf.all.arp_ignore=1
sysctl -w net.ipv4.conf.all.arp_announce=2这显然使接口只能响应那些被明确定向到它们的arp请求。
在我的设置中,这导致DHCP请求失败,无法将IP地址分配给veth0。使用veth0上的静态IP地址,我无法从网络中的其他主机访问这个地址(我尝试了arp/nmap/ping)。
我(初步的)结论是,在同一子网上不可能有一个具有不同MAC地址的虚拟接口。但是,我仍然想知道macvlan的确切用途是什么,以及为什么我在本地机器(我在这里设置虚拟接口)上看到了带有自己MAC地址的虚拟接口,而不是其他机器。
https://serverfault.com/questions/682311
复制相似问题