1

I am running Linux on VMware Fusion on my Mac. On Linux, I am using a TCP echo server based on TAP devices (it's called PicoTCP, link here: https://github.com/tass-belgium/picotcp). I run the echo server with this command: sudo ./build/test/picoapp.elf --tap tap1:192.168.13.37:255.255.255.0 --app tcpecho:8000 on one terminal window, and I can then talk to the echo server by using the command: sudo ip addr add 192.168.13.38/24 dev tap1 ; sudo ip link set tap1 up; followed by a simple netcat like this: nc 192.168.13.37 8000. My goal is now to be able to talk to the tcp echo server from my Mac (or any other computer on the same network), by running netcat (or equivalent command) from outside the VM. How can I do that? Currently, if I try running netcat with either the ip address of the VM network card, or the ip address specified when running the picotcp server (in this case it would be 192.168.13.37) it does not work.

Thank you so much! Also, let me know if you need more information from my current setup!

1
  • Does your Mac actually have a route to the VM? Dunno about VMWare, but with VirtualBox NAT, for example, you have to setup the networking correctly before the host can reach the guest. Commented Jul 9, 2019 at 1:07

1 Answer 1

2

You need to understand the network that you have. There are a number (at least 2) of points where communication could stop and you need to resolve all of them before you can access the device from the outside.

From the description, you have a TAP device on your local machine where the server listens to. Normally, you will not be able to access this TAP interface from outside your Linux box, even from another virtual machine on the VMWare network. The solution would be to bridge the TAP to the Linux's ethernet interface (which should be eth0, unless you have the stupid RedHat scheme; use ifconfig to be sure)

So, first create a bridge:

ip link add br0 type bridge

Then add the devices to the bridge (I assume that it is tap0, just as I assumed it should be eth0):

ip link set tap0 master br0
ip link set dev eth0 down
ip addr flush dev eth0 
ip link set dev eth0 up
ip link set eth0 master br0

And make sure the bridge is up:

ip link set dev br0 up

You should now be able to access the server on tap0 from a virtual machine on the same VMWare virtual network. You should test this by bringing-up a second virtual machine.

In your virtual linux box, you now have the following network:

+------+      +-------+
| tap0 |      | eth0  |
+------+      +-------+
   |             |   |
   +-------------+   +--------
      bridge 0         "outside world"

Next: how does this VMWare virtual network connect to the outside world? Is this network also bridged on your Mac? Or is it NATted? In that case you should provide some port forwarding rules. Not sure how that works in VMWare, because, like many, I'm on VirtualBox.

In VirtualBox, the "outside world" can be a number of things, the most important are:

  • Bridged Adapter: like you did with the tap-interface, the virtual interface is bridged to the outside interface of the host that runs VirtualBox. The virtual machine will have its own IP address on the outside.

  • NAT: the virtual interface is connected with the outside, but via NAT (Network Address Translation). This is the way that most SOHO DSL routers connect to the Internet. On the outside, there is a single IP address, and if you want to access the machine from the outside, you must set-up portforwarding (never done that; not sure it is feasible in VirtualBox)

  • Host-only: A separate network, that should only be available within the VirtualBox environment.

In VirtualBox, therefore, the bridged adapter is the best suited for you.

Assuming you bridge in VirtualBox, you will now have the following network:

+------+      +-----+     }
| tap0 |      | eth0|     }
+------+      +-----+     }  in your Linux virtual machine
   |     br0    |  |      }
   +------------+  |      }
                   |
Your host (mac)    |
-----------------+ |
                 | |
              +-----------+     physical outside world
              | mac's eth0|--------------
              +-----------+

Other issues you should look at is your IP plan and subnets.

1
  • Thank you so much @LjmDullart! This is very helpful. Could you expand a little bit on what I have to do after I set up the bridge correctly? I just set up a VirtualBox machine, so feel free to refer to VirtualBox if you are more familiar with it Commented Jul 11, 2019 at 20:15

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.