Changes

Jump to: navigation, search

VLS2VLS-Routing

2,206 bytes removed, 13:02, 22 March 2021
Shell Script for adding custom routes on your gateway to other's VLSs
* ip route show
== Manually Configure routes on each VM in each virtual network VLS ==You only need to create the custom routes on the VM in your VLS, but make sure that other students have proper routes on their VMs as well.=== VLS 1 VM2 to VM4 ===On Virtual Network VLS 1's VM (192.168.1.2 .. 192.168.1.2544)* route add -net nmcli con modify ens224 +ipv4.routes "192.168.2.0 netmask 255.255.255.0 gw /16 192.168.1.1100"* nmcli con down ens224* nmcli con up ens224* ip route add -net 192.168.3.0 netmask 255.255.255.0 gw 192.168.1.1show
=== VLS 2 VM2 to VM4 ===On Virtual Network VLS 2's VM (192.168.2.2 .. 192.168.12.2544)* route add -net nmcli con modify ens224 +ipv4.routes "192.168.1.0 netmask 255.255.255.0 gw /16 192.168.2.1100"* nmcli con down ens224* nmcli con up ens224* ip route add -net 192.168.3.0 netmask 255.255.255.0 gw 192.168.2.1show
=== VLS 3 VM2 to VM4 ===On Virtual Network VLS 3's VM (192.168.3.2 .. 192.168.3.2544)* route add -net nmcli con modify ens224 +ipv4.routes "192.168.1.0 netmask 255.255.255.0 gw /16 192.168.3.1100"* nmcli con down ens224* nmcli con up ens224* ip route add -net 192.168.2.0 netmask 255.255.255.0 gw 192.168.3.1show
= 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 edit 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, 40, 41, and 99 1 to 43 that you want to create a custom route on your gateway:.
<pre>
export OTHER_NETWORKS OTHER_VLS_NOS="32 33 34 35 40 41 99"`seq 1 43`
</pre>
 The following Bash script to add 7 42 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_NETWORKS" ]then echo "Please run # change 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" >&2if necessary echo "with the ones you actually wanted." >&2 echo " export OTHER_NETWORKSOTHER_VLS_NOS=\"32 33 34 35 40 41 99\"" >&2`seq 1 43` exit 2fiY=`echo ${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 /24 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