Skip to content
Snippets Groups Projects
Commit 198fea96 authored by Denis Gremaud's avatar Denis Gremaud
Browse files

part 4 done

parent 3311b648
No related branches found
No related tags found
No related merge requests found
# v_res
ssh H1 ip address add 10.0.0.2/24 dev eth0
ssh H1 ip link set eth0 up
ssh R1 ip netns add ns2
ssh R1 ip netns add ns3
ssh R1 ip link add veth1 type veth peer name veth0 netns ns3
ssh R1 ip netns exec ns3 ip link add veth1 type veth peer name veth1 netns ns2
ssh R1 ip link add veth0 type veth peer name veth0 netns ns2
## Getting started
ssh R1 ip link set veth0 up
ssh R1 ip link set veth1 up
ssh R1 ip netns exec ns2 ip link set veth0 up
ssh R1 ip netns exec ns2 ip link set veth1 up
ssh R1 ip netns exec ns3 ip link set veth0 up
ssh R1 ip netns exec ns3 ip link set veth1 up
To make it easy for you to get started with GitLab, here's a list of recommended next steps.
ssh R1 ip link add br0 type bridge
ssh R1 ip link add br1 type bridge
Already a pro? Just edit this README.md and make it your own. Want to make it easy? [Use the template at the bottom](#editing-this-readme)!
ssh R1 ip link set eth1 master br1
ssh R1 ip link set veth1 master br1
## Add your files
ssh R1 ip link set eth0 master br0
ssh R1 ip link set veth0 master br0
- [ ] [Create](https://docs.gitlab.com/ee/user/project/repository/web_editor.html#create-a-file) or [upload](https://docs.gitlab.com/ee/user/project/repository/web_editor.html#upload-a-file) files
- [ ] [Add files using the command line](https://docs.gitlab.com/ee/gitlab-basics/add-file.html#add-a-file-using-the-command-line) or push an existing Git repository with the following command:
ssh R1 ip link set eth1 up
ssh R1 ip link set veth1 up
ssh R1 ip link set eth0 up
ssh R1 ip link set veth0 up
ssh R1 ip link set br0 up
ssh R1 ip link set br1 up
```
cd existing_repo
git remote add origin https://gitedu.hesge.ch/denis.gremaud/v_res.git
git branch -M main
git push -uf origin main
```
ssh R1 sysctl net.ipv4.ip_forward=1
ssh R1 ip netns exec ns2 sysctl net.ipv4.ip_forward=1
ssh R1 ip netns exec ns3 sysctl net.ipv4.ip_forward=1
## Integrate with your tools
ssh R1 ip netns exec ns3 ip address add 10.0.0.1/24 dev veth0
ssh R1 ip netns exec ns3 ip link set veth0 up
- [ ] [Set up project integrations](https://gitedu.hesge.ch/denis.gremaud/v_res/-/settings/integrations)
ssh R1 ip netns exec ns2 ip address add 10.0.0.3/24 dev veth1
ssh R1 ip netns exec ns2 ip link set veth1 up
## Collaborate with your team
ssh R1 ip netns exec ns3 ip route del default
ssh R1 ip netns exec ns3 ip route add default via 10.0.0.3
- [ ] [Invite team members and collaborators](https://docs.gitlab.com/ee/user/project/members/)
- [ ] [Create a new merge request](https://docs.gitlab.com/ee/user/project/merge_requests/creating_merge_requests.html)
- [ ] [Automatically close issues from merge requests](https://docs.gitlab.com/ee/user/project/issues/managing_issues.html#closing-issues-automatically)
- [ ] [Enable merge request approvals](https://docs.gitlab.com/ee/user/project/merge_requests/approvals/)
- [ ] [Automatically merge when pipeline succeeds](https://docs.gitlab.com/ee/user/project/merge_requests/merge_when_pipeline_succeeds.html)
ssh R1 ip netns exec ns2 ip route del default
ssh R1 ip netns exec ns2 dhclient -v veth0
ssh R1 ip netns exec ns2 ip link set veth0 up
## Test and Deploy
ssh H1 ip route del default
ssh H1 ip route add default via 10.0.0.1
Use the built-in continuous integration in GitLab.
- [ ] [Get started with GitLab CI/CD](https://docs.gitlab.com/ee/ci/quick_start/index.html)
- [ ] [Analyze your code for known vulnerabilities with Static Application Security Testing(SAST)](https://docs.gitlab.com/ee/user/application_security/sast/)
- [ ] [Deploy to Kubernetes, Amazon EC2, or Amazon ECS using Auto Deploy](https://docs.gitlab.com/ee/topics/autodevops/requirements.html)
- [ ] [Use pull-based deployments for improved Kubernetes management](https://docs.gitlab.com/ee/user/clusters/agent/)
- [ ] [Set up protected environments](https://docs.gitlab.com/ee/ci/environments/protected_environments.html)
***
# Editing this README
When you're ready to make this README your own, just edit this file and use the handy template below (or feel free to structure it however you want - this is just a starting point!). Thank you to [makeareadme.com](https://www.makeareadme.com/) for this template.
## Suggestions for a good README
Every project is different, so consider which of these sections apply to yours. The sections used in the template are suggestions for most open source projects. Also keep in mind that while a README can be too long and detailed, too long is better than too short. If you think your README is too long, consider utilizing another form of documentation rather than cutting out information.
## Name
Choose a self-explaining name for your project.
## Description
Let people know what your project can do specifically. Provide context and add a link to any reference visitors might be unfamiliar with. A list of Features or a Background subsection can also be added here. If there are alternatives to your project, this is a good place to list differentiating factors.
## Badges
On some READMEs, you may see small images that convey metadata, such as whether or not all the tests are passing for the project. You can use Shields to add some to your README. Many services also have instructions for adding a badge.
## Visuals
Depending on what you are making, it can be a good idea to include screenshots or even a video (you'll frequently see GIFs rather than actual videos). Tools like ttygif can help, but check out Asciinema for a more sophisticated method.
## Installation
Within a particular ecosystem, there may be a common way of installing things, such as using Yarn, NuGet, or Homebrew. However, consider the possibility that whoever is reading your README is a novice and would like more guidance. Listing specific steps helps remove ambiguity and gets people to using your project as quickly as possible. If it only runs in a specific context like a particular programming language version or operating system or has dependencies that have to be installed manually, also add a Requirements subsection.
## Usage
Use examples liberally, and show the expected output if you can. It's helpful to have inline the smallest example of usage that you can demonstrate, while providing links to more sophisticated examples if they are too long to reasonably include in the README.
## Support
Tell people where they can go to for help. It can be any combination of an issue tracker, a chat room, an email address, etc.
## Roadmap
If you have ideas for releases in the future, it is a good idea to list them in the README.
## Contributing
State if you are open to contributions and what your requirements are for accepting them.
For people who want to make changes to your project, it's helpful to have some documentation on how to get started. Perhaps there is a script that they should run or some environment variables that they need to set. Make these steps explicit. These instructions could also be useful to your future self.
You can also document commands to lint the code or run tests. These steps help to ensure high code quality and reduce the likelihood that the changes inadvertently break something. Having instructions for running tests is especially helpful if it requires external setup, such as starting a Selenium server for testing in a browser.
## Authors and acknowledgment
Show your appreciation to those who have contributed to the project.
## License
For open source projects, say how it is licensed.
## Project status
If you have run out of energy or time for your project, put a note at the top of the README saying that development has slowed down or stopped completely. Someone may choose to fork your project or volunteer to step in as a maintainer or owner, allowing your project to keep going. You can also make an explicit request for maintainers.
scp shell/nftables_R2.sh R1:~/
ssh R1 ip netns exec ns2 nft -f nftables_R2.sh
\ No newline at end of file
# Labo 2, Equipements réseaux virtuels basé sur les namespaces Linux
Auteur : [Denis Gremaud](mailto:denis.gremaud@hes-so.ch)
Date : 06-03-2023
Cours : Virtualisation des réseaux
Git : [https://gitedu.hesge.ch/denis.gremaud/v_res.git](https://gitedu.hesge.ch/denis.gremaud/v_res.git)
## Introduction
## 1 - Topologie
### A - Préparation du routeur hôte
### B - Vérification du bon fonctionnement(1)
## 2 - Routeur virtuel routé
```bash
ip netns add ns2
ip link add veth0 type veth peer name veth0 netns ns2
ip link add veth1 type veth peer name veth1 netns ns2
ip address add 192.168.0.1/24 dev veth0
ip link set veth0 up
ip address add 192.168.1.1/24 dev veth1
ip link set veth1 up
ip netns exec ns2 ip address add 192.168.0.2/24 dev veth0
ip netns exec ns2 ip link set veth0 up
ip netns exec ns2 ip address add 192.168.1.2/24 dev veth1
ip netns exec ns2 ip link set veth1 up
ip route del default
ip route add default via 192.168.1.2
ip netns exec ns2 ip route add default via 192.168.0.1
echo 100 custom >> /etc/iproute2/rt_tables
ip rule add iif veth0 table custom
ip route add default via 172.21.1.1 table custom
set nat namespace
ip netns exec ns2 nft -f nftables_R2.sh
ip netns exec ns2 ip route add 10.0.0.0/24 via 192.168.1.1
```
### A - Préparation
### B - Vérification du bon fonctionnement(2)
## 3 - Routeur virtuel bridgé
## 4 - Instanciation de plusieurs routeurs virtuels sur R1
#!/usr/sbin/nft -f
flush ruleset
table ip nat {
chain masq {
type nat hook postrouting priority 100;
oifname "veth1" counter masquerade
}
}
\ No newline at end of file
# Retrieve all the hostname found in ~/.ssh/config
HOSTS=$(grep -oP '(?<=^Host ).*' ~/.ssh/config)
echo "Retrieved theses hostnames : $HOSTS"
change_name() {
echo "Change name of $1"
ssh $1 "hostname $1"
}
active_dhcp() {
echo "Active DHCP on $1"
ssh $1 "dhclient mgmt0"
}
install_tcpdump() {
echo "Install tcpdump on $1"
ssh $1 "apt-get install -y tcpdump"
}
set_ip() {
echo "Set IP on $1"
ssh $1 "ip address add $2 dev $3"
ssh $1 "ip link set $3 up"
}
set_ip_forward() {
echo "Set IP forward on $1"
ssh $1 "sysctl net.ipv4.ip_forward=1"
}
set_ip_forward_on_ns() {
echo "Set IP forward on $1 in namespace $2"
ssh $1 "ip netns exec $2 sysctl net.ipv4.ip_forward=1"
}
create_ns() {
echo "Create namespace $1 on $2"
ssh $2 "ip netns add $1"
}
add_veth() {
echo "Add veth on $1"
ssh $1 "ip link add $2 type veth peer name $3 netns $4"
}
add_veth_namespace() {
echo "Add veth on $1 in namespace $2"
ssh $1 "ip netns exec $2 ip link add $3 type veth peer name $4 netns $5"
}
add_bridge() {
echo "Add bridge $2 on $1"
ssh $1 "ip link add $2 type bridge"
}
set_interface_to_bridge() {
echo "Set interface $2 on bridge $3 on $1"
ssh $1 "ip link set $2 master $3"
}
set_interface_up() {
echo "Set interface $2 up on $1"
ssh $1 "ip link set $2 up"
}
set_interface_up_ns() {
echo "Set interface $2 up on $1 in namespace $3"
ssh $1 "ip netns exec $3 ip link set $2 up"
}
set_ip_on_ns() {
echo "Set IP $3 on $1 in namespace $2"
ssh $1 "ip netns exec $2 ip address add $3 dev $4"
ssh $1 "ip netns exec $2 ip link set $4 up"
}
set_dhcp_on_ns() {
echo "Set DHCP on $1 in namespace $2"
ssh $1 "ip netns exec $2 ip route del default"
ssh $1 "ip netns exec $2 dhclient -v $3"
ssh $1 "ip netns exec $2 ip link set $3 up"
}
set_nat_namespace() {
echo "Set nat namespace $1 $3"
scp $2 $1:~/
ssh $1 "ip netns exec $3 nft -f $4"
echo "Nftables on $3 is done"
}
set_route_on_host() {
echo "Set route on $1"
ssh $1 "ip route del default"
ssh $1 "ip route add $2 via $3"
}
set_ip_route_on_ns() {
echo "Set route on $1 in namespace $2"
ssh $1 "ip netns exec $2 ip route add $3 via $4 dev $5"
}
delete_route_on_ns() {
echo "Delete route on $1 in namespace $2"
ssh $1 "ip netns exec $2 ip route del $3"
}
for host in $HOSTS; do
change_name $host
active_dhcp $host
install_tcpdump $host
done
set_ip_forward "R1"
set_ip "H1" "10.0.0.2/24" "eth0"
create_ns "ns2" "R1"
create_ns "ns3" "R1"
set_ip_forward_on_ns "R1" "ns2"
set_ip_forward_on_ns "R1" "ns3"
add_veth "R1" "veth1" "veth0" "ns3"
add_veth_namespace "R1" "ns3" "veth1" "veth1" "ns2"
add_veth "R1" "veth0" "veth0" "ns2"
add_bridge "R1" "br0"
add_bridge "R1" "br1"
set_interface_to_bridge "R1" "eth0" "br0"
set_interface_to_bridge "R1" "veth0" "br0"
set_interface_to_bridge "R1" "eth1" "br1"
set_interface_to_bridge "R1" "veth1" "br1"
set_interface_up "R1" "eth0"
set_interface_up "R1" "eth1"
set_interface_up "R1" "veth0"
set_interface_up "R1" "veth1"
set_interface_up_ns "R1" "veth0" "ns3"
set_interface_up_ns "R1" "veth1" "ns3"
set_interface_up_ns "R1" "veth0" "ns2"
set_interface_up_ns "R1" "veth1" "ns2"
set_interface_up "R1" "br0"
set_interface_up "R1" "br1"
set_ip_on_ns "R1" "ns3" "10.0.0.1/24" "veth0"
set_ip_on_ns "R1" "ns3" "192.168.0.2/24" "veth1"
set_ip_on_ns "R1" "ns2" "192.168.0.1/24" "veth1"
set_dhcp_on_ns "R1" "ns2" "veth0"
set_nat_namespace "R1" "shell/nftables_R2.sh" "ns2" "nftables_R2.sh"
set_nat_namespace "R1" "shell/nftables_R3.sh" "ns3" "nftables_R3.sh"
set_route_on_host "H1" "default" "10.0.0.1"
delete_route_on_ns "R1" "ns3" "default"
set_ip_route_on_ns "R1" "ns3" "default" "192.168.0.1" "veth1"
set_ip_route_on_ns "R1" "ns2" "10.0.0.0/24" "192.168.0.2" "veth1"
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment