Setup a Virtual Network using GNS3
This is the second part of this article series, you can refer to the other articles from below.
- Setup a Virtual Network in Oracle VM
- Setup a Virtual Network using GNS3
- Emulate a DHCP Server in a Network
Scenario
In this article, we are going to use Oracle VM to run 3 linux servers which will act as a router and the remaining 2 servers as devices in a network. Here the 2 devices are in 2 different networks and the networks are connected through the router. And also the end devices are connected to switch and the switch is connected to the router.
Prerequisites
As the prerequisites,
- You need to download and install Oracle Virtual Box
- Create 3 Virtual Machines in the Oracle Virtual box
- Download and install GNS3
VM configurations
You can follow the Article 01 for configuring the VMs in the Oracle Virtual Box. Please note that when you are configuring the VMs follow the below steps for this session.
In the settings of all the 3 VMs, modify the network settings as below where the Network Adaptor ‘Attached to:’ as ‘Not Attached’.
Setting up Project in GNS3
You can follow the below steps to add the created VMs to GNS3 workspace.
- Open GNS3
- Navigate to File -> Preferences
- Select VirtualBox -> VirtualBox VMs
- Select ‘New’ and add the VMs created
- Once you add the 3 VMs to GNS3, click on ‘Apply’ and ‘Ok’.
- Now let’s create a new project in GNS3. Click on File -> New Blank Project.
- Then provide a name for the project and choose the location to save the project.
- Then from the left panel, click on ‘Browse End Devices’
- Drag and drop the 3 devices to the workspace. So it will look like below.
- Then let’s add switches to our network. Click on the ‘Browse All Devices’ from the left side panel. Drag and drop 2 ‘Ethernet Switch’ to workspace.
- Right click on the device used for the router and select ‘Configure’. Select the ‘Network’ tab and modify the ‘Adaptors’ as 2.
- Then we can connect the devices using the links. For that use the option ‘Add a link’ from the left side panel.
- Now you can run the network. When you click on the ‘Start’ button it will start the VMs.
- So the devices are started, we can start configuring them. The IP configurations used are as below.
Configure the Router
Let’s start by configuring the router. You can refer to the article 01 for more information on the below configurations.
1. List the network adaptors available.
ifconfig
2. Set the network adaptor with IP addresses
sudo ifconfig eth0 192.168.1.1 netmask 255.255.255.0
sudo ifconfig eth1 192.168.2.1 netmask 255.255.255.0
3. Once you set the above, network adaptors will display the above information with ‘ifconfig’ command.
4. Enable IP forwarding in the router.
sudo sysctl -w net.ipv4.ip_forward=1
Configure End Device 01
Then let’s configure the Device01.
1. List the network adaptors available.
ifconfig
2. Set the network adaptor with IP addresses
sudo ifconfig eth0 192.168.1.10 netmask 255.255.255.0
3. Set the default gateway for the device
sudo route add default gw 192.168.1.1 eth0
Configure the Device 02
Similarly, let’s configure the Device02.
1. List the network adaptors available.
ifconfig
2. Set the network adaptor with IP addresses
sudo ifconfig eth0 192.168.2.10 netmask 255.255.255.0
3. Set the default gateway for the device
sudo route add default gw 192.168.2.1 eth0
Test the Connectivity
Now you should be able to ping 192.168.2.10 from Device01 and ping 192.168.1.10 from Device02.
What does the Switch Do?
Please note that we have not done any configuration at the switch, because a switch operates at Layer 2 of the OSI model, dealing with MAC addresses to forward data between devices in a local network. Below is what happens in a switch at high level.
Step 1: A device (A) wants to communicate with another device (B) on the same network but only knows B’s IP address, not its MAC address.
Step 2: Device A sends an ARP request (broadcast) to the entire network.
Step 3: The switch forwards the ARP request to all devices connected to its ports.
Step 4: Device B, recognizing its IP address in the ARP request, responds with its MAC address in an ARP reply.
Step 5: The switch learns the MAC address of Device B from the ARP reply and updates its MAC address table. Now, the switch can forward future traffic from Device A to Device B directly.
So that’s all I’m going to discuss in this article. Let’s meet from another article soon.