Sei sulla pagina 1di 13

HOME

SUBSCRIBE

Howto: SSH into


VirtualBox 3 Linux
Guests
08 FEBRUARY 2010 on Virtualbox, Linux

In a previous post I wrote about using a TAP


interface to be able to SSH into linux guests from
the host. Since then changes in the newer versions
of VirtualBox have seen the addition of a virtual
interface on the Host by default. This post details
how to utilise this to allow communication from
your host to your guests by simply configuring a
second network interface on the guest.
Note: the same result can be used by using one
bridged interface to a physical network interface.
However, I prefer to do it this way as I'm using a
laptop and I don't know at what point I'll be using a

wired, wireless or 3G connection. The following


config will always work irrespective of where you
are. That said feel free to detail any experiences of
alternative methods in the comments.
The following assumes you are using Linux as a host.
The process is very straightforward if you already
have a linux VM or if you are creating one from
scratch the process is essentially the same note if
you are doing this prior to installing an OS the only
thing to note is which interface should be your
primary interface. In most case this should always
be the NAT adapter. Here's a screenshot showing
the dialogue you'll see when installing JEOS as an
example.
All you need to do is access the settings when the
guest is off and add a second network interface to
the guest. By default you should have one interface
already which is using NAT. This should be left
alone as this provides access to the internet. Select
the tab "Adapter 2" and change "attached to" to
"Host-only Adapter" this will have the name

vboxnet0 by default.

Once that's set, boot the Guest image.


Once booted; from the console of the guest VM
you'll need to set-up the configuration for the
second network interface in this case eth1 as we
already have eth0 defined. To do this all you need
to do is edit /etc/network/interfaces to add the
eth1 configuration.

This is a simple as adding the following lines based


on our vboxnet0 is configured to 192.168.56.1 (based
on running ifconfig on the host.

auto eth1
iface eth1 inet static
address 192.168.56.10
netmask 255.255.255.0

Save this and then run the following to fire up eth1:

sudo ifup eth1

Note: If you haven't already installed opensshserver now would be a good time to do so! sudo
apt-get install openssh-server

Now you can drop into the terminal and ssh into
your VM e.g:
ssh jeos@192.168.56.10

That's it.

Stuart Colville

Share this post

Stuart is an Expert Yak Shaver at Mozilla who writes

about web development amongst other things. No Yaks

were harmed in the creation of this blog.

UK

41Comments

MuffinResearchBlog

SortbyNewest

Share

Login
Favorite

Jointhediscussion
Morgan 6monthsago

Nicepost:)thx
Reply Share

rhpaiva 7monthsago

Workedlikeacharm!Thanksalot!
GeorgeLondon'stipwasalsovalid!:)
Reply Share

hexaust 10monthsago

superb!
Reply Share

Bobbum_Man ayearago

Thankyousomuch.i'vebeentryingtofigurethisoutforthepast2hours.
1

Reply Share

JaehyunKim 2yearsago

perfectconfig!thanks.
1

Reply Share

amit 2yearsago

Iamfacingissuewhilesshfromwin7hosttoOEL5guest(installedonVB)
ipaddressandsubnetmaskisasbelow:

ipaddressandsubnetmaskisasbelow:
hostip:192.168.56.3
guestip:192.168.56.101
subnetmask:255.255.255.0(onbothmachines)
Entryofguestiphasbeenmadeinwindowshostfile.
Iamabletopingguestipfromhostbutnotabletopinghostipfromguest
machine.
Pleasehelp!!!!
1

Reply Share

GeorgeLondon 2yearsago

Thiswasn'tworkingformeuntilIcreatedanewnetworkinterfacevboxnet1,
wenttothemainVMBoxprefsandhit"addserver"andfollowChris'
instructionsbelow.Butnowitworks...thanksfortheguide!
1

Reply Share

OriPeleg 2yearsago

Thanks,workedlikeacharmwithaOS/XLionhostandUbuntu12.04
guest.

Reply Share

Pankov 2yearsago

Greattutorialonlythereisaneedto"/etc/init.d/networkingrestart"ifyou
don'twanttorestarttheguest.

Reply Share

kevin 3yearsago

Thanksforthegreattip.
Ididn'thavetoeditmyinterfacesfileatallthough.AfterIaddedtheextra
networkinterfacetotheguestIbooteditupandtypedifconfigandsawthat
eth1hadanIPof192.168.56.101soinmyhostItriedtosshintothatandit
worked!
WhenIwasaddingthesecondnetworkinterfaceinvirtualboxthoughatfirst
Ihadnooptionsforname.TofixthisIjustopenedthevirtualboxsettings
fromFile>Preferences.AndinthenetworktabIjustclickedaddhostonly
network.

Reply Share

StuartColville kevin 3yearsago

@kevin:thatsoundsreasonableIsetitasstaticjusttopreventthe
caseofaDHCPleaseexpiringandtheipaddresschanging.

Reply Share

Sriram 3yearsago

Thanksalot,thisworksverywellwithanUbuntu11.10hostwith2(+)
Ubuntu11.10guests
Reply Share

NielsBom 3yearsago

Iencounteredaproblemwiththe"Name"dropdowninyourscreenshot.My
dropdownwasemptyandIgotthefollowingnotice:
"Nohostonlynetworkadapterisselected"
Solution:firstaddanetworkviaFile>Preferences>Network>Add(plus
sign)
10

Reply Share

Ole 3yearsago

Excellent!Itworks!almostuponfirsttry...
Iactuallyreversedthesteps,andthatmademehavetorestarttheVM,but
thenitjustworkedautomagically.
PS:Ilefttheadaptertypeinthedefaultsetting,becausethetextualsteps
didn'tmentionit.MydefaultwasIntelPRO/1000MTDesktop(sameasVW
postedtohaveused).
PPS:MyhostisWin7andmyguestisUbuntu

Reply Share

vw 3yearsago

Solvedmyissue.Itwastheadaptortypeformyhostonlyadaptor.Ihadset
ittomatchwhatwasinthehowto(PCnetFASTIII).Iswitchtheadaptor
typetomatchmyNATadaptor(IntelPRO/1000MTDesktop).Iamnow
abletoaccessmyguestVMfrom192.168.56.10

Reply Share

vw 3yearsago

AftersettingupmyhostandlocalguestVMexactlyasdescribedinthis
howto.IamnotabletopingmyguestVMfrommyhost.TheguestVMis
abletoconnecttotheinternetfrometh0.UltimatelyIwouldliketoreachport
22and80forsshandhttpd.Belowistheoutputofrunningapingfrommy

22and80forsshandhttpd.Belowistheoutputofrunningapingfrommy
host:
PING192.168.56.10(192.168.56.10)56(84)bytesofdata.
From192.168.56.1icmp_seq=1DestinationHostUnreachable
From192.168.56.1icmp_seq=2DestinationHostUnreachable
From192.168.56.1icmp_seq=3DestinationHostUnreachable
IhaveVirtualBoxversion4.0.4OSEbelowaremymachineconfigurations:
Host:Ubuntu11.04
Inifconfig:
vboxnet0 Link encap:Ethernet HWaddr 0a:00:27:00:00:00
inet addr:192.168.56.1 Bcast:192.168.56.255 Mask:255.255.255
inet6 addr: fe80::800:27ff:fe00:0/64 Scope:Link
seemore
Reply Share

ChrisYallop 3yearsago

I'mrunningamacasthehostandhadthesamedifficultiesasKyonand
John.Eventually,formethesolutionwasintheVirtualBoxpreferences.As
alreadymentionedmakesurethereisavboxnet0hostadded.Whendone,
selectthevboxnet0itemandeditit.Onthepopupscreen,switchtothe
DHCPServertab,enableitandfillitin.Iusedthefollowingsettings:
Server Address: 192.168.56.100
Server mask: 255.255.255.0
Lower Address Bound: 192.168.56.101
Upper Address Bound: 192.168.56.254

PressOKandstartupyourguestVM.ThisassumesyourguestVMis
usingthefollowingsettingsinthe/etc/network/interfacesfileforethernet1:
auto eth1
iface eth1 inet dhcp

Reply Share

DarekAdamkiewicz 3yearsago

Thankyouverymuchforthisrecipe.I'vetwoUbuntuboxeson
virtualbox/vistaandI'vebeenlookingforwaytoconnectviasshtosecond
oneonipotherthan192.168.56.1
Regards
Darek

Darek
Reply Share

FredObermann 3yearsago

Lovelyarticle,however....
Iranthroughthesestepson64bitMandrivaSpring2010.WhenItrytossh
fromthehost,theresultisthatIlogintothehost,nottheguest.
1

Reply Share

LCamel 3yearsago

Thankyouforthetutorial!

!
Reply Share

StuartColville 3yearsago

@AmittaiAviram:Thanksfortakingthetimetoprovideanupdate.
Reply Share

AmittaiAviram 3yearsago

Ihavesolvedmyownproblem!Ijusthadtogobacktomyvirtualmachine's
Settings>Systemandcheck"EnableI/OAPIC."ThenIbootedtheVMup
asusual,switchedwindowstomyhost'sterminalandIcouldSSHtomy
virtualmachine!
1

Reply Share

AmittaiAviram 3yearsago

IhavethesameproblemasJohnandKyon.IhaveMacOSX10.6(Snow
Leopard)andVirtualBox4.0.4,andIhaveinstalledUbuntuServer10.10
(64bit)onavirtualAMDmachineinVirtualBox.Ifollowedalloftheabove
directionsexactly.WhenItrytoconnectfrommyhostterminal,SSHjust
hangsuntilittimesout.TheIPaddressisthesameaswhatmostpeople
hereareusing.Thatis,
$ifconfigvboxnet0
ether0a:00:27:00:00:00
inet192.168.56.1netmask0xffffff00broadcast192.168.56.255
SoIenteredthefollowinginmyguest's/etc/networks/interfaces:
#SecondinterfaceforVirtualBoxhosttoguestcommunication.
autoeth1
ifaceeth1inetstatic
address192.168.56.10
netmask255.255.255.0
Ihaverun

Ihaverun
$sudoifupeth1
and,introubleshooting,Ihaverunifdownandthenifupagain.Ihave
rebootedtheguest.Idon'tknowwhatelsetodo.Hasanybodysucceeded
withMacOSX10.5or10.6?Thanks!
Reply Share

Mike AmittaiAviram ayearago

ThismaybeanoldpostbutIstillfoundituseful.Iwasusingthe
"DeployingRails"book,whichshowedhowtosetupaserverusing
Vagrant+Puppet,butIwantedtofigurethisoutlocallyonanormal
Ubuntuserver.
IhadthesameproblemsuntilIranifconfigontheOSXandnoticean
entryfor
vboxnet0:flags=8843<up,broadcast,running,simplex,multicast>mtu
1500
ether0a:00:27:00:00:00
inet33.33.13.1netmask0xffffff00broadcast33.33.13.255
OnceI'dchangedtheVMboxeth1tousethatIPitallworked!
Idon'tknowhowtoaddavboxnet0entryontheMacmanually,but
maybethatwillgiveotherpeopleaclueonwhattotrynext.

Reply Share

John 3yearsago

IhavethesameproblemasKyon.
I'mrunningMacOSX10.5.6ashostwithVirtualBox4.0.4andI'musing
Ubuntu10.10Server64bitastheguestOS.
Theoutputforifconfiglooksasfollows:
$ ifconfig -a eth1
eth1

Link encap:Ethernet HWaddr 08:00:27:1f:60:e1


BROADCAST MULTICAST MTU:1500 Metric:1
RX packets:0 errors:0 dropped:0 overruns:0 frame:0
TX packets:0 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:0 (0.0 B) TX bytes:0 (0.0 B)
Interrupt:16 Base address:0xd240

Reply Share

janusz 4yearsago

Thanks,worksgreat.

Reply Share

SamanBarghi 4yearsago

Hi,
Thanks,itworkedgreat.IneededtoSSHtoFreeBsdguestmachine,andI
repostedthisentryforFreeBsdmachineshere:
http://www.samanbarghi.com/201...
Iincludedthelinktoyourpostatthebeginning.
Thanks,
Saman

Reply Share

Martin 4yearsago

Thanks..thisworkedforme...ihaveWindowshostanditworkedwithfew
effort.

Reply Share

PeterHinson 4yearsago

Thanksthisworkedgreat!!!InVirtualBox3.2onceyouselectAdapter2for
theinternalnetwork,everythingisconfiguredautomatically.Youdon'tneed
toaddthe192.168.56.10linestothenetworkinterfaceconfigfile.
Cheers

Reply Share

WilliamNotowidagdo 4yearsago

IcanSSHmyCentOSguesthostjustbyaddingthe2ndadapterlikeyou
said.Noneedextraconfiguration.
Thankyou.

Reply Share

StuartColville 4yearsago

@Kyon:It'sreallyhardtosaywhat'supwithoutfurtherinformation,andI
don'tuseamacsoI'munabletochecktheseinstructionsforyou.
Canyouposttheoutputofifconfig?

Reply Share

Kyon 4yearsago

Seemsthatitdoesn'tworkonMacOSX...Ican'tpingneithervirtualboxon

Seemsthatitdoesn'tworkonMacOSX...Ican'tpingneithervirtualboxon
56.1normyDebianVMon56.10fromthemac,andIcan'teitherping
virtualboxfromtheDebianVMitself...

Reply Share

marc 4yearsago

worksgreatthanks!

Reply Share

Adriano 4yearsago

Thanx!worksfineformeanditwasverysimple.
IwastedalotoftimedoingthewrongwaybeforeIreachthishowto!
cheers

Reply Share

whatdoesitwant 4yearsago

PS,addtheguestmachine'sipandnametoyourhostmachine'shostsfile
tosshfromthehosttotheguestbynameinsteadofip.
Soifyourusernameisbobbyandyourguestmachine'snameistintinand
itsipis192.168.56.10,addingtheline
192.168.56.10 tintin

tohosts(onthehostmachine)willallowyoutoaccesstheguestfromthe
hostlikeso:
ssh bobby@tintin

Reply Share

whatdoesitwant 4yearsago

Perfectexplanation.Btwthisalsoworksonawindows7host.Obviouslyto
checkthevboxnet0preferediponwindowsinsteadofusingifconfigayou
useipconfig/allbutIthinkvirtualbox3updefaultsto192.168.56.1anyway,
sothatleavesyouwiththechoiceofanynumberintherangeof
192.168.56.2192.168.56.255
Alternativelyinsteadofusingthecommandprompt,invistaand7youcan
usepowershell.Powershellacceptsmoststandardlinuxcommands,
makingclionwindowsmuchlessfrustrating.

Reply Share

GabrielK 4yearsago

Yourock,thanksforthistutorial.IwasworkingongettingDebiansetup
throughVirtualBoxasasandboxforwork,thenIrealizedIhadnoideahow
toaccesstheguestosfrommyhost.So,thanks!

Reply Share

JasonHeeris 4yearsago

Okay,theproblemwasactuallyFirestarterontheHOSTside(theiptables
basedfirewallmanager),thatIhappenedtoswitchoffataboutthesame
timeasrebootingtheguest.

Mu

n Research Labs 2014

Proudly published with Ghost

Potrebbero piacerti anche