Configure Networking between Virtual Machines.

Objectives

  • Configure networking between

    server

    and

    tester1

    .

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

  1. 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.

 

  1. If all goes well, you will see your adaptor in the output of

    ip a

    command:
  2. On

    server

# ip a

 

  1. On

    tester1

  1. If you don’t see

    enp0s8

    on your machines, use

    nmtui

    command to configure the Host only adaptor.

    Jump to step 12 if you see the adaptor in the list.

    1. On

      tester1

#

nmtui

  1. Use Up/Down arrow key to highlight “

    Edit a Connection

    “ and press enter

  1. 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.

  1. Change the Details of the Ethernet Adaptor as given below

Profile Name:

enp0s8

Device:

enp0s8

  1. Use tab key to select OK and press enter to close the dialog box
  2. You will back to opening screen. Highlight “

    Activate a Connection

    ” and Press Enter

  1. Select the adaptor you just added and use tab key to go to

    ” and press enter.

  1. Use tab key to go to

     

    and press enter.

  1. Use tab key to select

    Quit

    and press Enter.

  1. From the terminal use the following command to activate and verify he IP Address

 

# ifup enp0s8

# ip a

  1. You should see the IP address from the DHCP server of Virtual Box is assigned

  1. Repeat above steps if you don’t see the second adaptor on server and use ping command to verify the connectivity.
  2. Use ping command to verify the connectivity from

    tester1

    to

    server

# ping 10.10.0.100

  1. And from

    server

    to

    tester1

# ping 10.10.0.101

  1. Also from Host Machine (Windows 10 in my case). Open Command prompt and try to ping both VMs

  1. 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.

  1. Start both machines if not already running, login as root and follow these steps to generate the SSH Key pairs
  2. On

    tester1

# ssh-keygen

  1. On

    server

# ssh-keygen

  1. 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.

  1. Copy public key from

    server

    to

    tester1

  1. Copy public key from

    tester1

    to server

  1. Now try to ssh from both machines to connect to other machine.
  2. SSH from

    tester1

    to

    server

# ssh root@10.10.0.100

  1. SSH from

    server

    to

    tester1

# ssh root@10.10.0.101

  1. You should be able to use

    ssh

    command without password.
  2. 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 to

    server

    VM where you have the private key which you have used to connect to

    tester1

    . Use cat command to copy the content of the private key as follows

# cd # cat .ssh/id_rsa

  1. 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 enable

    Bidirectional Clipboard

    on your Virtual Box (

    Devices -> Shared Clipboard -> Bidirectional

    ). This is possible only for server VM.

  1. Save this File in your windows machine.

  1. Start Puttygen Program to convert the Private key to PPK format.

  1. Open

    Conversions -> Import Key

  1. Select the text file you saved earlier

  1. It will import the Private Key to Puttygen

  1. Click on Save Private Key and Confirm the

    Puttygen

    waring on saving this key without passphrase.

  1. Specify a location and accept the default name. Save the PPK format Key on your Host machine.

  1. The Key you have converted is the private key of your

    server

    . You have coped the corresponding public key to

    tester1

    Hence you can now use this PPK format key to connect to your

    tester1

    VM. Launch Putty from your windows machine. Enter the IP address of

    tester1

    .

  1. Expand

    SSH

    under

    Connection

    from Left part of the window and select

    Auth

    . Now on the right part of the window,

    browse

    to the PPK format Key on your system

  1. Click on

    Open

    to Connect. You will see a Security alert. Click on

    YES

    to accept.

 

  1. Enter the user name “

    root

    ” and press enter key.

  1. 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.

  1. To allow connection using hostname, verify the hostname of both VMs in

    /etc/hostname

    .

On Server

# cat /etc/hostname

On Tester1

  1. Now, verify the hostname entries of both VMs in

    server

    and

    tester1

    .

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

  1. Reboot both VMs. Now you should be able to ping and SSH both VMs with hostname.