Trip.com WW

How to Configure Network Settings for a Linux Distro on VirtualBox for Penetration Testing

VirtualBox is a free, open-source virtualization tool that allows you to create and run virtual machines (VMs) on your computer. It enables you to run multiple operating systems simultaneously on a single physical machine, making it ideal for testing, development, and security tasks. With its easy-to-use interface, VirtualBox allows you to manage and configure VMs for various purposes, such as penetration testing, software development, or running different operating systems.

To configure the network settings for a Linux distro running in a Virtual Machine (VM) on VirtualBox for penetration testing in your lab, you’ll need to adjust the VM’s network adapter to meet your testing requirements. In this guide, I’ll walk you through configuring the VirtualBox network settings to provide the VM with the appropriate network access for your penetration testing activities.

Step-by-Step Guide to Configure Network Settings in VirtualBox for Penetration Testing

1. Access VirtualBox Network Settings

  • Open Oracle VM VirtualBox.
  • Right click on your Linux VM.
  • Click on the Settings button (the gear icon).
  • In the left panel, go to the Network tab.

2. Choosing the Right Network Adapter

There are several network configurations in VirtualBox that determine how your VM interacts with the network. For penetration testing in your lab, the two most relevant options are:

  • NAT (Network Address Translation): This is the default setting, and it allows the VM to access external networks (like the internet) through the host machine's IP address. This can be useful if you need external internet access for updates, downloading tools, or accessing external targets in your lab.

  • Bridged Adapter: This allows the VM to appear as a separate device on the same network as your host machine. The VM gets its own IP address from your local network (e.g., DHCP). This is ideal for testing penetration testing attacks on local network devices or for simulating real-world attack scenarios where the VM interacts directly with other devices.

  • Host-Only Adapter: This creates a private network between your host and the VM. The VM cannot access external networks, but you can still interact with the VM from the host. This is a good option for isolated testing, where you do not need external internet access.

  • Internal Network: This option allows communication only between VMs connected to the same internal network (isolated from the host and external networks). This is useful when you want to set up an isolated test environment with multiple VMs interacting with each other, without exposure to your local network.

Let's go through configuring these options in detail:

Option 1: NAT Network (for general internet access)

  1. Enable NAT Network:

    • Select Adapter 1.
    • In the "Attached to" dropdown, select NAT.
    • This allows your VM to use the host machine’s network connection for internet access (e.g., for updating tools, scanning external targets).
  2. Check IP Configuration in the VM:

    • Start your VM and log in.
    • Open a terminal and run the command ip a or ifconfig to check the IP address.
    • The VM should have an IP address in the private range (e.g., 10.x.x.x or 192.168.x.x), and it should be able to access the internet through the host machine.
  3. Test Internet Connectivity:

    • In the VM, try pinging an external server to confirm the internet connection:
      ping google.com
      
    • If you get a response, the network is configured correctly.

Option 2: Bridged Adapter (for testing with other devices in your lab)

  1. Enable Bridged Adapter:

    • In the Network settings of the VM, select Adapter 1.
    • Set the Attached to dropdown to Bridged Adapter.
    • Under Name, select the network interface of your host machine that is connected to your local network (e.g., Ethernet or Wi-Fi adapter).
    • This will allow the VM to get its own IP address from your local network (DHCP server), just like any other physical device connected to the network.
  2. Check IP Configuration in the VM:

    • Start your VM and log in.
    • Open a terminal and run ip a or ifconfig to check the assigned IP address.
    • You should see the VM has been assigned an IP address in the same subnet as your local network (e.g., 192.168.x.x or 10.x.x.x).
  3. Test Network Communication:

    • From the VM, try pinging another device on your local network (e.g., your host machine or a different lab machine):
      ping <IP of your host or other device in your lab>
      
    • You should be able to reach other devices on your local network.
  4. Test External Connectivity (if needed):

    • If you need external internet access (e.g., for tool updates, etc.), you can test by pinging a public server:
      ping google.com
      

Option 3: Host-Only Adapter (for isolated testing with the host)

  1. Enable Host-Only Adapter:

    • In the Network settings, select Adapter 1.
    • Set Attached to to Host-Only Adapter.
    • This creates a private network between your host machine and the VM, and no external internet access will be available.
  2. Check IP Configuration in the VM:

    • In the VM, run ip a or ifconfig to check the IP address.
    • The VM should have an IP address assigned in a private subnet (e.g., 192.168.56.x), which can be used to communicate with the host machine or other VMs on the same host-only network.
  3. Test Communication with Host Machine:

    • From the VM, try pinging your host machine’s IP address:
      ping <Host IP Address>
      
    • If the VM and host communicate successfully, the network is set up correctly.
  4. Test Isolation (optional):

    • The VM won’t have access to external networks, but you can still configure the lab with other VMs using host-only networking to interact with each other in an isolated environment.

Option 4: Internal Network (for isolated VM-to-VM testing)

  1. Enable Internal Network:

    • In the Network settings, select Adapter 1.
    • Set Attached to to Internal Network.
    • You can name the internal network (e.g., "LabNetwork") to group multiple VMs together.
  2. Check IP Configuration in the VM:

    • Start the VM, and check the IP address assigned to the VM (ip a or ifconfig).
    • The VM will get an IP address in a private range, but only other VMs connected to the same internal network will be able to communicate with it.
  3. Test Communication Between VMs:

    • If you have other VMs connected to the same internal network, you can test communication between them:
      ping <IP address of another VM>
      
    • The VM should be able to communicate with others on the same internal network.

Additional Configuration: Setting Up Port Forwarding (for NAT Network)

If you are using NAT and need to access services running inside the VM (e.g., a web application you’re testing) from your host machine, you may need to set up port forwarding.

  1. Go to SettingsNetworkAdapter 1 (or whichever adapter is using NAT).

  2. Click the Advanced dropdown, and then click Port Forwarding.

  3. Add rules for port forwarding (e.g., for HTTP):

    • Name: HTTP
    • Protocol: TCP
    • Host IP: Leave blank (or use your host machine’s IP).
    • Host Port: 8080 (or another port you want to use on the host).
    • Guest IP: Leave blank (it will auto-fill).
    • Guest Port: 80 (the port where your web server runs in the VM).
  4. Save and test by accessing the VM's service (e.g., web server) through http://<host_ip>:8080.

Conclusion

By following these steps, you can properly configure the network settings of your Linux VM in VirtualBox for penetration testing in your lab. The choice of network mode (NAT, Bridged, Host-Only, Internal Network) depends on your testing requirements (internet access, local network testing, isolated lab environments). After setting up, always check your VM’s network configuration and ensure that it can communicate with other devices in your lab or on the internet, depending on your needs.

Previous
Next Post »

Subscribe to our mailing list

* indicates required
Select your Interested Topics.