networking - Port forwarded Virtualbox guest dropping ~ 50% of http requests

25
2013-09
  • codingkevin

    Roughly 50% of all HTTP request are being refused/timing out when trying to access the guest OS from the host OS via NAT. Requests being called via http://localhost:8001

    Below are some details:

    Host OS: Mac OS X Lion (10.7.2) - 64 bit
    Guest OS: CentOS 5.7 2.6.18-274.el5 - 64 Bit
    VirtualBox: 4.1.6.r74713 - Network Adapter Type: NAT
    

    Port forwarding is setup and running:

    $ VBoxManage showvminfo thevm |grep "NIC 1"
    NIC 1:           MAC: 0800272C2273, Attachment: NAT, Cable connected: on, Trace: off (file: none), Type: 82540EM, Reported speed: 0 Mbps, Boot priority: 0, Promisc Policy: deny
    NIC 1 Settings:  MTU: 0, Socket (send: 64, receive: 64), TCP Window (send:64, receive: 64)
    NIC 1 Rule(0):   name = http, protocol = tcp, host ip = , host port = 8001, guest ip = , guest port = 80
    NIC 1 Rule(3):   name = ssh, protocol = tcp, host ip = , host port = 2222, guest ip = , guest port = 22
    

    From the Host OS:

    $ netstat -nl |grep tcp |grep 127.0.0.1
    tcp4       0      0  127.0.0.1.8001         127.0.0.1.59056        ESTABLISHED
    tcp4       0      0  127.0.0.1.8001         127.0.0.1.59055        ESTABLISHED
    tcp4       0      0  127.0.0.1.59056        127.0.0.1.8001         ESTABLISHED
    tcp4       0      0  127.0.0.1.8001         127.0.0.1.59054        ESTABLISHED
    tcp4       0      0  127.0.0.1.59055        127.0.0.1.8001         ESTABLISHED
    tcp4       0      0  127.0.0.1.59054        127.0.0.1.8001         ESTABLISHED
    tcp4       0      0  127.0.0.1.2222         127.0.0.1.58891        ESTABLISHED
    tcp4       0      0  127.0.0.1.58891        127.0.0.1.2222         ESTABLISHED
    tcp4       0      0  127.0.0.1.5037         127.0.0.1.54240        ESTABLISHED
    tcp4       0      0  127.0.0.1.54240        127.0.0.1.5037         ESTABLISHED
    

    Also from Host OS:

    $ netstat -nl |grep tcp |grep 127.0.0.1
    tcp4       0      0  127.0.0.1.56778        127.0.0.2.80           SYN_SENT   
    tcp4       0      0  127.0.0.1.56777        127.0.0.2.80           SYN_SENT   
    tcp4       0      0  127.0.0.1.56776        127.0.0.2.80           SYN_SENT   
    tcp4       0      0  127.0.0.1.2222         127.0.0.1.55086        ESTABLISHED
    tcp4       0      0  127.0.0.1.55086        127.0.0.1.2222         ESTABLISHED
    tcp4       0      0  127.0.0.1.2222         127.0.0.1.54727        ESTABLISHED
    tcp4       0      0  127.0.0.1.54727        127.0.0.1.2222         ESTABLISHED
    tcp4       0      0  127.0.0.1.5037         127.0.0.1.54240        ESTABLISHED
    tcp4       0      0  127.0.0.1.54240        127.0.0.1.5037         ESTABLISHED
    

    (the destination fo 127.0.0.2 looks a little off to me...)

    From Guest OS:

    $ netstat -nl |grep tcp
    tcp        0      0 0.0.0.0:110                 0.0.0.0:*                   LISTEN      
    tcp        0      0 0.0.0.0:143                 0.0.0.0:*                   LISTEN      
    tcp        0      0 0.0.0.0:111                 0.0.0.0:*                   LISTEN      
    tcp        0      0 0.0.0.0:80                  0.0.0.0:*                   LISTEN      
    tcp        0      0 0.0.0.0:22                  0.0.0.0:*                   LISTEN      
    tcp        0      0 0.0.0.0:443                 0.0.0.0:*                   LISTEN      
    tcp        0      0 0.0.0.0:670                 0.0.0.0:*                   LISTEN 
    

    SSH works fine - no issues there at all.
    My google-fu is failing me hard on this one. This VM was initially created on a Win7 box, exported, and then imported onto OS X Lion. It works fine on Win7 (and continues to do so for devs using Windows boxes).

    iptables are disabled - as well as SELinux.

    Here is a tcpdump from Guest OS:

    $tcpdump -v |grep http
    tcpdump: listening on eth0, link-type EN10MB (Ethernet), capture size 96 bytes
    15:19:39.304055 IP (tos 0x0, ttl  64, id 47318, offset 0, flags [none], proto: TCP (6), length: 44) 10.0.2.2.58975 > 10.0.2.15.http: S, cksum 0x0bf8 (correct), 225280001:225280001(0) win 65535 <mss 1460>
    15:19:39.304081 IP (tos 0x0, ttl  64, id 0, offset 0, flags [DF], proto: TCP (6), length: 44) 10.0.2.15.http > 10.0.2.2.58975: S, cksum 0xa1a1 (correct), 1043076425:1043076425(0) ack 225280002 win 5840 <mss 1460>
    15:19:39.304120 IP (tos 0x0, ttl  64, id 47319, offset 0, flags [none], proto: TCP (6), length: 44) 10.0.2.2.58976 > 10.0.2.15.http: S, cksum 0x11f6 (correct), 225344001:225344001(0) win 65535 <mss 1460>
    15:19:39.304126 IP (tos 0x0, ttl  64, id 0, offset 0, flags [DF], proto: TCP (6), length: 44) 10.0.2.15.http > 10.0.2.2.58976: S, cksum 0xb6b7 (correct), 1039140461:1039140461(0) ack 225344002 win 5840 <mss 1460>
    15:19:39.304154 IP (tos 0x0, ttl  64, id 47320, offset 0, flags [none], proto: TCP (6), length: 40) 10.0.2.2.58975 > 10.0.2.15.http: ., cksum 0xd02e (correct), ack 1 win 65535
    15:19:39.304258 IP (tos 0x0, ttl  64, id 47321, offset 0, flags [none], proto: TCP (6), length: 44) 10.0.2.2.58978 > 10.0.2.15.http: S, cksum 0x17f3 (correct), 225408001:225408001(0) win 65535 <mss 1460>
    15:19:39.304264 IP (tos 0x0, ttl  64, id 0, offset 0, flags [DF], proto: TCP (6), length: 44) 10.0.2.15.http > 10.0.2.2.58978: S, cksum 0x1ffb (correct), 1041146632:1041146632(0) ack 225408002 win 5840 <mss 1460>
    15:19:39.304291 IP (tos 0x0, ttl  64, id 47322, offset 0, flags [none], proto: TCP (6), length: 40) 10.0.2.2.58976 > 10.0.2.15.http: ., cksum 0xe544 (correct), ack 1 win 65535
    15:19:39.304294 IP (tos 0x0, ttl  64, id 47323, offset 0, flags [none], proto: TCP (6), length: 44) 10.0.2.2.58979 > 10.0.2.15.http: S, cksum 0x1df1 (correct), 225472001:225472001(0) win 65535 <mss 1460>  
    

    Any help is greatly appreciated.

  • Answers
  • sblair

    A user in the #vbox IRC channel on freenode pointed me to: Virtualbox bug report. That solved the issue. The solution is as follows:

    Depending on your guest VM's configuration execute one of the following commands:

    # VBoxManage set extradata <vmname> \
    "VBoxInternal/Devices/e1000/0/LUN#0/Config/SoMaxConnection" 10
    

    Or

    # VBoxManage set extradata <vmname> \
    "VBoxInternal/Devices/pcnet/0/LUN#0/Config/SoMaxConnection" 10
    

  • Related Question

    networking - VirtualBox NAT port forwarding on Ubuntu 64?
  • Greg Mattes

    I have an Ubuntu 9.04 desktop 64-bit guest OS running on an Ubuntu 9.04 desktop 64-bit host OS (yes, the same OS). I'd like to run a web server on the guest and make it accessible through NAT on the host.

    I (think I) followed the VirtualBox port forwarding instructions, but the guest/VM won't start after I do the configuration.

    Here's the configuration that I ran:

    VBoxManage setextradata "<Guest Name>" "VBoxInternal/Devices/pcnet/0/LUN#0/Config/guesthttp/Protocol" TCP
    VBoxManage setextradata "<Guest Name>" "VBoxInternal/Devices/pcnet/0/LUN#0/Config/guesthttp/GuestPort" 80
    VBoxManage setextradata "<Guest Name>" "VBoxInternal/Devices/pcnet/0/LUN#0/Config/guesthttp/HostPort" 8080
    

    Where <Guest Name> is the name of the guest VM image.

    The error looks like this:

    enter image description here

    The same error happens regardless of whether I run the configuration while the VM is running, or not running.

    Guest additions are installed.

    How do I properly configure the NAT port forwarding? What is causing this error?


  • Related Answers
  • the_curator

    get all param you did for this WM with command:

    VBoxManage.exe getextradata "Name_of_VM" enumerate
    

    You should see all value transmited to VM.

    Key: GUI/SaveMountedAtRuntime, Value: yes
    Key: GUI/ShowMiniToolBar, Value: yes
    Key: GUI/MiniToolBarAlignment, Value: bottom
    Key: GUI/LastCloseAction, Value: save
    Key: GUI/LastWindowPostion, Value: 345,133,640,522
    Key: GUI/Fullscreen, Value: off
    Key: GUI/Seamless, Value: off
    Key: GUI/AutoresizeGuest, Value: on
    Key: GUI/MiniToolBarAutoHide, Value: on
    Key: VBoxInternal/Devices/pcnet/0/LUN#0/Config/guestssh/HostPort, Value: 22
    Key: VBoxInternal/Devices/pcnet/0/LUN#0/Config/guestssh/GuestPort, Value: 22
    

    Remove all ligne begin with VBoXInternal by Copying and paste the line to command like this

    VBoxManage.exe setextradata "Name_of_VM" "VBoxInternal/Devices/pcnet/0/LUN#0/Config/guesthttp/HostPort"
    

    with no value to the end. At end you should enumerate again and see no more lines of VBoxInternal.

    Now you can make again the NAT rules, with different name for rules.

    Key: VBoxInternal/Devices/pcnet/0/LUN#0/Config/guestssh/HostPort, Value: 2222
    Key: VBoxInternal/Devices/pcnet/0/LUN#0/Config/guestssh/GuestPort, Value: 22
    Key: VBoxInternal/Devices/pcnet/0/LUN#0/Config/guestssh/Protocol, Value: TCP
    Key: VBoxInternal/Devices/pcnet/0/LUN#0/Config/guesthttp/Protocol, Value: TCP
    Key: VBoxInternal/Devices/pcnet/0/LUN#0/Config/guesthttp/GuestPort, Value: 80
    Key: VBoxInternal/Devices/pcnet/0/LUN#0/Config/guesthttp/HostPort, Value: 8080
    

    Under linux you should remind that PORTS <1024 should NOT be redirected. use 2222 for guestssh and 8080 for guesthttp (Example) For ease of use I personnaly use <1014 port under WINDOWS.

    Hope this should help you.

    (Sorry For English! I'm frenchy :P)

    Jacques.guensherian

  • catchdave

    I had the same symptom when I setup up port forwarding in VirtualBox.

    When I create new VMs in VirtualBox, the default network adapter is e1000, not pcnet as per the instructions you followed.

    If you modify the config settings to:

    VBoxManage setextradata "<Guest Name>" "VBoxInternal/Devices/e1000/0/LUN#0/Config/guesthttp/Protocol" TCP
    VBoxManage setextradata "<Guest Name>" "VBoxInternal/Devices/e1000/0/LUN#0/Config/guesthttp/GuestPort" 80
    VBoxManage setextradata "<Guest Name>" "VBoxInternal/Devices/e1000/0/LUN#0/Config/guesthttp/HostPort" 8080
    

    This should solve your problem.


    The above configuration option will work for the first e1000 adapter, hence the e1000/0 in the settings. Double check which network adapter is being used by the VM you are trying to port forward to.

    On my installation, the network adapters available are two "PcNet" ones and three "Intel Pro 1000".

    The adapters are referred to by the following keys:

    • First PCNet: pcnet/0
    • Second PCNet: pcnet/1
    • First Intel PRO/1000: e1000/0
    • Second Intel PRO/1000: e1000/1
    • Third Intel PRO/1000: e1000/2

    If your adapter is, for example, the second "PRO/1000" in the list, then you need to modify the above config to e1000/1 (etc).