diff --git a/scripts/bridge.sh b/scripts/bridge.sh new file mode 100755 index 0000000000000000000000000000000000000000..cbb9c215333993067f056d919500d5ab63ac26e5 --- /dev/null +++ b/scripts/bridge.sh @@ -0,0 +1,56 @@ +#!/usr/bin/env bash + +echo "======= R1: Creating ns2 namespace =======" +ssh R1 ip netns add ns2 + +echo "======= R2: Activating IP forwarding =======" +ssh R1 ip netns exec ns2 sysctl net.ipv4.ip_forward=1 + +echo "======= R1: Creating veth pair (for veth0 and veth1) and moving them to ns2 =======" +ssh R1 ip link add default-veth1 type veth peer name ns2-veth1 netns ns2 +ssh R1 ip link add default-veth0 type veth peer name ns2-veth0 netns ns2 + +echo "======= R1: Creating and upping br1 bridge =======" +ssh R1 ip link add name br1 type bridge +ssh R1 ip link set dev br1 up + +echo "======= R1: Connecting and upping default-veth1 to br1 =======" +ssh R1 ip link set default-veth1 master br1 +ssh R1 ip link set dev default-veth1 up + +echo "======= R1: Connecting and upping eth1 to br1 =======" +ssh R1 ip link set eth1 master br1 +ssh R1 ip link set dev eth1 up + +echo "======= R1: Creating and upping br0 bridge =======" +ssh R1 ip link add name br0 type bridge +ssh R1 ip link set dev br0 up + +echo "======= R1: Connecting and upping default-veth1 to br1 =======" +ssh R1 ip link set default-veth0 master br0 +ssh R1 ip link set dev default-veth0 up + +echo "======= R1: Connecting and upping eth0 to br0 =======" +ssh R1 ip link set eth0 master br0 +ssh R1 ip link set dev eth0 up + +echo "======= R2: Upping the veths in ns2 =======" +ssh R1 ip netns exec ns2 ip link set dev ns2-veth0 up +ssh R1 ip netns exec ns2 ip link set dev ns2-veth1 up + +echo "======= R2: Obtaining IP for ns2-veth0 via DHCP =======" +ssh R1 ip netns exec ns2 dhclient -v ns2-veth0 + +echo "======= R2: Configuring static 10.0.0.2 IP for ns2-veth1 =======" +ssh R1 ip netns exec ns2 ip addr add 10.0.0.2/24 dev ns2-veth1 + +echo "======= R2: Implementing NAT inside ns2 ======" +scp ./r2_nat.ruleset root@R1:/root +ssh R1 ip netns exec ns2 nft -f ./r2_nat.ruleset + +echo "======= H1: Setting up static 10.0.0.1/24 IP for eth0 =======" +ssh H1 ip addr add 10.0.0.1/24 dev eth0 +ssh H1 ip link set dev eth0 up + +echo "======= H1: Setting default route via R1 (i.e. 10.0.0.2) =======" +ssh H1 ip route add default via 10.0.0.2