IP forwarding across Virtual Machine Network Interfaces

An Vo 1 Reputation point
2021-11-29T13:58:45.297+00:00

I have two Virtual Machines set up, VM1 has 1 network interface and VM2 has 2 network interfaces. Both use the same virtual network that I created that has an address space of 192.168.0.0/16. The NIC, eth0, on VM1 has a private IP of 192.168.5.200 while the NICs on VM2 have private IPs of 192.168.5.20 (eth1) and 192.168.1.20 (eth2). The two NICs with the 192.168.5.0/24 addresses are on the same subnet and I am able to ping from one interface to the other. I am trying to then use the 192.168.5.20 assigned NIC for IP forwarding, which I have set in both the azure options as well as within the operating system of the VM.

I added the following IP route onto VM1:
192.168.1.20 via 192.168.5.20

The aim is that if I ping 192.168.1.20 from VM1, the eth1 on VM2 will be used to forward the traffic to the 192.168.1.20 interface. In both cases where I ping directly to 192.168.5.20 and 192.168.1.20 and observing wireshark on the interfaces of VM1 and VM2, I see that VM1 sends out ARP requests for 192.168.5.20 as expected. For both cases a MAC address is returned as a response and VM1 sends out a packet to 192.168.5.20 with this MAC address as the destination. It should be noted that this MAC address is not the same as the one I see attached to the 192.168.5.20 interface as seen when running ifconfig. In the case of the direct ping to 192.168.5.20, this packet is received by eth1 on VM2, however in the IP forwarding case, the packet never reaches the interface.

Thanks

Azure Virtual Network
Azure Virtual Network
An Azure networking service that is used to provision private networks and optionally to connect to on-premises datacenters.
2,762 questions
{count} votes

1 answer

Sort by: Most helpful
  1. SaiKishor-MSFT 17,336 Reputation points
    2021-12-07T12:23:43.467+00:00

    @An Vo Apologize for the delay in responding to this issue. I had to perform some lab tests so determine the cause of this and understand the solution for this problem. I tested this scenario and see that doing the below fixes the issue:

    Find the Interface No. of Nic2 of VM2 using the route print command which will give a similar output as shown below:

    ===========================================================================

    Interface List
    3...00 0d 3a 10 92 ce ......Microsoft Hyper-V Network Adapter
    7...00 0d 3a 10 9b 2a ......Microsoft Hyper-V Network Adapter #2

    ===========================================================================

    -- Here the #2 Network Adapter has the Interface# 7

    On VM2, please add the following routes:

    route add -p 0.0.0.0 MASK 0.0.0.0 192.168.1.1 METRIC 5015 IF <Interface No. of NIC2>

    Now add another route specifically for VM1's IP address as shown below:

    route add -p 192.168.5.200 MASK 255.255.255.255 192.168.5.20 METRIC 5000 IF <Interface No. of NIC2>

    Once you add these routes, it will give you an "Ok!" for every command once it adds the same. You can verify if these are added by doing a "Route Print". After adding these routes, you should be able tp ping the VM2's NIC2 IP from VM1 as expected and also vice-versa. Hope this helps!
    Please let us know if you have any further questions and we will be glad to assist you further. Thank you!

    Remember:

    Please accept an answer if correct. Original posters help the community find answers faster by identifying the correct answer. Here is how.

    Want a reminder to come back and check responses? Here is how to subscribe to a notification.


Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.