Search code examples
linuxnetwork-programmingvirtualboxbridge

virtualbox vm can not access from outside


I installed a vbox in ubuntu 18.04, and used bridged network by adding parameters:

--bridgeadapter2 eno1 --nicpromisc2 allow-all

Everything goes fine, vm can ping outside, and host can ping vm, but outside can not ping vm: (outside in the same subnet can ping vm, for example: 10.124.214.x can ping vm)

# 10.124.214.116 is vm, 10.124.214.4 is host, 10.124.12.103 is outside IP
# From host to vm
traceroute 10.124.214.116
traceroute to 10.124.214.116 (10.124.214.116), 30 hops max, 60 byte packets
 1  10.124.214.116 (10.124.214.116)  0.232 ms  0.197 ms  0.191 ms
# From vm to outside
ping 10.124.12.103
PING 10.124.12.103 (10.124.12.103) 56(84) bytes of data.
64 bytes from 10.124.12.103: icmp_seq=1 ttl=63 time=1.38 ms

The tricky thing is vbox interface does not like normal linux tun/tap interface, I can see interface in VM, but there is nothing I can operate from host, and there is no bridge on the host.

Is there any API I can trouble shooting vbox?


Solution

  • Cheers code farmer

    You are right about bridge. Thing here is that your VM is currently behind NAT created by virtual box (see different subnets you mentioned)

    What you can do here is to create new bridge on host machine (good instructions HERE)

    Using this setup you will have to change networking setting slightly:

                                         VM Host
                                         +-----------------------------------------------------------------+
                                         |                                       -> VM A (10.124.214.5/24) |
    Outside network (10.124.214.0/24) -> | eno1 (no IP) -> br0 (10.124.214.4/24) -> VM B (10.124.214.6/24) |
                                         |                                       -> VM C (10.124.214.7/24) |
                                         +-----------------------------------------------------------------+
    

    Then you can assign your VM to br0. Depends on your outside network setting you might need to set static IP to your VM