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
24 changes: 24 additions & 0 deletions linux1/application/app.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
from flask import Flask, request, jsonify

app = Flask(__name__)


@app.route("/get", methods=["GET"])
def handle_get():
return jsonify({"method": "GET", "message": "Hello from GET endpoint"}), 200


@app.route("/post", methods=["POST"])
def handle_post():
data = request.get_json(silent=True) or {}
return jsonify({"method": "POST", "message": "Hello from POST endpoint", "received": data}), 200


@app.route("/put", methods=["PUT"])
def handle_put():
data = request.get_json(silent=True) or {}
return jsonify({"method": "PUT", "message": "Hello from PUT endpoint", "received": data}), 200


if __name__ == "__main__":
app.run(host="0.0.0.0", port=5000)
11 changes: 11 additions & 0 deletions linux1/configs/linux_a/netplan/00-installer-config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
network:
ethernets:
enp0s3:
# Bridge adapter — access from host machine
dhcp4: true
enp0s8:
# Internal network "servernet" — communication with VM B
dhcp4: no
addresses: [192.168.13.10/24]
gateway4: 192.168.13.1
version: 2
14 changes: 14 additions & 0 deletions linux1/configs/linux_a/systemd/web-server.service
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
[Unit]
Description=Flask Web Server
After=network.target

[Service]
Type=simple
User=kulakov_1
WorkingDirectory=/home/kulakov_1/server/
ExecStart=/usr/bin/python3 /home/kulakov_1/server/app.py
Restart=on-failure
RestartSec=3

[Install]
WantedBy=multi-user.target
24 changes: 24 additions & 0 deletions linux1/configs/linux_b/iptables/setup_iptables.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
#!/bin/bash
# IP Forwarding — enable kernel packet forwarding between interfaces
echo 1 > /proc/sys/net/ipv4/ip_forward
sed -i 's/#net.ipv4.ip_forward=1/net.ipv4.ip_forward=1/' /etc/sysctl.conf

# Allow NEW connections from clientnet (enp0s9) to servernet (enp0s8) only on port 5000
iptables -A FORWARD -i enp0s9 -o enp0s8 -p tcp --syn --dport 5000 -m conntrack --ctstate NEW -j ACCEPT

# Allow established/related packets in both directions
iptables -A FORWARD -i enp0s9 -o enp0s8 -m conntrack --ctstate ESTABLISHED,RELATED -j ACCEPT
iptables -A FORWARD -i enp0s8 -o enp0s9 -m conntrack --ctstate ESTABLISHED,RELATED -j ACCEPT

# Drop everything else in FORWARD chain
iptables -P FORWARD DROP

# NAT: masquerade packets going from clientnet to servernet
iptables -t nat -A POSTROUTING -o enp0s8 -j MASQUERADE

# Save rules so they persist after reboot
apt-get install -y iptables-persistent
iptables-save > /etc/iptables/rules.v4
ip6tables-save > /etc/iptables/rules.v6

echo "iptables rules applied and saved."
14 changes: 14 additions & 0 deletions linux1/configs/linux_b/netplan/00-installer-config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
network:
ethernets:
enp0s3:
# Bridge adapter — access from host machine
dhcp4: true
enp0s8:
# Internal network "servernet" — gateway side facing VM A
dhcp4: no
addresses: [192.168.13.1/24]
enp0s9:
# Internal network "clientnet" — gateway side facing VM C
dhcp4: no
addresses: [192.168.8.1/24]
version: 2
11 changes: 11 additions & 0 deletions linux1/configs/linux_c/netplan/00-installer-config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
network:
ethernets:
enp0s3:
# Bridge adapter — access from host machine
dhcp4: true
enp0s8:
# Internal network "clientnet" — communication with VM B
dhcp4: no
addresses: [192.168.8.10/24]
gateway4: 192.168.8.1
version: 2
59 changes: 59 additions & 0 deletions linux1/docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
services:
linux_a:
image: alpine:3.19
container_name: kulakov_server
hostname: kulakov_server
networks:
servernet:
ipv4_address: 192.168.13.10
privileged: true
tty: true
volumes:
- ./application:/app
- ./scripts/setup_linux_a.sh:/setup.sh
entrypoint: sh /setup.sh

linux_b:
image: alpine:3.19
container_name: kulakov_gateway
hostname: kulakov_gateway
networks:
servernet:
ipv4_address: 192.168.13.1
clientnet:
ipv4_address: 192.168.8.1
privileged: true
tty: true
volumes:
- ./scripts/setup_linux_b.sh:/setup.sh
entrypoint: sh /setup.sh

linux_c:
image: alpine:3.19
container_name: kulakov_client
hostname: kulakov_client
networks:
clientnet:
ipv4_address: 192.168.8.10
privileged: true
tty: true
volumes:
- ./scripts/setup_linux_c.sh:/setup.sh
entrypoint: sh /setup.sh
depends_on:
- linux_a
- linux_b

networks:
servernet:
driver: bridge
ipam:
config:
- subnet: 192.168.13.0/24
gateway: 192.168.13.254
clientnet:
driver: bridge
ipam:
config:
- subnet: 192.168.8.0/24
gateway: 192.168.8.254
Binary file added linux1/imgs/screen1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added linux1/imgs/screen2.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added linux1/imgs/screen3.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading