In this blog, I’m going to cover how to script interface configurations for a Virtual Machine that’s booting from a “Live” iso image. In this case, it’s a Live Raizo iso image.

In some of my earlier blogs, I’ve covered how to create a Live Raizo Virtual Machine with persistence using VirtualBox, and then configuring the interfaces and routes required to communicate between the host machine, the Live Raizo VM, and the devices running in the GNS3 software.

Live Raizo provides some short cuts to configure things like the virtual interface that connects to the GNS3 devices, performs NAT on the host interface and also configures forwarding and DHCP and DNS services.

As with most things network related, it depends on how you’d like the whole package set up, as to which shortcuts you might want to use. I wanted specific IP addresses on the host only connection and virtual connection for the GNS3 side, but I didn’t want to use NAT or the DHCP server. I did want to use DHCP to get an address from my wireless network though because that would provide the default route for Internet connectivity.

Before creating the script, don’t forget to boot the Live Raizo VM using persistence or the file won’t be saved, and to use the script each time you log in, you’ll also need to use persistence mode to access the file.

Identifying the interfaces

Before writing the script, you’ll want to identify the interfaces. In my case, I wanted to connect to the Internet using a wifi connection which provides the IP address and default gateway routing information.

1; Type “ifconfig” and press the “Enter” or “Return” key. Note from the output the MAC address for each interface. In this case, it’s the output shown after “ether” in the format xx:xx:xx:xx:xx:xx (3).

In the screenshot below we can see some of the output from the ifconfig command as well as the settings window from the VM. To get to the settings window click on “Machine” (1) and choose “Settings” from the drop-down menu, then select “Network”. You can choose the tabs for each active adapter in turn until you find the one you want. The wireless interfaces can be identified by the name (5) (802.11g is a WiFi standard) so we know that adapter 1 is associated with our wireless adapter on the VM. We can identify the MAC address of the wireless adapter (2), and match it to the MAC from the “ifconfig” command and hence we know the interface name (4) that we need to configure to use DHCP (Dynamic Host Configuration Protocol).

Identifying a wireless interface on a VM, and matching it to an interface in the OS.
Identifying a wireless interface on a VM, and matching it to an interface in the OS.

Creating the script

2; Create the file with your preferred text editor in a terminal session. I chose the “nano” text editor below. The full command to open the editor was “sudo nano”, although you can name the file anything, the “.sh” extension indicates that it’s a bash shell script. You’ll need elevated privileges to save the file once complete, hence the “sudo” at the beginning of the line. The file will be created in the “/home/user” directory unless you’ve changed to another, in which case you can check the directory you are in by typing “pwd” followed by “Enter” to see the path

How to script interface configurations in Linux, using nano to create a bash shell script.
Scripting interface configurations in Linux using the nano text editor

3; The above script configures all the interfaces I had on the VM as well as configuring forwarding and then printing out the interfaces, along with the configured addresses and the routing table. Below is an explanation of each line.

#!/bin/bash – pointer to the bash shell
sudo dhclient enp0s3 – set the interface enp0s3 to use DHCP to get its IP address
sudo ifconfig enp0s8 – set the interface IP address and netmask of the enp0s8 interface
sudo ifconfig virbr0 – set the interface IP address and netmask of the virbr0 interface
sudo sysctl -w net.ipv4.ip_forward=1 – make the VM forward packets from one interface to another if required.
ifconfig | egrep “192|0s8|0s3|br0” – print lines from the ifconfig command that include “192” or “0s8” or “0s3” or “br0” you may want to use a different egrep expression or just us “ifconfig” on its own.
netstat -rn – print out the routing table in number format

4; Once you’re happy with the script then type “Ctrl” and “x” to exit, then choose “Y” to save. You can just press the “Enter” key to save with the existing name or type a new name, followed by “Enter”.

Preparing and running the script

5; The script needs to be executable and we can check to see if it is by typing “ls -l” followed by return. Below the script is first in the list. The -rw-r–r– indicates to us that the owner of the file (user) has read and write access, anybody in the group (also called user) has read access, and anyone else has read access. It isn’t executable for any users, and that needs changing before the script can be run.

6; Making the script executable can be done with the linux command “chmod” or change mode. As a minimum, one of either the owner, the group, or any other user needs to have executable access to run the script. If you type “sudo chmod 764” followed by return this will result in changing the parameters to -rwx-rw-r–, so the file becomes executable by the owner, read writeable by the group and readable by any other user. The output from the second “ls-l” command shows this below.

How to script interface configurations in Linux, Activating and running a script in Linux.
Activating and running a script in Linux

Running the script

7; Once the script is executable and we are in the same folder as the script (we can type “ls” followed by return and see the script in the output), then typing either “./” or “bash” will run the script.

The output from the script is shown above. “net.ipv4.ip_forward = 1” shows that it has configured forwarding, we can also see each interface has been configured with an IP address and our routing table has a default route, (the one with a destination of

If the wireless interface does not get an IP address, check first that the host has connected and authenticated to the WiFi hotspot and has an IP address.

You can test the effects of the script by either trying to ping an Internet address, for example, “ping” or starting the graphical user interface and browsing to the Internet using the built-in Live Raizo web browser.

To cut a long story short, the summary

This blog covered how to script interface configurations for a Virtual Machine that’s booting from a “Live” iso image.

This required identifying the interfaces in the Virtual Machine and matching them with the interfaces in the Operating System, then writing an appropriate script, followed by making the script executable and finally running the script and inspecting the output.

If you’re a network engineer and you could use an IPv4 subnet calculator check out the free techiedoodah IPv4 excel subnet calculator spreadsheet and if you get a lot of time hands on rackside and need a tray to put your laptop on, let us know what you think of the Portable Rack Mount Laptop Tray and sign up if you want one. Type with two hands instead of one, be more comfortable, improve your productivity and get out of the server room sooner, (or wherever the rack happens to be).

Techiedoodah blogs are created in the hope that they can help others by giving real-life examples. If this has been useful to you please feel free to leave a comment. If you’re reading this post on the home page, you won’t be able to post comments here, so follow this link to the blog, and then scroll to the comments section at the bottom of the page.

Comments for How to script interface configurations for a Virtual Machine that’s booting from a “Live” iso image .