Last active
January 26, 2021 20:46
-
-
Save da667/ce39d245bd9d6bd30a205156a48ec67e to your computer and use it in GitHub Desktop.
equivalent of the flightcheck-OSX.sh script. Checks to see if vmnet1 (vmware workstation pro) or vboxnet0 (virtualbox) exists, sets its IP to 172.16.1.2/24, then creates a route to 172.16.2.0 via 172.16.1.1
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
#This script is meant for VMware Workstation Professional, or Oracle Virtualbox users on most modern Linux Distributions. | |
#Ensure that the Linux distro you will be running this on has the ip [addr/route] command available. | |
#This script checks for the existence of the interface vmnet1 (vmware workstation) or vboxnet0 (virtualbox) | |
#and will assign the IP address 172.16.1.2 to the first interface it finds. The script will check to see if vmnet1 exists, then check for vboxnet0 | |
#if neither interface exists, the script will fail. | |
#after setting the IP address, the script attempts to add a static route to the 172.16.2.0 network via 172.16.1.1 (LAN interface of the pfSense VM) | |
#Note: If you are using alternative networks for your lab other than 172.16.1.0/24, and 172.16.2.0/24, you will have to modify the ip route and ip addr add statements on lines 42, 55, and 75 on your own to reflect your lab network properly. You may also want to change the echo statements on lines 41, 44, 56, 58, 73, and 80 if you care about the output reflecting the changes you made. | |
### Notifying users to have VMs up and running ### | |
echo "Warning: Please make sure that all of your vmware workstation OR oracle virtualbox VMs are running. In particular, the pfSense VM MUST be running!" | |
read -p "Once you have verified that your VMs are up and running, Press enter to continue." | |
################################################## | |
### Root privilege check ### | |
echo "Checking for root privs.." | |
if [ $(whoami) != "root" ]; then | |
echo "This script must be ran with sudo or root privileges." | |
exit 1 | |
else | |
echo "We are root." | |
fi | |
################################################## | |
### Check to see if vmnet1 or vboxnet0 exist. ### | |
### If either interface exists, flush its current IP address config. ### | |
### Then set the IP address to 172.16.1.2 with a netmask of 255.255.255.0. ### | |
### If neither interface exists, we inform the user and abort the script. ### | |
echo "Checking to see if vmnet1 exists..." | |
ip addr show dev vmnet1 > /dev/null 2>&1 | |
if [ $? -eq 0 ]; then | |
echo "vmnet1 exists. Flushing current IPv4 address..." | |
ip -4 addr flush label "vmnet1" > /dev/null 2>&1 | |
echo "Setting IP to 172.16.1.2/24..." | |
ip addr add 172.16.1.2/24 dev vmnet1 | |
if [ $? -eq 0 ]; then | |
echo "vmnet1 interface IP set to 172.16.1.2" | |
else | |
echo "Could not set IP address of vmnet1 interface. You got troubleshooting to do. Aborting." | |
exit 1 | |
fi | |
else | |
echo "vmnet1 interface does not exist. Checking to see if vboxnet0 exists..." | |
ip addr show dev vboxnet0 > /dev/null 2>&1 | |
if [ $? -eq 0 ]; then | |
echo "vboxnet0 interface exists. Flushing current IPv4 address..." | |
ip -4 addr flush label "vboxnet0" > /dev/null 2>&1 | |
ip addr add 172.16.1.2/24 dev vboxnet0 | |
echo "Setting IP to 172.16.1.2/24..." | |
if [ $? -eq 0 ]; then | |
echo "vboxnet0 interface IP set to 172.16.1.2" | |
else | |
echo "Could not set IP address of vboxnet0 interface. You got troubleshooting to do. Aborting." | |
exit 1 | |
fi | |
else | |
echo "vboxnet0 interface does not exist. This script only checks for vmnet1 or vboxnet0. Aborting." | |
exit 1 | |
fi | |
fi | |
####################################################################################################### | |
### Adding static route ### | |
echo "Adding static route to 172.16.2.0/24 via 172.16.1.1..." | |
ip route add 172.16.2.0/24 via 172.16.1.1 | |
if [ $? -ne 0 ]; then | |
echo "Could not create route to 172.16.2.0/24. Does the network exist? Is vmware fusion running? Is virtualbox running? Is the pfSense/gateway VM running? Does the pfSense LAN interface have the correct IP address?" | |
exit 1 | |
else | |
echo "added route to 172.16.2.0/24 via 172.16.1.1." | |
fi | |
########################### | |
exit 0 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Note: If you are using alternative networks for your lab other than 172.16.1.0/24, and 172.16.2.0/24, you will have to modify the ip route and ip addr add statements on lines 42, 55, and 75 on your own to reflect your lab network properly. You may also want to change the echo statements on lines 41, 44, 56, 58, 73, and 80 if you care about the output reflecting the changes you made.
Please be aware this script assumes that your lab environment (or at least the pfSense virtual machine) is fully configured, and capable of routing traffic between network segments correctly.