Virtual Router with OpenWRT

In this tutorial, we will present a way to use a virtual router with OpenWRT for internal virtual machines. For this, we are going to use OpenWRT in a virtual machine.

This way, from this virtual machine, we will allow other virtual machines on the internal network to use OpenWRT to access the Internet.

Initially we will use the configuration we used in the article: Installing OpenWRT in VirtualBox https://simplificandoredes.com/en/openwrt-in-virtualbox/

This way, we will access the OpenWRT virtual machine using the real machine to configure the necessary settings.

Class 1: Installing OpenWRT in VirtualBox

Lesson 2: Virtual Router with OpenWRT

Modifying the OpenWRT interface in VirtualBox

The first step is to access the IP of the VirtualBox interface that is in “host-only” mode. In this case, virtualbox gave the IP 192.168.56.102 to the OpenWRT virtual machine. 

OpenWRT web interface

Remember that this IP may vary depending on its implementation. That way, if in doubt, you can directly type in the OpenWRT virtual machine the command below to check the IPs.

ip addr 
Check LAN access IP

After accessing the Interfaces tab, let’s select “Edit” on the LAN interface, as shown in the figure below. 

Editing the LAN interface

Entering a static IP for OpenWRT LAN

Next, let us change the “Protocol” mode to “Static address”. In this way, we will be able to enter an IP in our LAN interface manually.

Switching the interface to static mode

 
After that, let’s click on the option “Switch Protocol”, as in the picture below. 

Click switch protocol

After clicking on “Switch Protocol”, we will start the manual configuration of the LAN interface. For this, we will enter the IP of the interface in the field “IPv4 address” and then the netmask in “Ipv4 netmask”

Next, we have the option of “Ipv4 gateway”. In this case, OpenWRT tries to auto-populate using the WAN IP.

Enter the IP mask and alternate DNS

Also, we can enter an alternate DNS, in our case we are using google DNS (8.8.8.8). 

After doing the configuration and saving, let’s click on “Save & Apply”. 

Click Save&Apply

Changing Networking from VirtualBox to OpenWRT

Now shut down the virtual machine. Next, we are going to select the OpenWRT virtual machine, and we are going to change the interface configuration. Therefore, we will change the interface previously in “host-only Adapter” mode to “Internal Network” in this case.

It is worth mentioning that we have to give a name to the “Internal Network” interface. Due to our low creativity, we will call it “Internal_Network”

Modifying the network interface in VirtualBox

Configuring the Client Virtual Machine

Now we are going to use a client machine. Therefore, we will configure the network interface to “Internal Network,” and we will use the same network name as “Internal_Network”.

Remember, “Internal_Network” was the name we gave to the internal network on the OpenWRT machine

Configuring client to same network as OpenWRT LAN

Configuring the client’s network interface

Next, we will configure an IP for the client machine and we will point to the gateway which is the IP of the OpenWRT LAN

Entering a manual IP, remember to enter the gateway = the OpenWRT LAN IP

Testing Client Access

Now, let’s open the client’s virtual machine browser and access the OpenWRT GUI. This way, we can see that we now have configuration access in OpenWRT.

Accessing the OpenWRT interface using the virtual client

In addition, we can use the client’s virtual machine browser to access the Internet using the OpenWRT virtual machine as a virtual router.

The configuration in this tutorial allows the creation of several laboratories for testing new solutions and analyzing network protocols.

Below, we have a video lesson demonstrating the entire configuration process described in this tutorial.  

If you liked it, comment on the channel.

Links:

How to install OpenWrt on Raspberry Pi

Turn the raspberry pi into a WIFI router

Virtualizing the Raspberry Pi – Raspbian

YouTube: https://www.youtube.com/c/SimplificandoRedes

External links:

https://openwrt.org/

Juliana Mascarenhas

Data Scientist and Master in Computer Modeling by LNCC.
Computer Engineer