How to Create a Network of Machines in VirtualBox with SSH Access
24:13

How to Create a Network of Machines in VirtualBox with SSH Access

Corey Schafer 20.07.2017 137 550 просмотров 2 029 лайков

Machine-readable: Markdown · JSON API · Site index

Поделиться Telegram VK Бот
Транскрипт Скачать .md
Анализ с AI
Описание видео
In this video, we'll be learning how to clone Virtual Machines, add these machines to a network so they can communicate with each other, make sure they have internet access, and also set up SSH so that we are able to SSH into these machines from our host machine. This will allow us to pretty much build an entire virtual lab that we can use to test all kinds of different software. So after we're done, this will give us the ability to quickly spin up a new VM that behaves just like a real machine on our network. Let's get started. VirtualBox Snapshots: https://www.youtube.com/watch?v=Qte4X-rdr2Q Ubuntu Install: https://www.youtube.com/watch?v=-2x-5DN-caM VirtualBox Networking Docs: https://www.virtualbox.org/manual/ch06.html ✅ Support My Channel Through Patreon: https://www.patreon.com/coreyms ✅ Become a Channel Member: https://www.youtube.com/channel/UCCezIgC97PvUuR4_gbFUs5g/join ✅ One-Time Contribution Through PayPal: https://goo.gl/649HFY ✅ Cryptocurrency Donations: Bitcoin Wallet - 3MPH8oY2EAgbLVy7RBMinwcBntggi7qeG3 Ethereum Wallet - 0x151649418616068fB46C3598083817101d3bCD33 Litecoin Wallet - MPvEBY5fxGkmPQgocfJbxP6EmTo5UUXMot ✅ Corey's Public Amazon Wishlist http://a.co/inIyro1 ✅ Equipment I Use and Books I Recommend: https://www.amazon.com/shop/coreyschafer ▶️ You Can Find Me On: My Website - http://coreyms.com/ My Second Channel - https://www.youtube.com/c/coreymschafer Facebook - https://www.facebook.com/CoreyMSchafer Twitter - https://twitter.com/CoreyMSchafer Instagram - https://www.instagram.com/coreymschafer/

Оглавление (11 сегментов)

<Untitled Chapter 1>

hey there how's it going everybody so there are a lot of system administration videos that I'd like to do in the near future on topics like anible and setting up web servers and running a Jenkin server and things like that and in order to do that I'd like to have some virtual machine set up that we can have SSH access to so in a previous video we already saw how to create snapshots of certain machine States and in this video we'll be learning how to clone virtual machines add these machines to a network so that they can communicate with each other and make sure that they have internet access and also set up SSH so that we're able to SSH into these machines from our host machine so this will allow us to pretty much build an entire Virtual Lab that we can use to test all kinds of different stuff so after we're done this will give us the ability to quickly spin up a new virtual machine that behaves just like a real machine on our Network so if you do want to follow along with those future videos and don't currently have a machine that you can run experiments on then you should probably follow along with this video so that you have a virtual machine that you can SS into and we'll be using virtual box for this video and in a few previous videos we looked at how to install a couple of different operating systems in Virtual box so we learned how to install auntu desktop and C Linux so if you'd like to see how I got these machines installed then you can go back and watch either of those videos and I'll put a link to that in the description section below so in this video we're going to go ahead and create two clones of this boonu machine and get them set up to where we can SSH into them from our host machine so let's go ahead and get started so first of all I'd like to point out that the virtual machines that we've created so far are pretty fresh installations so the only thing that we've done is install the operating system and some guest editions now I also went in and added some code to the bash RC files and made the text a little larger so that you could see but other than that it should be just about the same so those changes aren't going to affect if you're following along but if you notice that my prompt looks different than yours when you log into these machines then that's the reason and after you do get those machines set up how you like I usually like to create a snapshot of that machine so that you can go back to the fresh install or any place else if anything gets changed by mistake and like I said if you would like to learn more about how to do snapshots then I do have a video on specifically just that and I'll put a link to that video in the description section also and personally one thing that I also like to do is after I get all my operating systems set up then I like to rename these to bass at the beginning here so that I know that these are machines that I want to clone from so now that I have these set up to where I want to clone from these machines I'm not going to change anything on these machines anymore and then I'll just work with the Clones so let's go ahead and do that now and get started on creating our machines that we're going to be able to SSH into so to start let's check out our virtual box preferences so we want to go up here to Virtual box and hit preferences and from here let's go to network and now let's choose hostonly Network and we want to be sure that we have a hostonly network in here um so you can see that I have one you might have two but you want to be sure that you at least have one and if you need to create one then you can click this add button over here so now I'm going to double click on this vbox Net Zero and look at its settings so you can see that we have an ipv4 address of 192168 56. 1 and we're going to need to remember that IP for later and our subnet mask is 2552552550 and if we click on the DHCP server settings here then I'm just going to leave this unchecked because we're going to be assigning static IPS to our machines and once we're sure that we have that hoston Network then we need to change the network settings for our base machine so let's go ahead and do that now so I'll close out of this and then for our base machine I'm going to open

select the base machine

up select the base machine and then open up its settings now let's go over here to network and within Network we're going to go to adapter one which should be the default and we're going to have this set to natat Nat and this will allow Our Guest to connect to the internet through our host connection and now let's go over here to adapter 2 and let's enable this network adapter also and for this adapter we're going to choose this drop down here and let's choose hostonly adapter now just a quick side note uh if you want to view these different network options on the virtual box page they have a good rundown of what each of these options mean and I'll leave a link to that in the description section below um I have it pulled up right here it's just this website here and I'll leave a link to this but they have what all of these different uh Network possibilities are so I'm going to go ahead and minimize this again be sure that we have hoston adapter selected there and once we select host only you also want to make sure that it's set to the specific Network that we just made sure existed okay so now that we have our different base Linux systems set up how we'd like let's look at how fast we can get up and running with creating multiple clones that we can SSH into so now to clone that machine I'm just going to right click on our machine and hit clone you can see we could all also use command o and within here I'm going to rename this to this first clone here I'm just going to name auntu -1 and we do want to reinitialize the MAC address of the network card so let's go ahead and continue and we'll do a full clone for this one and we will do the current machine State and once that clone is finished I'm going to go ahead and create a second clone here and I'm going to call this one a boon 2 and we'll reinitialize the MAC address and continue and full clone and current machine state is fine okay so once both of those are created let's go ahead and start up both of those machines and log in to each one so I'll just grab auntu 2 and put it on the right side of my screen and auntu one I will put on the left side of my screen now since we clone these from a machine that already had guest editions installed we already have guest editions installed for these clones as well so that's the benefit of cloning machine that's already been set up so now I'll log into both of these machines and then as soon as I log in here I'm going to open up terminal so open up terminal on auntu one here and also on Aon 22 so first let's make sure that we can access the internet on both of our machines and to do that I'm just going to go ahead and ping google. com and I'll do that on the second machine here as well so you can see that we are pinging google. com so it does have network access and the reason it has that access is because we're using that Nat as our first adapter and that gives us internet access through our host machine so now let's set up the

set up the host names of both of our machines

host names of both of our machines so I have my prompt set up to display the host name here in the prompt and you can see that currently these are both the same uh because it has the same host name as our base machines since that's what we clone from so to do this to change these host names we're going to have to edit two different files and you can use Vim to edit these files but if you're unfamiliar with Vim then you may want to use an editor like Nano so let's edit this file so we're going to do pseudo Nano and the first file that we want to edit is under ECC host name and we'll open that up and put in our credentials here and for the first machine we will just call this auntu D1 and we'll also do this over here on the second machine so we'll do pseudo Nano SLC hostname and put in our credentials and we will call this one auntu -2 and in Nano to save this you hit contrl X and then y to save and over here we'll now another file to change that host name uh we need to open up our host file so SL tc/ host and right here on the first line where we had the old host name I'm just going to uh erase that and this one was called auntu D1 so we will save that then over here on this machine will do the same thing pseudo Nano that's- Etc slh host and on this second line here we're going to erase the old host name and the new one for this machine was auntu 2 so contrl X Y to save okay so now that we have that done let's run a command uh if config and Das a and we'll do that on this machine as well if config Das a oh looks like I missed a space there so if config space- a okay so now we should be able to see our network interfaces now this first one here with the inet address is bound to our first adapter and we're going to bind this second one here to an IP address on our hoston Network that we specified before so keep the name of this second interface in mind here because it may be different than what is on my machine so for you this may be something like uh eth1 or something like that um so be sure that you keep in mind the second adapter name here so mine is 0 S8 so I'm going to remember that and while remembering that now I'm going to uh change one more file here to change

change our network interfaces

our network interfaces so this file is going to be pseudo Nano and the file is SLC Network SL interfaces and we'll open this up in our second machine here as well so that's SLC slash Network slash interfaces and within this file I'm going to come down here to the bottom I'll do it on my first machine first and this is going to be uh kind of long here but just bear with me so we're going to say Auto and then the name of that interface and mine was P0 S8 then on the next line we're going to do iFace and then the name of that interface again now we're going to tell this that we want it to be a static IP address so it's uh inet static and now we want to specify what this address is so we'll say address and I'm going to set the address for this machine to 192. 168 56100 and now this 1 192. 168 56 remember that was the uh first part of our hostonly adapter address okay and with that said let's also do our subnet mask so we'll do net mask and we're going to set this to 255 255. 255. 0. 0 now we're going to have to do the same thing on our second machine here so I'll go ahead and speed this up so that you don't have to watch me type all this again okay so once we get to this point on our second machine now we want to be

choose a different static ip address for each of these machines

sure that we choose a different static IP address for each of these machines because we have to know which machine that we're going to be sshing into so for this one instead of1 192. 168 56100 let's do uh 101 and now the subnet mask is going to be the same so we'll do a net mask of 255. 255. 255. 0 and you'll want to check your typing at this point because it's easy to make typos whenever you're typing all this stuff out so let's go ahead and save both of these so crl X and Y crl X and yes to save okay so now once we've made it to that point I'm going to go ahead and reboot my machine so I'm going to do a Pudu reboot and we'll do this on the second machine as well sudu reboot now I think we could have activated those changes without a reboot but since it doesn't take too long I just uh like to go ahead and reboot at that point just in case okay so once our reboot is complete let's go ahead and log back into each of our machines and once we're logged let's pull back up the terminal and we'll run a couple of checks here okay so first of all we can see that it has the new host name for each machine so this is now auntu one and 2 um so now if we rerun the if config command if config Dasa and over here we'll do if config d a now if we look at our second adapter here we can see that now it has an IP address that we set in our network interfaces file and over here let's do that same check so we have our second adapter here and we have a static IP address that's set to the IP address that we specified in that file so now that we have these machines set up on the same network uh they should be able to communicate with each other and we

test this by pinging their ip addresses

can test this by pinging their IP addresses so from the first machine we can say I want to Ping that 1 192. 168 56101 because that's our second machine is 101 so if I run that you can see that we're getting some ping responses back and from the second machine we can try to Ping the first machine so we can say ping 192. 168 56100 and that's our first machine so if we run that we can see that we're getting a ping response back from that as well so now I'll go ahead and kill those and clear our screens okay so that's nice that those machines can talk to each other but also the good thing about this is that if we

open up a terminal on our host machine

open up a terminal on our host machine then we should also be able to hit both of those uh guest machines from our host machine as well so to try this we can do a ping 192. 168 56100 for our first machine and we can see that we're getting a response back from that and if I do a ping on the second machine then we can see that we're getting a response back from that as well so I'll go ahead and clear that out okay so we can ping those machines but now let's try to SSH into those machines so instead of a ping command here I'm going to do an SSH and then the user that we want to SSH as so Corey Ms at the IP address so we're going to try to log in to and I'll try to log into the first machine here so I'll make that a 100 so we're trying to SSH as Corey Ms on this machine so if I run this now at this point that may have worked for you and it may not have so it didn't work for me so if it doesn't work for you then you might not have open SSH installed so if it doesn't work for you then we'll need to go to our virtual

install your ssh server

machine and install your SSH server so to do this let's go to each of our machines here and we're just going to do a pseudo apt get update and type in our credentials here and we'll do that on this machine as well and type in our credentials and that just updates our packages list so now I'll clear those out and now we want to install open SSH

install ssh server

server so to do this we will do pseudo apt G install and this is open SSH all one word with a dash and then server then it'll ask you to continue and you can just hit yes there and we'll do the same thing on our second machine so pseudo app to get install open SSH and then Dash server and then it'll ask us to continue and we'll hit yes now I should also point out that those commands may be different depending on which version of Linux that you're using so now I'm going to clear our screens here now if you already had open SSH server installed and it still wasn't working then one thing that you can try is just restarting that service and to do that you can restart the service by saying pseudo service SSH restart and we'll do that over here as well so pseudo service SSH restart so now if those changes work correctly then we should be able to SSH into our machine now from our host machine so let's go ahead and try that so that same command that failed a little bit ago if we try this again so now we've got a little further it's asking us if we want to continue connecting and we'll type yes and then for the pass phrase I'm just going to leave that blank and hit enter and now it's asking us for our password so we'll put in our password and now we can see here that from our host machine we are on the abtu one machine so the SSH was successful so if I do an LS then this is the home directory of my virtual machine if I do a un name- a then we can see that it says that it's lunux auntu so we actually are SED into that machine so let's try to do the same thing with our second machine so instead of 100 there as the one that we're sshing into let's do 101 if I hit enter okay so at this point that may have worked for you but I also wanted to show you what this looked like as well so if you have been messing around with a few different machines and trying this then it may get to the point where you need to remove your keys belonging to a host name from a known host file because that's what this error is here so basically with that first machine when we typed in yes it added information to that known host file and if you do this with multiple machines then that can get confusing so to do this and to remove that key from the known host file all we have to do is do ssh-key gen and then a-h capital r option and then the IP address and the IP address for this is 1 192. 168 56101 and if we hit enter there we can see that it found that old key on line 7 and updated the file so now let's try and I'll clear my screen here now so now let's try to SSH into that second machine again so now it says that it didn't find it and if we want to continue connecting and we'll type yes and then again for the P phrase we'll just leave that blank and now it's asking for our password okay so now we can see that we're sshed into that auntu machine that second auntu machine okay so once I get the machines to this point where I can log in Via SSH I usually like to create a snapshot of that virtual machine at this point so I can revert back to that state if I ever mess anything up by experimenting because that's what we want to do with the these machines is experiment with different softwares so I will go ahead and create

create two snapshots

two snapshots so on auntu one here I'll go in and create a snapshot and for the snapshot description I'm just going to say SSH setup and in the snapshot description I usually like to add the static IP address uh just in case I forget in the future I can look in the description so I'm just going to say 192 2. 1 16856 do1 100 for that one and I will copy that for the next one and for a boon 2 machine I'll take a snapshot and again I will just uh for the name I'll do SSH setup and down here I will paste in the IP address and that was 101 and hit okay there oh and actually I just realized that I made a mistake when creating these snapshots if you have watched my Snapshot video uh then you'll remember that you don't want to take snapshots of running machines unless you need to because it'll save the exact state of that machine and uh takes up way more space so I'm going to shut down these machines first and then create a snapshot and I'll go ahead and Skip forward here so that you don't have to see this entire process okay and with those snapshots created now I'm going to power these machines back up so that we can uh SSH back into them one last time okay and lastly let's set this up so that we can SSH into these machines by their host name So currently if I was to say SSH as Corey Ms abtu one for our first machine and hit enter then it says that it doesn't know that host name so even though we can SSH into uh that machine using the IP address it would be nice if we could SSH into it using the host name as well so to get this working we're going to have to update our host file on our host machine so that it knows that host name is associated with that IP address and I'll just use Nano again so I'll do pseudo Nano and this host file is in SLC SL host and we'll need to put in our password okay and at the bottom of this file I'm going to go down to the very bottom here and first we're going to put

put in the ip address

in the IP address so we'll put in 192. 168 56. 00 and then we'll have a space actually instead I will do a tab and now we want the host name associated with that IP address so I'll do abun 2-1 and now let's do that same thing for the second one here so 192. 168 56101 Tab and this one is abtu 2 and we'll hit control X and Y to save that okay so now let's clear our screen and try that again so I'll try to ssh in as auntu D1 and we will add that to our host file no passphrase now it's asking for our password okay and we can see that we're in there and just to double check let's exit out of that machine and let's try to SSH into auntu 2 so we'll type in yes there no passphrase type in our password and we can see that we can SSH into both of those using the host name okay so I think that is going to do it for this video now I know that seems like a lot to set up these machines that can communicate with each other and that we can SSH into but really the process isn't that long from start to finish if you do it a few times and like I was saying before this is going to allow us to test a lot of different things in a sandbox environment that we can just scrap and recreate if we mess anything up now one thing that I wanted to mention is that there are a lot of different ways that I've seen other people set this up and this is just my preferred method for several reasons that I'm not going to go into here um now there are ways to do this similar thing using port forwarding or bridged network connections or using Docker uh but those of all slightly different behaviors and for my testing needs this method has worked well okay so now that we have some fresh machines set up that we can SSH into maybe I'll try to put together some tutorials on tools like anspo where we can automate the provisioning of multiple machines or we can do something like Jenkins where we can walk through how to get started with continuous integration or anything like that but if you have any questions about what we covered in this video then feel free to ask in the comments section below and I'll do my best to answer those and if you enjoy these tutorials and would like to support them then there are several ways you can do that the easiest way is simply like the video and give it a thumbs up and also it's a huge help to share these videos with anyone who you think would find them useful and if you have the means you can contribute through patreon and there's a link to that page in the description section below be sure to sub subscribe for future videos and thank you all for watching

Другие видео автора — Corey Schafer

Ctrl+V

Экстракт Знаний в Telegram

Экстракты и дистилляты из лучших YouTube-каналов — сразу после публикации.

Подписаться

Дайджест Экстрактов

Лучшие методички за неделю — каждый понедельник