脚本来源地址
路由原理
/script/single-router.sh
#!/bin/sh
# Author: fasion
# Created time: 2020-10-16 08:28:12
# Last Modified by: fasion
# Last Modified time: 2020-12-10 08:45:42
SELF_PATH=`realpath "$0"`
SCRIPT_DIR_PATH=`dirname "$SELF_PATH"`
source "$SCRIPT_DIR_PATH/nsvm-util.sh"
create-host() {
name="$1"
network="$2"
iface="$3"
mac="$4"
ip="$5"
routes="$6"
create-node "$name"
disable-ipv6-for-nsvm "$name" || exit
connect-node-to-network "$name" "$network" "$iface" "$mac" "$ip"
add-routes-for-nsvm "$node" "$routes"
# exec-in-nsvm "$node" ip route add default via "$gw" || exit
}
#禁止IP V6
echo 1 > /proc/sys/net/ipv6/conf/all/disable_ipv6 || exit
# 创建第一个交换机
create-network net1 || exit 1
# 创建一个节点,分别是名字/放在那个以太网下/网卡/mac/IP/路由
# 这里不懂的是IP和路由
# 实际的创建过程需要细看👀
create-host ant net1 eth0 '1e:1f:84:08:d2:aa' 192.168.1.2/24 192.168.1.1:192.168.2.0/24 || exit
create-host bee net1 eth0 'e6:04:b1:10:f1:bb' 192.168.1.3/24 192.168.1.1:192.168.2.0/24 || exit
create-host cicada net1 eth0 'ce:ba:ec:ff:fd:cc' 192.168.1.4/24 192.168.1.1:192.168.2.0/24 || exit
# 创建第二个交换机
create-network net2 || exit 1
create-host apple net2 eth0 'b6:f1:81:44:21:11' 192.168.2.2/24 192.168.2.1:192.168.1.0/24 || exit
create-host banana net2 eth0 '22:5b:7c:b3:d6:22' 192.168.2.3/24 192.168.2.1:192.168.1.0/24 || exit
# 创建路由器
create-node router || exit
disable-ipv6-for-nsvm router || exit
# 添加路由条目
connect-node-to-network router net1 eth1 'fa:1c:b2:d0:b0:01' 192.168.1.1/24 || exit
connect-node-to-network router net2 eth2 'ee:21:30:4a:5a:02' 192.168.2.1/24 || exit
echo 'press Ctrl-C to exit'
# zsh
cat