Changes

Jump to: navigation, search

VLS2VLS-Routing

1,909 bytes removed, 13:13, 18 March 2021
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
route add -net nmcli con modify ens192 +ipv4.routes "192.168.${y}.0 netmask 255.255.255.0 gw 172.1620.${y}.1100
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>
 
== Shell Script for adding the proper routes on your VM (all Linux VMs) to other's private network ==
* set the shell variable MY_NETWORK_NO to your assigned network ID (we use 99 here is an example, please change 99 to your assigned network ID)
<pre>
export MY_NETWORK_NO=99
</pre>
* set the shell variable OTHER_NETWORKS to the list of private network you want to create a route. The following example assign the list of network numbers 32, 33, 34, 35, 40, 41, and 99 that you want to create a route on your gateway:
<pre>
export OTHER_NETWORKS="32 33 34 35 40 41 99"
</pre>
The following Bash script to add 7 new route to your VM's routing table:
<pre>
#! /bin/bash
if [ -z "$MY_NETWORK_NO" ]
then
echo "Please run the following command to assign your network number" >&2
echo "to the shell varible MY_NETWORK_NO and run this script again." >&2
echo "Please replace xx with your actual network number." >&2
echo " export MY_NETWORK_NO=xx" >&2
exit 1
fi
X=${MY_NETWORK_NO}
echo "Your Network Number is $X"
if [ -z "$OTHER_NETWORKS" ]
then
echo "Please run the following command to assign the list of " >&2
echo "private networks you want to add a route on your gateway " >&2
echo "to the shell variable OTHER_NETWORKS and run this script again." >&2
echo "The following command assign 32, 33, 34, 35, 40, 41, and 99" >&2
echo "to the variable OTHER_NETWORKS. Please replace those number" >&2
echo "with the ones you actually wanted." >&2
echo " export OTHER_NETWORKS=\"32 33 34 35 40 41 99\"" >&2
exit 2
fi
Y=${OTHER_NETWORKS}
echo "Route to be add for the network number(s) $Y"
echo -n "Press ENTER to continue ... "
read dummy
 
# Add new route
for y in $Y
do
if [ "$X" -ne "$y" ]
then
route add -net 192.168.${y}.0 netmask 255.255.255.0 gw 192.168.${X}.1
echo "Adding route to 192.168.${y}.0 network via 192.168.${X}.1"
fi
 
done
 
# Add route to the 172.16.0.0 network
route add -net 172.16.0.0 netmask 255.255.0.0 gw 192.168.${X}.1
</pre>
1,760
edits

Navigation menu