Configure Networking between Virtual Machines.
Objectives
- Configure networking between
server
andtester1
.
Pre-requisite
- Two VMs already downloaded and imported in Oracle VM VirtualBox
- Host Only adaptor is configured on both machines.
Sequence 1. Configure Networking between Virtual Machines
- Start both VMs and Login as root on both machines.
If you are not able to start VMs, it may be due to
Host only Adaptor
change (if you had different adaptor earlier and you changed it). Just restart your Host machine and then start the guest VMs.
- If all goes well, you will see your adaptor in the output of
ip a
command: - On
server
# ip a
- On
tester1
- If you don’t see
enp0s8
on your machines, usenmtui
command to configure the Host only adaptor.Jump to step 12 if you see the adaptor in the list.
- On
tester1
- On
#
nmtui
- Use Up/Down arrow key to highlight “
Edit a Connection
“ and press enter
- Click Use tab key to move the cursor/selection bar to Add and press enter. Now select Ethernet” from the list and use tab to jump to “
Create
” and press enter.
- Change the Details of the Ethernet Adaptor as given below
Profile Name:
enp0s8
Device:
enp0s8
- Use tab key to select OK and press enter to close the dialog box
- You will back to opening screen. Highlight “
Activate a Connection
” and Press Enter
- Select the adaptor you just added and use tab key to go to
“
” and press enter.
- Use tab key to go to
- Use tab key to select
Quit
and press Enter.
- From the terminal use the following command to activate and verify he IP Address
# ifup enp0s8
# ip a
- You should see the IP address from the DHCP server of Virtual Box is assigned
- Repeat above steps if you don’t see the second adaptor on server and use ping command to verify the connectivity.
- Use ping command to verify the connectivity from
tester1
toserver
# ping 10.10.0.100
- And from
server
totester1
# ping 10.10.0.101
- Also from Host Machine (Windows 10 in my case). Open Command prompt and try to ping both VMs
- If you see IP address different from screenshot, edit the file /etc/sysconfig/network-scripts/ifcfg-enp0s8 and changes IP addresses as given in the screen shot (for tester1 – 10.10.0.101 and for server – 10.10.0.100).
Enable Key Based Authentication between VMs
Sequence 2. Create and use SSH Keys
Watch the video https://www.youtube.com/watch?v=A9CNbrwhcJs to know about SSH Key pair.
- Start both machines if not already running, login as root and follow these steps to generate the SSH Key pairs
- On
tester1
# ssh-keygen
- On
server
# ssh-keygen
- Once the Keys are generated you need to copy your public key to other machine. Copy the public key in a notepad file. You will need this Key in Lab 4 also.
# cat .ssh/id_rsa.pub
Paste the contents of the output to a notepad file and save it for later use in Lab 4 and other labs.
- Copy public key from
server
totester1
- Copy public key from
tester1
to server
- Now try to ssh from both machines to connect to other machine.
- SSH from
tester1
toserver
# ssh [email protected]
- SSH from
server
totester1
# ssh [email protected]
- You should be able to use
ssh
command without password. - To use putty to connect any of the VM, you first have to convert the Private Key of that machine to PPK format. For example to connect to
tester1
, login toserver
VM where you have the private key which you have used to connect totester1
. Use cat command to copy the content of the private key as follows
# cd # cat .ssh/id_rsa
- Now select the entire Key from
“---- BEGIN“
to end and past it in a notepad file. If you are not able to paste it, then you have to enableBidirectional Clipboard
on your Virtual Box (Devices -> Shared Clipboard -> Bidirectional
). This is possible only for server VM.
- Save this File in your windows machine.
- Start Puttygen Program to convert the Private key to PPK format.
- Open
Conversions -> Import Key
- Select the text file you saved earlier
- It will import the Private Key to Puttygen
- Click on Save Private Key and Confirm the
Puttygen
waring on saving this key without passphrase.
- Specify a location and accept the default name. Save the PPK format Key on your Host machine.
- The Key you have converted is the private key of your
server
. You have coped the corresponding public key totester1
Hence you can now use this PPK format key to connect to yourtester1
VM. Launch Putty from your windows machine. Enter the IP address oftester1
.
- Expand
SSH
underConnection
from Left part of the window and selectAuth
. Now on the right part of the window,browse
to the PPK format Key on your system
- Click on
Open
to Connect. You will see a Security alert. Click onYES
to accept.
- Enter the user name “
root
” and press enter key.
- You are now logged into the
tester1
from putty using Key based authentication.
Troubleshooting tip - Ensure that you have
PermitRootLogin Yes
in the file /etc/ssh/sshd_config
Repeat all the above steps as “oracle” user also so that you have key based authentication enabled for both users.
- To allow connection using hostname, verify the hostname of both VMs in
/etc/hostname
.
On Server
# cat /etc/hostname
On Tester1
- Now, verify the hostname entries of both VMs in
server
andtester1
.
On
tester1
, open
/etc/hosts
and add the two lines as given below. The IP address must match IP addresses of your machines On
server
, enter same lines in
/etc/hosts
of server
- Reboot both VMs. Now you should be able to ping and SSH both VMs with hostname.