Can mac-vlan use special MAC Address send packege?

61 views Asked by At

I'm using mac-valn to create virtual NIC and send package

Here is the network

       20.0.0.25/24              20.0.0.26/24
 ----- ens10        ---------     ens4  -----
| PC1 |  ----------| VSwitch |--------| PC2 |
|     |            |         |        |     |
 -----              ---------          ------

Here is the command I use:

ip link add link ens10 ens10.1 type macvlan
ip addr add 20.0.0.100/24 dev ens10.1
ip link set dev ens10.1 up

Here is the ip a return :

3: ens10: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc fq_codel state UP group default qlen 1000
    link/ether 0c:da:41:1d:fe:6c brd ff:ff:ff:ff:ff:ff
    inet 20.0.0.25/24 scope global ens10
       valid_lft forever preferred_lft forever
    inet6 fe80::eda:41ff:fe1d:fe6c/64 scope link 
       valid_lft forever preferred_lft forever
5: ens10.1@ens10: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc noqueue state UP group default qlen 1000
    link/ether 3e:9e:85:d0:f7:f1 brd ff:ff:ff:ff:ff:ff
    inet 20.0.0.100/24 scope global ens10.1
       valid_lft forever preferred_lft forever
    inet6 fe80::3c9e:85ff:fed0:f7f1/64 scope link 
       valid_lft forever preferred_lft forever


When I send Ping with ping -I 20.0.0.100 20.0.0.26,I found I only can capture packet on ens10, and all Ping packet use the mac of ens10,not the ens10.1. And I capture an ARP between 20.0.0.100 and 20.0.0.26 , it reply the mac of ens10,not the ens10.1.

Is there any way to send Package with ens10.1's MAC address?

1

There are 1 answers

0
indexalice On BEST ANSWER

Use network namespace can solve this problem.Here is the command:

create a network namespace

ip netns add net1

create a mac-vlan

ip link add link ens10 mac1 type macvlan mode private

set mac-vlan into network namespace, set ip and up

ip link set mac1 netns net1
ip netns exec net1 bash  //after run this command,all command below will exec in net1 which is detached from the main network
ip netns exec net1 ip addr add 20.0.0.100/24 dev mac1
ip netns exec net ip link

Then send Ping with ping -I 20.0.0.100 20.0.0.26 and I found all packet use the mac of mac1,not the ens10.