Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
N
namespaces
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
ISC3
vres
namespaces
Commits
06a6724f
Verified
Commit
06a6724f
authored
3 weeks ago
by
iliya.saroukha
Browse files
Options
Downloads
Patches
Plain Diff
feat: bridge part done
parent
cbbe6723
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
report/report.qmd
+140
-59
140 additions, 59 deletions
report/report.qmd
with
140 additions
and
59 deletions
report/report.qmd
+
140
−
59
View file @
06a6724f
...
...
@@ -21,103 +21,184 @@ format:
## Préparation du routeur
```bash
### Script `bash`
```{bash}
#!/usr/bin/env bash
echo "======= R1: Activating IP forwarding ======="
ssh R1 "echo 1 > /proc/sys/net/ipv4/ip_forward"
sleep 1
echo "======= R1: Obtaining IP for eth0 ======="
ssh R1 dhclient -v eth0
echo "=======
R
1: Setting up static 10.0.0.
2
/24 IP for eth
1
======="
echo "=======
H
1: Setting up static 10.0.0.
1
/24 IP for eth
0
======="
ssh H1 ip addr add 10.0.0.1/24 dev eth0
sleep 1
ssh H1 ip link set up dev eth0
sleep 1
echo "======= R1: Setting up static 10.0.0.2/24 IP for eth1 ======="
ssh R1 ip addr add 10.0.0.2/24 dev eth1
sleep 1
ssh R1 ip link set up dev eth1
sleep 1
echo "======= H1: Setting default route via R1 (i.e. 10.0.0.2) ======="
ssh H1 ip route add default via 10.0.0.2
sleep 1
echo "======= R1: Implementing NAT gateway ======="
scp ./r1_nat.ruleset root@R1:/root
ssh R1 nft -f ./r1_nat.ruleset
echo "======= H1 and R1: Installing tcpdump ======="
ssh H1 apt update
sleep 1
ssh H1 apt update
ssh H1 apt install -y tcpdump
sleep 1
ssh R1 apt update
sleep 1
ssh R1 apt update
ssh R1 apt install -y tcpdump
sleep 1
echo "======= R1: Implementing NAT gateway ======="
scp ./r1_nat.ruleset root@R1:/root
sleep 1
ssh R1 chmod +x ./r1_nat.ruleset
sleep 1
ssh R1 ./r1_nat.ruleset
sleep 1
```
#
# Routeur virtuel routé
# Routeur virtuel routé
###
Préparation
###
Script `bash`
- Création de `ns-default` et `ns2` sur R1
```{bash}
#!/usr/bin/env bash
```bash
ip netns add ns2
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
```
- Création d'une paire d'interfaces virtuelles
### Vérification
```bash
ip link add default-veth1 type veth peer name ns2-veth1
ip link add default-veth0 type veth peer name ns2-veth0
```

- Assignation des interfaces virtuelles aux namespaces

```bash
ip link set ns2-veth0 netns ns2
ip link set ns2-veth1 netns ns2
```

- Configuration IP des interfaces virtuelles

```bash
ip addr add 192.168.0.1/24 dev default-veth0
ip addr add 192.168.1.1/24 dev default-veth1
```
- Lorsque R2 est utilisé, le TTL des paquets est décrémenté de 2 (valeur 52)
pas rapport à lorsqu’il n'est pas utilisé (valeur 54), expliquez pourquoi ?
- Ceci est dû au fait que le TTL du paquet ICMP est à présent décrémenté
une première fois lorsqu'il traverse la paire d'interfaces `default-veth0`
$\leftrightarrow$ `ns2-veth0` et une seconde fois par `default-veth1`
$\leftrightarrow$ `ns2-veth1`. Par conséquent le TTL est décrémenté de 2
lorsque le paquet traverse le routeur R2.
```bash
ip netns exec ns2 ip addr add 192.168.0.2/24 dev ns2-veth0
ip netns exec ns2 ip addr add 192.168.1.2/24 dev ns2-veth1
```
# Routeur virtuel bridgé
- Upping the interfaces
### Script `bash`
```bash
ip link set dev default-veth0 up
ip link set dev default-veth1 up
```
```{bash}
#!/usr/bin/env bash
```bash
ip netns exec ns2 ip link set dev ns2-veth0 up
ip netns exec ns2 ip link set dev ns2-veth1 up
```
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
- In `ns2` adding default route
echo "======= R1: Creating and upping br1 bridge ======="
ssh R1 ip link add name br1 type bridge
ssh R1 ip link set dev br1 up
```bash
ip netns exec ns2 ip r add default via 192.168.0.1
ip netns exec ns2 ip r add 10.0.0.0/24 via 192.168.1.1
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
```
## Vérification


Comme nous pouvons le remarquer sur les deux captures d'écrans précédentes, le
TTL ne change pas entre la baseline (i.e. topologie avec R1 sans namespace) et
l'utilisation de R2 de manière bridgée via le namespace **ns2**. Ceci s'explique
suite au fait que dans le cas bridgée, nous avons _de-facto_ remplacer
l'existence de R1 par celle de R2, donc le paquet traversera le même nombre
de routeurs que si le namespace n'existait pas.
# Instanciation de plusieurs routeurs virtuels sur R1
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment