Internal Network Setup With Linux Virtual Machines
Hey guys! Ever wondered how to set up your own little network playground using VirtualBox and Linux? I'm talking about creating an internal network with a client, a router, and a server, all living happily within your virtual environment. It's a fantastic way to learn about networking concepts, test configurations, and experiment without messing with your actual home network. So, let's dive into how you can build this cool setup using Linux Mint on VirtualBox.
Why Build an Internal Network?
Before we get our hands dirty, let's quickly chat about why you might want to do this. Setting up an internal network is incredibly useful for:
- Learning Networking: You get to see firsthand how networks operate, from routing to IP addressing.
- Testing Configurations: Safely experiment with different network setups without affecting your live environment.
- Security Practice: Simulate security threats and test your defense mechanisms in a controlled environment.
- Application Development: Deploy and test client-server applications in a realistic network setting.
Basically, it's your own personal lab for all things networking! Now, let's get started.
Prerequisites
Here’s what you’ll need to get this party started:
- VirtualBox: Make sure you have VirtualBox installed on your machine. It’s free and available for Windows, macOS, and Linux.
- Linux Mint ISO: Download the ISO images for Linux Mint. We’ll be using this to create our virtual machines.
- Basic Linux Knowledge: A little familiarity with Linux commands will go a long way.
Step 1: Creating the Virtual Machines
First, we need to create three virtual machines in VirtualBox:
- Client VM: This will simulate a regular client machine accessing the network.
- Router VM: This will act as our network's router, directing traffic between the client and server.
- Server VM: This will be the server providing services to the client.
Creating the Client VM
- Open VirtualBox and click on "New."
- Name it “Client-VM” and select Linux Mint as the type and version.
- Allocate some RAM (e.g., 1GB should be fine).
- Create a virtual hard disk (VDI) – 20GB should be plenty.
- Once the VM is created, go to its settings:
- Under "Network," attach the adapter to “Internal Network” and name the network (e.g., “InternalNet”).
Creating the Router VM
- Create another VM named “Router-VM,” using the same Linux Mint settings.
- Allocate RAM and create a virtual hard disk as before.
- For the Router VM, we need two network adapters:
- Adapter 1: Attach to “Internal Network” and use the same name as the Client VM (“InternalNet”).
- Adapter 2: Attach to “NAT” (Network Address Translation). This allows the Router VM to access the internet for updates and package installations.
Creating the Server VM
- Create the final VM named “Server-VM,” with Linux Mint settings.
- Allocate RAM and create a virtual hard disk.
- For the Server VM:
- Attach the adapter to “Internal Network” and use the same network name (“InternalNet”).
Now you should have three VMs, all connected to the same internal network. Time to install Linux Mint on each of them!
Step 2: Installing Linux Mint on Each VM
Boot each VM using the Linux Mint ISO you downloaded. Follow the on-screen instructions to install Linux Mint on each virtual machine. You can use the default settings for most options. During the installation, create a user account for each VM.
Once the installations are complete, shut down all the VMs. We need to configure the network settings before we start using them.
Step 3: Configuring the Network Settings
The key to making this internal network work is properly configuring the network interfaces on each VM.
Configuring the Router VM
The Router VM is the heart of our network. It needs to:
- Have static IP addresses for both network interfaces.
- Enable IP forwarding to route traffic.
- Configure NAT to allow the internal network to access the internet.
-
Start the Router VM.
-
Identify Network Interfaces: Open a terminal and use the
ip addrcommand to identify the names of your network interfaces (e.g.,eth0,eth1,enp0s3,enp0s8). Usually, the interface connected to the internal network iseth1orenp0s8, and the one connected to NAT iseth0orenp0s3. We can verify usingip link show. Useroute -ncommand to show Kernel IP routing table. -
Edit the
/etc/network/interfacesfile:sudo nano /etc/network/interfacesAdd the following configuration (replace
eth1andeth0with your actual interface names):# Internal Network Interface auto eth1 iface eth1 inet static address 192.168.10.1 netmask 255.255.255.0 # NAT Interface auto eth0 iface eth0 inet dhcp -
Enable IP Forwarding:
-
Edit the
/etc/sysctl.conffile:sudo nano /etc/sysctl.conf -
Uncomment the line
#net.ipv4.ip_forward=1by removing the#. -
Apply the changes:
sudo sysctl -p
-
-
Configure NAT:
-
Use
iptablesto set up NAT. First, identify the correct interface connected to the internet (e.g.,eth0). Then run:sudo iptables -t nat -A POSTROUTING -o eth0 -j MASQUERADE sudo iptables -A FORWARD -i eth1 -o eth0 -m state --state RELATED,ESTABLISHED -j ACCEPT sudo iptables -A FORWARD -i eth0 -o eth1 -j ACCEPT -
Make the NAT configuration persistent: Install
iptables-persistentto save the rules across reboots:sudo apt-get install iptables-persistentWhen prompted, save the current IPv4 and IPv6 rules.
-
-
Restart the networking service:
sudo systemctl restart networking
Configuring the Client VM
The Client VM needs to:
- Have a static IP address within the same subnet as the Router VM.
- Use the Router VM as its gateway.
- Use a DNS server for name resolution.
-
Start the Client VM.
-
Edit the
/etc/network/interfacesfile:sudo nano /etc/network/interfacesAdd the following configuration (replace
eth0orenp0s3with your actual interface name):auto eth0 iface eth0 inet static address 192.168.10.10 netmask 255.255.255.0 gateway 192.168.10.1 dns-nameservers 8.8.8.8 8.8.4.4 -
Restart the networking service:
sudo systemctl restart networking
Configuring the Server VM
The Server VM needs a static IP address within the same subnet as the Router and Client VMs.
-
Start the Server VM.
-
Edit the
/etc/network/interfacesfile:sudo nano /etc/network/interfacesAdd the following configuration (replace
eth0orenp0s3with your actual interface name):auto eth0 iface eth0 inet static address 192.168.10.20 netmask 255.255.255.0 gateway 192.168.10.1 dns-nameservers 8.8.8.8 8.8.4.4 -
Restart the networking service:
sudo systemctl restart networking
Step 4: Testing the Network
Alright, let’s see if all our hard work paid off!
-
Ping the Router from the Client:
-
On the Client VM, open a terminal and run:
ping 192.168.10.1 -
You should get replies from the Router VM.
-
-
Ping the Client from the Router:
-
On the Router VM, open a terminal and run:
ping 192.168.10.10 -
You should get replies from the Client VM.
-
-
Ping the Server from the Client:
-
On the Client VM, open a terminal and run:
ping 192.168.10.20 -
You should get replies from the Server VM.
-
-
Test Internet Access from the Client:
-
On the Client VM, try pinging a public website:
ping google.com -
If everything is configured correctly, you should get replies, indicating that the Client VM can access the internet through the Router VM.
-
Step 5: Setting up SSH (Optional)
For easier management, you might want to set up SSH access to the Server and Router VMs. Here’s how:
On the Server VM:
-
Install the SSH server:
sudo apt-get update sudo apt-get install openssh-server -
Start the SSH service:
sudo systemctl start ssh sudo systemctl enable ssh
On the Client VM:
-
SSH into the Server VM:
ssh username@192.168.10.20Replace
usernamewith your username on the Server VM. Enter the password when prompted. -
Repeat the process for the Router VM if needed:
ssh username@192.168.10.1
Now you can remotely manage your Server and Router VMs from the Client VM!
Conclusion
And there you have it! You've successfully created an internal network with a Client, Router, and Server using Linux Mint on VirtualBox. This setup is perfect for experimenting with network configurations, practicing security measures, and deploying client-server applications. Have fun exploring and tweaking your new virtual network! Remember to save snapshots of your VMs so you can easily revert to a working state if something goes wrong. Happy networking!