Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion Report.md

This file was deleted.

67 changes: 67 additions & 0 deletions vms/ubuntu_a/application/A_bash.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
#! /bin/bash
# a script to create the second virtual machine
echo "create network bridge between first (192.168.18.10) and second (192.168.18.1) servers
....
...."
ip a
ip link add macvlan1 link eth0 type macvlan mode bridge
ip address add dev macvlan1 192.168.18.10/24
ip link set macvlan1 up
ip a
echo "create tcp connection between first and second servers
....
...."
apk add tcpdump
tcpdump

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if you run this script, in this raw you just open tcpdump and switch to tcpdump promt. bash script should be written as scrip run at once - so after run this script you should get VM with all apllied settings for task.
So, could you remove from this script all commands, that can broke your run - i think you need remove

  • tcpdump
  • ping command or you should declare how many times you try to ping other machine, otherwise you will ping other VM all the time (infinity loop)

echo "check connection with the second server
....
...."
ping 192.168.18.1
echo "check the routes for first server
....
...."
ip route
echo "tcp connection between first(192.168.18.10) and third (192.168.4.100) servers
....
...."
tcpdump
echo "create sub netwoek with third server by routing
....
...."
ip route add 192.168.4.0/24 via 192.168.18.1
echo "check connect with the third server (192.168.4.100)
....
...."
ping 192.168.4.100

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

infinity loop

echo "create a web server on port 5000 with third server as a client
....
...."
pip install flask
mkdir myapp
cd myapp
echo "web-server configration with requests: GET, PUT, POST

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

echo command should be used with PIPE syntax. So you need echo some text and than try to move output of this command to file like this:

echo 'Hello world' > my_test_file.txt

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if you want to use multiple raws, check this syntax https://stackoverflow.com/a/51864828

..load app.py from the File VM_A file or open the A_bash file and look at the end of it..
...."
vim app.py
python3 app.py

"""
from crypt import methods
from flask import Flask

app = Flask(__name__)

@app.route("/", methods=['GET'])
def hello_world():
return "<p>Hello, World!</p>"

@app.route("/", methods=['PUT'])

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

could you try to change put and post requests to something better? for example, you can put and post some data and return it to html (hello world is just example) https://pythonbasics.org/flask-rest-api/
for example

@app.route('/', methods=['PUT'])
def create_record():
    record = json.loads(request.data)
    with open('/tmp/data.txt', 'r') as f:
        data = f.read()
    if not data:
        records = [record]
    else:
        records = json.loads(data)
        records.append(record)
    with open('/tmp/data.txt', 'w') as f:
        f.write(json.dumps(records, indent=2))
    return jsonify(record)

@souhair souhair Mar 17, 2023

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok, i will do it . Thank you)

def hello_world_put():
return "<p>Hello, World!</p>"

@app.route("/", methods=['POST'])
def hello_world_post():
return "<p>Hello, World!</p>"

app.run(host='0.0.0.0', port=5000)
"""
40 changes: 40 additions & 0 deletions vms/ubuntu_a/application/B_bash.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
echo "create network bridge between second (192.168.18.1) and first (192.168.18.10) servers
....
...."
ip a
ip link add macvlan1 link eth0 type macvlan mode bridge
ip address add dev macvlan1 192.168.18.1/24
ip link set macvlan1 up
ip a
echo "create network bridge between second (192.168.4.1) and third (192.168.4.100) servers
....
...."
ip link add macvlan2 link eth0 type macvlan mode bridge
ip address add dev macvlan2 192.168.4.1/24
ip link set macvlan2 up
ip a
echo "check connection with the third server
....
...."
ping 192.168.4.100

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

infinity loop

echo "check connection with the first server
....
...."
ping 192.168.18.10

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

infinity loop

echo "tcp connection between second (192.168.18.1) and first (192.168.18.10) servers
....
...."
apk add tcpdump
tcpdump -i macvlan1

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

infinity loop

echo "tcp connection between second(192.168.4.1) and third (192.168.4.100) servers
....
...."
tcpdump -i macvlan2
echo "check the routes for second server
....
...."
ip route
echo "create tcp connection to listen to port 5000
....
...."
tcpdump 'port 5000'

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

infinity loop

39 changes: 39 additions & 0 deletions vms/ubuntu_a/application/C_bash.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
echo "create network bridge between third (192.168.4.100) and second (192.168.4.1) servers
....
...."
ip a
ip link add macvlan1 link eth0 macvlan mode bridge
ip address add dev macvlan1 192.168.4.100/24
ip link set macvlan1 up
ip a
echo "create tcp connection the third and second servers
....
...."
apk add tcpdump
tcpdump
echo "check connection with the second server
....
...."
ping 192.168.4.1
echo "check the routes for second server
....
...."
ip route
echo "create sub netwoek with first server by routing
....
...."
ip route add 192.168.18.0/24 via 192.168.4.1
echo "check connection with the first server
....
...."
ping 192.168.18.10
echo "create tcp connection the third and first servers
....
...."
tcpdump
echo "send requests to the web-server on port 5000
....
...."
curl 'http://192.168.18.10:5000'
curl -X POST 'http://192.168.18.10:5000'
curl -X PUT 'http://192.168.18.10:5000'