1,760
edits
Changes
→Automate the process using BASH script
= Automate the process using BASH script =
The above example shows that 12 route commands will be 2 custom routes on each VLS are needed to create provides the necessary routes just for 3 virtual networks, each with a proper routing to reach 2 other VLS on the your gateway and one VM(VM1). It will be difficult quite time consuming to manage all the routes if the number of virtual networks VLS is much greater(how about 40 VLSs?). The following script will be more practical if your need to set up all the necessary routes for a large number of virtual networksVLSs. Both script scripts use the shell environment variables "MY_NETWORK_NOMY_VLS_NO" and "OTHER_NETWORKSOTHER_VLS_NOS" to allow customization for different values of private network addressVLSs.
== Shell Script for adding the proper custom routes on your gateway to other's private network VLSs ==* set the shell variable MY_NETWORK_NO MY_VLS_NO to your assigned network ID (we I use 99 2 here is as an example, please change 99 2 to your assigned network ID)
<pre>
export MY_NETWORK_NOMY_VLS_NO=992
</pre>
* set the shell variable OTHER_NETWORKS OTHER_VLS_NOS to the list of private network VLS you want to create have a routeto their VLS network. The following example assign the list of network numbers 32, 33, 34, 35, 4041, 4142, and 99 43 that you want to create a custom route on your gateway:
<pre>
export OTHER_NETWORKS="32 33 34 35 40 41 9942 43"
</pre>
The following Bash script to add 7 new route custom routes to your gateway hostVM's routing table:
<pre>
#! /bin/bash
if [ -z "$MY_NETWORK_NOMY_VLS_NO" ]
then
echo "Please run the following command to assign your network number" >&2
echo "to the shell varible MY_NETWORK_NO MY_VLS_NO and run this script again." >&2
echo "Please replace xx with your actual network number." >&2
echo " export MY_NETWORK_NOMY_VLS_NO=xx" >&2
exit 1
fi
X=${MY_NETWORK_NOMY_VLS_NO}
echo "Your Network Number is $X"
if [ -z "$OTHER_NETWORKSOTHER_VLS_NOS" ]
then
echo "Please run the following command to assign the list of " >&2
echo "private networks VLS Networks you want to add a route on your gateway " >&2 echo "to the shell variable OTHER_NETWORKS OTHER_VLS_NOS and run this script again." >&2 echo "The following command assign 32, 33, 34, 35, 4041, 4142, and 9943" >&2 echo "to the variable OTHER_NETWORKSOTHER_VLS_NOS. Please replace those number" >&2
echo "with the ones you actually wanted." >&2
echo " export OTHER_NETWORKSOTHER_VLS_NOS=\"32 33 34 35 40 41 9942 43\"" >&2
exit 2
fi
Y=${OTHER_NETWORKSOTHER_VLS_NOS}echo "Route to be add added for the network number(s) $Y"
echo -n "Press ENTER to continue ... "
read dummy
if [ "$X" -ne "$y" ]
then
echo "Adding route to 192.168.${y}.0 network."
fi
done
nmcli con down ens192nmcli con up ens192ip route show # enable IP forwarding on the gateway, add "net.ipv4.ip_forward = 1" to /etc/sysctl.conf
echo "1" > /proc/sys/net/ipv4/ip_forward
</pre>