networking - Cant access into ubuntu server using putty in virtualbox

07
2014-07
  • rakibtg

    I have ubuntu server installed in virtualbox and the host os is windows 7.
    I need to access into that ubuntu server using putty.
    Now the way to access via putty is to, have two adapter in virtual box one should be NAT and another one should be Bridged Adapter everything is fine and in my virtual server there is internet connection as well, to check the internet i use this in my ubuntu server:

    wget http://www.google.com
    

    And it successfully downloads a index.html page on the directory.
    But once i write in ubuntu terminal

    ifconfig
    

    then it dosen't show a working IP address that i can access via putty. enter image description here And when i try with that ip via putty it shows error :/ enter image description here enter image description here What's wrong with this? Thanks

  • Answers
  • jlliagre

    The eth0 interface is the NAT one. It only allows outgoing traffic by default.

    In order to access the VM through a bridged interface, there should be an eth1 entry in your ifconfig output. Double check you properly enabled and configured the second NIC in VirtualBox.

    Alternatively, you can also stay with NAT only and configure port forwarding: https://www.virtualbox.org/manual/ch06.html#network_nat


  • Related Question

    SSH session becomes unresponsive when logged into Ubuntu Server virtual machine using VirtualBox
  • nickbart

    I'm really at my wits end here, so I'm hoping someone here can help me. I have a virtual machine running Ubuntu Server 9.10. It's just a small development environment so I can keep my code separate from the test and production environments. I am running it through VirtualBox 3.1.6 on a laptop running Ubuntu Desktop 9.10. I have it set up with a bridged network connection and it is bridged to my laptop's wireless adapter. We have no wired connections in this office.

    I boot up the VM and everything is fine. I can SSH into it using gnome-terminal and for a while everything is Kosher. Then seemingly randomly, the SSH terminal session with hang. No error message, nothing; it just becomes unresponsive. If I go to the VirtualBox terminal I find the VM itself is perfectly fine. It can ping and I can SSH out with it. If I restart the networking on the VM the SSH session in my gnome-terminal will most of the time become responsive again.

    Here's an interesting point, the SSH session will sometimes die right in the middle of me typing something (this points to it not being an idle session issue) and if I go to the VirtualBox terminal and restart the networking and then return to my gnome-terminal SSH session I find that it will come back to life and what I typed when the session hung originally will magically type itself in to the buffer. So, my input is getting stored somewhere and just can't make its way to the VM until the networking on the VM is restarted.

    I've tried different versions of VirtualBox and used vmdk images and vdi images and nothing seems to work. I can't tell if the problem is with my laptop, VirtualBox, or the Ubuntu Server VDI. Is there anyway to debug this issue? Or has anyone out there seen anything similar?

    Your help is much appreciated.

    Nick


  • Related Answers
  • nickbart

    OK, so I found the root cause of my issue and it's so simple I'm slightly embarrassed: conflicting network IPs. It was indeed a network issue as I had surmised, however, it was not as complicated as I was making it.

    Since I am using bridged networking, the VM shows up in the DHCP clients table along with all the other machines on the network. If any one of those other machines grabs my VM's IP from DHCP (say before I boot my VM up for the day) it will cause a conflict whenever my VM comes on line and might cause my VM to stop responding to SSH. This explains why when I was using the VirtualBox terminal, I did not experience any problems at all.

    I'm not exactly sure how most routers handle IP conflicts, but it seems that, whichever machine is last to have network activity gets precedence. So when I bounced the networking on my machine it was fine until whichever machine was sharing the IP decided to engage in networking activity and then BOOM ... my connection would hang.

    I reset my VM's static network IP to be quite high in our range, so hopefully that will keep it clear of any IP conflicts with my co-workers' machines.

  • Journeyman Geek

    I wasn't aware bridged connections and wireless worked together- least with most VMs i have tried. You'd likely want/need to use nat, or host only and see if you can get that to work

  • indiv

    Are you typing CTRL-S, which may halt the session (for legacy reasons)? Press CTRL-Q one of these times its frozen and see whether it un-freezes.

  • nickbart

    Well, I never found the root cause of this issue, but it's definitely something network related. We have a Cisco router here that certainly is a handful some of the time, so the official answer might lie there. I did come up with a work around, however. I wrote a very simple shell script, which I cronned under the root user to run every minute:

    #!/bin/bash
    
    #keep-alive.sh
    
    /etc/init.d/networking restart
    /etc/init.d/ssh restart
    

    This just bounces the networking and Open SSH on the VM server every minute. It's a hacky, inelegant solution, but it keeps my SSH session from permanently hanging. The only reason I find this acceptable, is that it gets the job done and it's only for a small VM server development environment. Naturally, I ABSOLUTELY AM NOT advocating this sort of thing for any kind of production environment.