Skip to content
Snippets Groups Projects
Verified Commit 9b556f31 authored by iliya.saroukha's avatar iliya.saroukha :first_quarter_moon:
Browse files

feat: part 2 fully finished

parent 11326cc6
No related branches found
No related tags found
No related merge requests found
#!/usr/bin/env bash
echo "======= R1: Creating ns2 namespace ======="
ssh R1 ip netns add ns2
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: Configuring IPs for ns-default veths ======"
ssh R1 ip addr add 192.168.0.1/24 dev default-veth0
ssh R1 ip addr add 192.168.1.1/24 dev default-veth1
echo "======= R2: Configuring IPs for ns2 veths ======"
ssh R1 ip netns exec ns2 ip addr add 192.168.0.2/24 dev ns2-veth0
ssh R1 ip netns exec ns2 ip addr add 192.168.1.2/24 dev ns2-veth1
echo "======= R1: Upping the veths ======"
ssh R1 ip link set dev default-veth0 up
ssh R1 ip link set dev default-veth1 up
echo "======= R2: Upping the veths ======"
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
# Effacement de la route par défaut obtenue par dhclient.
echo "======= R1: Dropping default route ======"
ssh R1 ip route delete default
# Redirection des paquets via l'interface veth qui mène à R2.
echo "======= R1: Adding default route via 192.168.1.2 ======"
ssh R1 ip route add default via 192.168.1.2 dev default-veth1
echo "======= R1: Implementing policy routing ======"
# Utilisation du policy routing pour passer par eth0 si le trafic vient de R2.
# 172.21.1.1 est la passerelle obtenue par DHCP sur le Nuage Internet.
ssh R1 "echo 100 custom >> /etc/iproute2/rt_tables"
ssh R1 ip rule add iif default-veth0 table custom
ssh R1 ip route add default via 172.21.1.1 table custom
echo "======= R2: Adding default route via 192.168.0.1 and route to 10.0.0.0/24 ======"
ssh R1 ip netns exec ns2 ip r add default via 192.168.0.1 dev ns2-veth0
ssh R1 ip netns exec ns2 ip r add 10.0.0.0/24 via 192.168.1.1 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
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment