From 49a80e364061d02add87ef0c2c5cb4a99c64e319 Mon Sep 17 00:00:00 2001 From: root Date: Wed, 18 Mar 2026 07:46:57 +0300 Subject: [PATCH] new --- adm | 18 ++++++++ dhcp | 31 +++++++++++++ dns | 129 ++++++++++++++++++++++++++++++++++++++++++++++++++++ hqs | 74 ++++++++++++++++++++++++++++++ int | 136 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ ospf_brr | 71 +++++++++++++++++++++++++++++ ospf_hqr | 80 ++++++++++++++++++++++++++++++++ tunel | 14 ++++++ usr | 17 +++++++ 9 files changed, 570 insertions(+) create mode 100755 adm create mode 100755 dhcp create mode 100755 dns create mode 100755 hqs create mode 100755 int create mode 100755 ospf_brr create mode 100755 ospf_hqr create mode 100755 tunel create mode 100755 usr diff --git a/adm b/adm new file mode 100755 index 0000000..6579db7 --- /dev/null +++ b/adm @@ -0,0 +1,18 @@ +#!/bin/bash +# Задание 3, Модуль 1 (HQ-RTR / BR-RTR) + +[ $EUID -ne 0 ] && echo "Требуется root" && exit 1 + +# Пользователь net_admin (маршрутизаторы) +USER="net_admin" +PASS="admin" + +# Создание пользователя +useradd -m -s /bin/bash "$USER" 2>/dev/null +echo "$USER:$PASS" | chpasswd + +# Sudo без пароля +echo "$USER ALL=(ALL) NOPASSWD: ALL" > /etc/sudoers +chmod 440 /etc/sudoers + +echo "Готово" diff --git a/dhcp b/dhcp new file mode 100755 index 0000000..ee43dcc --- /dev/null +++ b/dhcp @@ -0,0 +1,31 @@ +#!/bin/nash + +cat > /etc/dhcp/dhcpd.conf << EOF +default-lease-time 600; +max-lease-time 7200; +authoritative; + +subnet 192.168.4.0 netmask 255.255.255.248 { + range 192.168.4.2 192.168.4.6; + option domain-name-servers 192.168.3.2, 8.8.4.4; + option subnet-mask 255.255.255.248; + option routers 172.16.4.1; +} + + +host hq-cli { + hardware ethernet +08:00:27:c7:82:fa; + fixed-address +192.168.4.2; +} +EOF +chmod 600 /etc/dhcp/dhcpd.conf + +cat > /etc/sysconfig/dhcpd << EOF +DHCPDARGS="enp0s9" +EOF + +echo "_________________Перезагрузка и старт dncpd________________________" +systemctl restart dhcpd +systemctl start dhcpd diff --git a/dns b/dns new file mode 100755 index 0000000..6747ba9 --- /dev/null +++ b/dns @@ -0,0 +1,129 @@ +#!/bit/bash +cat > /etc/named.conf << EOF +options { + listen-on port 53 { 127.0.0.1; 192.168.3.2; }; + listen-on-v6 port 53 { none; }; + directory "/var/named"; + dump-file "/var/named/data/cache_dump.db"; + statistics-file "/var/named/data/named_stats.txt"; + memstatistics-file "/var/named/data/named_mem_stats.txt"; + secroots-file "/var/named/data.named/data/named.secroots"; + recursing-file "/var/named/data/named.recursing"; + allow-query { any; }; + forward first; + forwarders { 8.8.8.8; }; +}; + +logging { + channel default_debug { + file "data/named.run"; + severity dynamic; + }; +}; +zone "." IN { + type hint; + file "named.ca"; +}; + +include "/etc/named.rfc1912.zones"; +include "/etc/named.root.key"; + +zone "au-team.irpo" { +type master; +file "master/au-team.irpo"; +}; + +zone "3.168.192.in-addr.arpa" { +type master; +file "master/3.168.192.in-addr.arpa"; +}; + +zone "4.168.192.in-addr.arpa" { +type master; +file "master/4.168.192.in-addr.arpa"; +}; + +#zone "4.16.172.in-addr.arpa" { +#type master; +#file "4.16.172.in-addr.arpa"; +#}; +EOF + + +mkdir /var/named/master + +cat > /var/named/master/au-team.irpo << EOF +\$TTL 604800 ; +au-team.irpo. IN SOA ns01.au-team.irpo. root.au-team.irpo. ( + 1 ; Serial + 600 ; Refresh + 3600 ; Retry + 1w ; Expire + 360 ; Minimum TTL + ) + IN NS br-srv.au-team.irpo. + IN NS hq-rtr.au-team.irpo. + IN NS br-rtr.au-team.irpo. + IN NS hq-srv.au-team.irpo. + IN NS hq-cli.au-team.irpo. + IN NS docker.au-team.irpo. + IN NS web.au-team.irpo. +br-srv IN A 192.168.2.2 +hq-rtr IN A 172.16.4.2 +br-rtr IN A 172.16.5.2 +hq-srv IN A 192.168.3.2 +hq-cli IN A 192.168.4.2 +docker IN A 172.16.4.1 +web IN A 172.16.5.1 +EOF + +# Zone for HQ-SRV +cat > /var/named/master/3.168.192.in-addr.arpa << EOF +\$TTL 604800 ; +@ IN SOA ns01.au-team.irpo. root.au-team.irpo. ( + 20060204 ; Serial + 3600 ; Refresh + 900 ; Retry + 3600000 ; Expire + 3600 ; Minimum + ) +@ IN NS au-team.irpo. +2 IN PTR hq-srv.au-team.irpo. +EOF + +# Zone for HQ-CLI +cat > /var/named/master/4.168.192.in-addr.arpa << EOF +\$TTL 604800 ; +@ IN SOA ns01.au-team.irpo. root.au-team.irpo. ( + 20060204 ; Serial + 3600 ; Refresh + 900 ; Retry + 3600000 ; Expire + 3600 ; Minimum + ) +@ IN NS au-team.irpo. +2 IN PTR hq-cli.au-team.irpo. +EOF + +# Zone for HQ-RTR +cat > /var/named/master/4.16.172.in-addr.arpa << EOF +\$TTL 604800 ; +@ IN SOA ns01.au-team.irpo. root.au-team.irpo.( + 20060204 ; Serial + 3600 ; Refresh + 900 ; Retry + 3600000 ; Expire + 3600 ; Minimum + ) +@ IN NS au-team.irpo. +2 IN PTR hq-rtr.au-team.irpo. +EOF + +read -p "Resolution?: " res +if [[ -n $res ]]; then + chown -R root:named /var/named/master + chmod 0640 /var/named/master/* +fi +echo "" +echo "_______________________Перезагрузка named______________________" +systemctl restart named diff --git a/hqs b/hqs new file mode 100755 index 0000000..9a22fb0 --- /dev/null +++ b/hqs @@ -0,0 +1,74 @@ +#!/bin/bash +echo "hostname" +read -p "enter name" name +if [[ -n $name ]]; then + hostnamectl set-hostname $name + exec bash +fi +echo "enter enp0s3" +read enp0s3 +if [[ -n $enp0s3 ]]; then + read -p "enter gateway" gat + read -p "enter dns" dns + cat > /etc/NetworkManager/system-connections/enp0s3.nmconnection << EOF +[connnection] +id=enp0s3 +uuid=$(uuidgen) +tipe=ethernet +autoconnect-priority=-999 +interface-name=enp0s3 +timestamp=$(date +%s) + +[ethernet] + + +[ipv4] +address1=$enp0s3 +dns=$dns +gateway=$gat +method=manual + +[ipv6] +addr-gen-mode=eui64 +method=disabled + +[proxy] + +EOF + + chmod 600 /etc/NetworkManager/system-connections/enp0s3.nmconnection +fi +read -p "Reboot?" o +if [[ -n $o ]]; then + reboot +fi + +echo "enter accaunt" +read -p "continue: " can +if [[ -n $can ]]; then + useradd -u 2026 remote_user + passwd remote_user + cat >> /etc/sudoers << EOF +remote_user ALL=(ALL)NOPASSWD:ALL + +EOF + +fi + +read -p "ftp?: " ftp +read -p "enter ip: " ip +if [[ -n $ftp ]]; then + iptables -I INPUT -p tcp --match multiport --dports 21,22,20000:25000 -j ACCEPT + iptables -t nat -A POSTROUTING -p tcp -d $ip --dport 21 -j MASQUERADE + iptables -t nat -A PREROUTING -i enp0s3 -p tcp --dport 21 -j DNAT --to-destination $ip:21 + service iptables save + + cat >> /etc/vsftpd/vsftpd.conf << EOF +pasv_min_port=20000 +pasv_max_port=25000 +pasv_enable=YES + +EOF + chmod 600 /etc/vsftpd/vsftpd.conf +fi + diff --git a/int b/int new file mode 100755 index 0000000..74aaef1 --- /dev/null +++ b/int @@ -0,0 +1,136 @@ +#!bin/bash + +a=1 +while a==1 + do + echo "" + echo "Выберите параметр" + echo "" + echo "1. Имя" + echo "2. Калькулятор маски" + echo "3. IP-адрес" + echo "4. Forward и masquerade" + echo "5. Перезагрузить машину" + echo "6. Time zone" + echo "0. Выход" + echo "" + read num + echo "" + + + if (( $num == 0 )); then + break + + elif (( $num == 1 )); then + echo "______________________Имя_____________________" + read -p "Введите имя(isp.au-team.irpo): " name + hostnamectl set-hostname $name + exec bash + elif (( $num == 3)); then + echo "_____________________Enp0s3_______________________" + read -p "Введите ip-адрес или пропустите для DHCP: " ip_s3 + if [[ -n $ip_s3 ]]; then + read -p "Введите шлюз или пропустите: " gt_s3 + cat > /etc/NetworkManager/system-connections/enp0s3.nmconnection << EOF +[connection] +id=enp0s3 +uuid=$(uuidgen) +type=ethernet +autoconnect-priority=-999 +interface-name=enp0s3 +timestamp=$(date +%s) + +[ethernet] + +[ipv4] +address1=$ip_s3 +dns=8.8.8.8 +gateway=$gt_s3 +method=manual + +[ipv6] +addr-gen-mode=eui64 +method=disabled + +[proxy] +EOF + chmod 600 /etc/NetworkManager/system-connections/enp0s3.nmconnection + systemctl restart NetworkManager + fi + echo "" + echo "________________________Enp0s8_________________________" + read -p "Введите ip-адрес или пропустите: " ip_s8 + if [[ -n $ip_s8 ]]; then + nmcli connection modify enp0s8 ipv4.method manual ipv4.addresses $ip_s8 ipv6.method disabled + systemctl restart NetworkManager + fi + echo "" + echo "____________________________Enp0s9____________________________" + read -p "Введите ip-адрес или пропустите: " ip_s9 + if [[ -n $ip_s9 ]]; then + nmcli connection modify enp0s9 ipv4.method manual ipv4.addresses $ip_s9 ipv6.method disabled + systemctl restart NetworkManager + fi + echo "" + echo "___________________________Enp0s10___________________________" + read -p "Введите ip-адрес или пропустите: " ip_s10 + if [[ -n $ip_s10 ]]; then + nmcli connection modify enp0s10 ipv4.method manual ipv4.addresses $ip_s10 ipv6.method disabled + systemctl restart NetworkManager + fi + systemctl restart NetworkManager + + elif (( $num == 4 )); then + echo "" + echo "_____________________________Forward и Masquerade__________________________" + sysctl net.ipv4.ip_forward=1 >> /etc/sysctl.conf + systemctl enable --now iptables + iptables -F + read -p "Введите количество ip-адресов для которых необходимо задать Masquerade: " a + if (( $a == 2 )); then + if [[ -n $ip_s8 || $ip_s9 ]]; then + iptables -t nat -A POSTROUTING -s $ip_s8 -o enp0s3 -j MASQUERADE + iptables -t nat -A POSTROUTING -s $ip_s9 -o enp0s3 -j MASQUERADE + echo "Готово" + else + read -p "Введите ip-адрес для enp0s8(192.168.0.0/30): " ip_s8 + read -p "Введите ip-адрес для enp0s9(192.168.0.0/30): " ip_s9 + iptables -t nat -A POSTROUTING -s $ip_s8 -o enp0s3 -j MASQUERADE + iptables -t nat -A POSTROUTING -s $ip_s9 -o enp0s3 -j MASQUERADE + fi + elif (( $a == 1)); then + if [[ -n $ip_s8 ]]; then + iptables -t nat -A POSTROUTING -s $ip_s8 -o enp0s3 -j MASQUERADE + echo "Готово" + else + read -p "Введите ip для enp0s8: " ip_s8 + iptables -t nat -A POSTROUTING -s $ip_s8 -o enp0s3 -j MASQUERADE + fi + fi + iptables-save --file /etc/sysconfig/iptables + + + elif (( $num == 5)); then + read -p "Перезвгрузить?: " r + if (( $r == n || $r == N)); then + echo "No" + else + reboot + fi + + elif (( $num == 2)); then + echo "" + echo "____________________________Калькулятор____________________________" + read -p "Введите количество PC: " mask + mask=$(echo "sqrt($mask)" | bc) + mask=$((32 - $mask)) + echo $mask + echo"" + + elif (( $num == 6)); then + echo "For watch time zone inter: timedatectl list-timezones" + echo "Inter timedatectl set-timezone 'timezone' " + + chmod 600 /etc/sudoers + fi +done diff --git a/ospf_brr b/ospf_brr new file mode 100755 index 0000000..6c399f6 --- /dev/null +++ b/ospf_brr @@ -0,0 +1,71 @@ +#!bin/bash + +read -p "Введите id роутера(1.1.1.1): " r_id +read -p "Введите подсеть для enp0s3 (172.16.5.0/28): " ip_s3 +read -p "Введите подсеть для enp0s8(192.168.2.0/26): " ip_s8 +read -p "Введите подсеть для туннеля(192.168.9.0/30): " ip_tun +read -p "Введите имя(BR-RTR): " name +cat > /etc/frr/daemons << EOF +bgpd=no +ospfd=yes +ospf6d=no +ripd=no +ripngd=no +isisd=no +pimd=no +pim6d=no +nhrpd=no +eigrpd=no +babeld=no +sharpd=no +pbrd=no +bfdd=no +fabricd=no +vrrpd=no +pathd=no +EOF + +cat > /etc/frr/frr.conf << EOF +frr version 10.1.2 +frr defaults traditional +hostname $name +no ipv6 forwarding +! +interface gre1 + no ip ospf passive +exit +! +router ospf + ospf router-id $r_id + area 0 authentication message-digest + passive-interface default + network $ip_s3 area 0 + network $ip_s8 area 0 + network $ip_tun area 0 +exit +! +interface gre1 + ip ospf network point-to-point + ip ospf authentication message-digest + ip ospf message-digest-key 1 md5 1 +! +interface enp0s8 + ip ospf authentication message-digest + ip ospf message-digest-key 1 md5 1 +! +line vty +! +EOF + +chmod 600 /etc/frr/frr.conf + +echo "" +echo "__________________________Начало и перезагузка frr_____________________________" +systemctl restart frr +systemctl enable frr +systemctl start frr + +echo "" +echo "_______________________________Проверка_______________________________" +systemctl status frr +ip route show diff --git a/ospf_hqr b/ospf_hqr new file mode 100755 index 0000000..44fce45 --- /dev/null +++ b/ospf_hqr @@ -0,0 +1,80 @@ +#!bin/bash + +read -p "Введите имя(HQ-RTR): " name +read -p "Введите id роутера(2.2.2.2): " r_id +read -p "Введите подсеть для enp0s3(172.16.4.0/28): " ip_s3 +read -p "Введите подсеть для enp0s8(192.168.3.0/26): " ip_s8 +read -p "Введите подсеть туннеля(192.168.9.0/30): " ip_tun +cat > /etc/frr/daemons << EOF +bgpd=no +ospfd=yes +ospf6d=no +ripd=no +ripngd=no +isisd=no +pimd=no +pim6d=no +nhrpd=no +eigrpd=no +babeld=no +sharpd=no +pbrd=no +bfdd=no +fabricd=no +vrrpd=no +pathd=no +EOF + +cat > /etc/frr/frr.conf << EOF +frr version 10.1.2 +frr defaults traditional +hostname $name +no ipv6 forwarding +! +interface gre1 + no ip ospf passive +exit +! +router ospf + ospf router-id $r_id + area 0 authentication message-digest + passive-interface default + network $ip_s3 area 0 + network $ip_s8 area 0 + network $ip_tun area 0 +exit +! +interface gre1 + ip ospf network point-to-point + ip ospf authentication message-digest + ip ospf message-digest-key 1 md5 1 +! +interface enp0s8 + ip ospf authentication message-digest + ip ospf message-digest-key 1 md5 1 +! +interface enp0s9 + ip ospf authentication message-digest + ip ospf message-digest-key 1 md5 1 +! +interface enp0s10 + ip ospf authentication message-digest + ip ospf message-digest-key 1 md5 1 +! +line vty +! +EOF + + +chmod 600 /etc/frr/frr.conf + +echo "" +echo "__________________________Старт и перезагрузка frr_____________________________" +systemctl restart frr +systemctl enable frr +systemctl start frr + +echo "" +echo "_______________________________Проверка_______________________________" +systemctl status frr +ip route show diff --git a/tunel b/tunel new file mode 100755 index 0000000..c84393d --- /dev/null +++ b/tunel @@ -0,0 +1,14 @@ +#!/bin/bash +read -p "Введите локальный ip-адрес для тунеля(172.16.0.2): " l_ip +read -p "Введите удаленный ip-адрес для туннеля(172.16.0.2): " r_ip +read -p "Введите ip-адрес туннеля(192.168.9.1/30)" t_ip +read -p "Введите имя туннеля(gre1): " name + +ip link delete gre1 2>/dev/null + +ip tunnel add $name mode gre local $l_ip remote $r_ip ttl 64 dev enp0s3 +ip addr add $t_ip dev $name +ip link set $name up + +echo "Введите nmcli connection modify "$name" ip-tunnel.ttl 64" +systemctl restart NetworkManager diff --git a/usr b/usr new file mode 100755 index 0000000..e959374 --- /dev/null +++ b/usr @@ -0,0 +1,17 @@ +#!/bin/bash +# Задание 3, Модуль 1 (HQ-SRV / BR-SRV) + +[ $EUID -ne 0 ] && echo "Требуется root" && exit 1 + +# 1. Пользователь remote_user +useradd -m remote_user 2>/dev/null + +# 2. Пользователь sshuser (UID 2026, пароль P@ssw0rd) +useradd -u 2026 -m sshuser 2>/dev/null +echo "sshuser:user" | chpasswd + +# 3. Sudo без пароля для sshuser +echo "sshuser ALL=(ALL) NOPASSWD: ALL" > /etc/sudoers +chmod 440 /etc/sudoers + +echo "Готово"