From b11ebfa255255ca1fbfc9d0093067f3caed21baa Mon Sep 17 00:00:00 2001 From: Lucky <14868134+L-U-C-K-Y@users.noreply.github.com> Date: Fri, 15 Dec 2023 11:39:04 +0100 Subject: [PATCH 01/10] support multiple ip addresses and show a prompt for network_config.sh --- script/network_config.sh | 115 ++++++++++++++++++++++++--------------- 1 file changed, 71 insertions(+), 44 deletions(-) diff --git a/script/network_config.sh b/script/network_config.sh index 72880f4..871cf10 100755 --- a/script/network_config.sh +++ b/script/network_config.sh @@ -1,13 +1,56 @@ #!/bin/bash -read -p "MAIN_SERVER_IP: " MAINSERVERIP -read -p "MAIN_SERVER_GATEWAY_ADRESS: " GATEWAYADRESS -read -p "NETMASK: " NETMASK -read -p "BROADCASTIP: " BROADCASTIP -read -p "ADDITIONAL_IP_ADRESS: " ADD_IP_ADRESS -read -p "NETWORK_INTERFACE: " NETWORK_INTERFACE +# Function to prompt for input with a default value +prompt_input() { + local prompt=$1 + local default=$2 + read -p "$prompt [$default]: " input + echo "${input:-$default}" +} -echo " +# Function to create bridge interface text for additional IP +create_bridge_text() { + local ip=$1 + local bridge_id=$2 + echo " +auto vmbr${bridge_id} +iface vmbr${bridge_id} inet static + address ${ip} + netmask ${NETMASK} + bridge_ports none + bridge_stp off + bridge_fd 0 +#LAN${bridge_id}" +} + +# Collect inputs +MAINSERVERIP=$(prompt_input "MAIN_SERVER_IP" "192.168.0.1") +GATEWAYADDRESS=$(prompt_input "MAIN_SERVER_GATEWAY_ADDRESS" "192.168.0.254") +NETMASK=$(prompt_input "NETMASK" "255.255.255.0") +BROADCASTIP=$(prompt_input "BROADCASTIP" "192.168.0.255") +ADD_IP_ADDRESSES=$(prompt_input "ADDITIONAL_IP_ADDRESSES (comma-separated)" "") +NETWORK_INTERFACE=$(prompt_input "NETWORK_INTERFACE" "eth0") + +# Display inputs for confirmation +echo "You have entered the following configuration:" +echo "MAIN_SERVER_IP: $MAINSERVERIP" +echo "MAIN_SERVER_GATEWAY_ADDRESS: $GATEWAYADDRESS" +echo "NETMASK: $NETMASK" +echo "BROADCASTIP: $BROADCASTIP" +echo "ADDITIONAL_IP_ADDRESSES: $ADD_IP_ADDRESSES" +echo "NETWORK_INTERFACE: $NETWORK_INTERFACE" +read -p "Is this correct? [yes/no]: " confirmation + +if [[ $confirmation != [Yy]* ]]; then + echo "Exiting without changes." + exit +fi + +# Split ADD_IP_ADDRESSES into an array +IFS=',' read -ra ADDR <<<"$ADD_IP_ADDRESSES" + +# Initialize the interfaces file content +interfaces_content=" ### Hetzner Online GmbH installimage source /etc/network/interfaces.d/* @@ -16,63 +59,47 @@ auto lo iface lo inet loopback iface lo inet6 loopback - iface ${NETWORK_INTERFACE} inet manual - - up ip route add -net up ip route add -net ${GATEWAYADRESS} netmask ${NETMASK} gw ${GATEWAYADRESS} vmbr0 + up ip route add -net up ip route add -net ${GATEWAYADDRESS} netmask ${NETMASK} gw ${GATEWAYADDRESS} vmbr0 up sysctl -w net.ipv4.ip_forward=1 up sysctl -w net.ipv4.conf.${NETWORK_INTERFACE}.send_redirects=0 up sysctl -w net.ipv6.conf.all.forwarding=1 - up ip route add 192.168.0.0/16 via ${ADD_IP_ADRESS} dev vmbr0 - up ip route add 172.16.0.0/12 via ${ADD_IP_ADRESS} dev vmbr0 - up ip route add 10.0.0.0/8 via ${ADD_IP_ADRESS} dev vmbr0 - + up ip route add 192.168.0.0/16 via ${ADDR[0]} dev vmbr0 + up ip route add 172.16.0.0/12 via ${ADDR[0]} dev vmbr0 + up ip route add 10.0.0.0/8 via ${ADDR[0]} dev vmbr0 iface ${NETWORK_INTERFACE} inet6 static address 2a01:4f8:110:5143::2 netmask 64 gateway fe80::1 - auto vmbr0 iface vmbr0 inet static address ${MAINSERVERIP} netmask 32 - gateway ${GATEWAYADRESS} + gateway ${GATEWAYADDRESS} broadcast ${BROADCASTIP} bridge-ports ${NETWORK_INTERFACE} bridge-stp off bridge-fd 0 - pointopoint ${GATEWAYADRESS} + pointopoint ${GATEWAYADDRESS} #WAN +" - -# Virtual switch for DMZ -# (connect your firewall/router KVM instance and private DMZ hosts here) -auto vmbr1 -iface vmbr1 inet manual - bridge_ports none - bridge_stp off - bridge_fd 0 -#LAN0 - -" >interfaces - -cat interfaces - -while true; do - read -p "Config correct? [yes][no]: " yn - case $yn in - [Yy]*) - echo "" - break - ;; - [Nn]*) exit ;; - *) echo "Please answer yes or no." ;; - esac +# Append bridge interfaces for each additional IP +for i in "${!ADDR[@]}"; do + interfaces_content+=$(create_bridge_text "${ADDR[i]}" "$((i + 1))") done -mv /etc/network/interfaces /etc/network/interfaces.old -mv interfaces /etc/network/interfaces +echo "$interfaces_content" >interfaces -echo "The network can be restarted with the following command: /etc/init.d/networking restart " +# Confirm before applying changes +read -p "Apply this network configuration? [yes/no]: " apply_conf + +if [[ $apply_conf == [Yy]* ]]; then + mv /etc/network/interfaces /etc/network/interfaces.old + mv interfaces /etc/network/interfaces + echo "The network can be restarted with the following command: /etc/init.d/networking restart" +else + echo "Exiting without applying changes." +fi From 1845d834d328e1fe0ea34cb6b8f0314ceade03ca Mon Sep 17 00:00:00 2001 From: Lucky Bassi Date: Fri, 15 Dec 2023 12:14:48 +0100 Subject: [PATCH 02/10] fix(network): fix --- script/network_config.sh | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/script/network_config.sh b/script/network_config.sh index 871cf10..6a599c1 100755 --- a/script/network_config.sh +++ b/script/network_config.sh @@ -32,6 +32,7 @@ ADD_IP_ADDRESSES=$(prompt_input "ADDITIONAL_IP_ADDRESSES (comma-separated)" "") NETWORK_INTERFACE=$(prompt_input "NETWORK_INTERFACE" "eth0") # Display inputs for confirmation +echo "--------------------------" echo "You have entered the following configuration:" echo "MAIN_SERVER_IP: $MAINSERVERIP" echo "MAIN_SERVER_GATEWAY_ADDRESS: $GATEWAYADDRESS" @@ -39,6 +40,8 @@ echo "NETMASK: $NETMASK" echo "BROADCASTIP: $BROADCASTIP" echo "ADDITIONAL_IP_ADDRESSES: $ADD_IP_ADDRESSES" echo "NETWORK_INTERFACE: $NETWORK_INTERFACE" + +echo "--------------------------" read -p "Is this correct? [yes/no]: " confirmation if [[ $confirmation != [Yy]* ]]; then @@ -91,9 +94,13 @@ for i in "${!ADDR[@]}"; do interfaces_content+=$(create_bridge_text "${ADDR[i]}" "$((i + 1))") done -echo "$interfaces_content" >interfaces +# Display the generated configuration for review +echo "--------------------------" +echo "Generated network configuration:" +echo "$interfaces_content" # Confirm before applying changes +echo "--------------------------" read -p "Apply this network configuration? [yes/no]: " apply_conf if [[ $apply_conf == [Yy]* ]]; then From 32e5e5d76ea0d55a7c7202423bd52db0afc71df9 Mon Sep 17 00:00:00 2001 From: Lucky Bassi Date: Fri, 15 Dec 2023 12:58:37 +0100 Subject: [PATCH 03/10] fix(network): fix --- script/network_config.sh | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) diff --git a/script/network_config.sh b/script/network_config.sh index 6a599c1..77d4d8b 100755 --- a/script/network_config.sh +++ b/script/network_config.sh @@ -94,10 +94,23 @@ for i in "${!ADDR[@]}"; do interfaces_content+=$(create_bridge_text "${ADDR[i]}" "$((i + 1))") done -# Display the generated configuration for review +# Save the new configuration to a temporary file +echo "$interfaces_content" > /tmp/new_interfaces + +# Display the current network configuration echo "--------------------------" -echo "Generated network configuration:" -echo "$interfaces_content" +echo "Current network configuration (/etc/network/interfaces):" +cat /etc/network/interfaces + +# Display the new network configuration +echo "--------------------------" +echo "New network configuration:" +cat /tmp/new_interfaces + +# Show the differences +echo "--------------------------" +echo "Configuration differences:" +diff /etc/network/interfaces /tmp/new_interfaces # Confirm before applying changes echo "--------------------------" From 892c94581be1bca2c7dba4be2d8a6d08c5149338 Mon Sep 17 00:00:00 2001 From: Lucky Bassi Date: Fri, 15 Dec 2023 13:15:42 +0100 Subject: [PATCH 04/10] fix(app): with separator --- script/network_config.sh | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/script/network_config.sh b/script/network_config.sh index 77d4d8b..b94402d 100755 --- a/script/network_config.sh +++ b/script/network_config.sh @@ -32,7 +32,7 @@ ADD_IP_ADDRESSES=$(prompt_input "ADDITIONAL_IP_ADDRESSES (comma-separated)" "") NETWORK_INTERFACE=$(prompt_input "NETWORK_INTERFACE" "eth0") # Display inputs for confirmation -echo "--------------------------" +echo "---------------------------------------------------------------------" echo "You have entered the following configuration:" echo "MAIN_SERVER_IP: $MAINSERVERIP" echo "MAIN_SERVER_GATEWAY_ADDRESS: $GATEWAYADDRESS" @@ -41,7 +41,7 @@ echo "BROADCASTIP: $BROADCASTIP" echo "ADDITIONAL_IP_ADDRESSES: $ADD_IP_ADDRESSES" echo "NETWORK_INTERFACE: $NETWORK_INTERFACE" -echo "--------------------------" +echo "---------------------------------------------------------------------" read -p "Is this correct? [yes/no]: " confirmation if [[ $confirmation != [Yy]* ]]; then @@ -98,22 +98,26 @@ done echo "$interfaces_content" > /tmp/new_interfaces # Display the current network configuration -echo "--------------------------" +echo "---------------------------------------------------------------------" echo "Current network configuration (/etc/network/interfaces):" +echo "" cat /etc/network/interfaces # Display the new network configuration -echo "--------------------------" +echo "---------------------------------------------------------------------" +echo "" echo "New network configuration:" cat /tmp/new_interfaces # Show the differences -echo "--------------------------" +echo "---------------------------------------------------------------------" echo "Configuration differences:" +echo "" diff /etc/network/interfaces /tmp/new_interfaces # Confirm before applying changes -echo "--------------------------" +echo "---------------------------------------------------------------------" +echo "" read -p "Apply this network configuration? [yes/no]: " apply_conf if [[ $apply_conf == [Yy]* ]]; then From 7e1d9d9cceb0dab6e32b87106aa120a4d2bb3f1f Mon Sep 17 00:00:00 2001 From: Lucky Bassi Date: Fri, 15 Dec 2023 13:29:50 +0100 Subject: [PATCH 05/10] fix(script): minor fixes --- script/network_config.sh | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/script/network_config.sh b/script/network_config.sh index b94402d..89e71fb 100755 --- a/script/network_config.sh +++ b/script/network_config.sh @@ -121,9 +121,11 @@ echo "" read -p "Apply this network configuration? [yes/no]: " apply_conf if [[ $apply_conf == [Yy]* ]]; then - mv /etc/network/interfaces /etc/network/interfaces.old - mv interfaces /etc/network/interfaces + timestamp=$(date +%Y%m%d-%H%M%S) + mv /etc/network/interfaces /etc/network/interfaces.bak-$timestamp + mv /tmp/new_interfaces /etc/network/interfaces echo "The network can be restarted with the following command: /etc/init.d/networking restart" else echo "Exiting without applying changes." + rm /tmp/new_interfaces fi From 10193206ec0e20621f95ec6f1409a697296aac47 Mon Sep 17 00:00:00 2001 From: Lucky Bassi Date: Fri, 15 Dec 2023 15:37:53 +0100 Subject: [PATCH 06/10] fix(script): add mac address --- script/network_config.sh | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/script/network_config.sh b/script/network_config.sh index 89e71fb..b332b9c 100755 --- a/script/network_config.sh +++ b/script/network_config.sh @@ -12,6 +12,7 @@ prompt_input() { create_bridge_text() { local ip=$1 local bridge_id=$2 + local mac_address=$3 echo " auto vmbr${bridge_id} iface vmbr${bridge_id} inet static @@ -20,6 +21,7 @@ iface vmbr${bridge_id} inet static bridge_ports none bridge_stp off bridge_fd 0 + hwaddress ether ${mac_address} #LAN${bridge_id}" } @@ -29,6 +31,7 @@ GATEWAYADDRESS=$(prompt_input "MAIN_SERVER_GATEWAY_ADDRESS" "192.168.0.254") NETMASK=$(prompt_input "NETMASK" "255.255.255.0") BROADCASTIP=$(prompt_input "BROADCASTIP" "192.168.0.255") ADD_IP_ADDRESSES=$(prompt_input "ADDITIONAL_IP_ADDRESSES (comma-separated)" "") +MAC_ADDRESSES=$(prompt_input "MAC_ADDRESSES for additional IPs (comma-separated)" "") NETWORK_INTERFACE=$(prompt_input "NETWORK_INTERFACE" "eth0") # Display inputs for confirmation @@ -39,6 +42,7 @@ echo "MAIN_SERVER_GATEWAY_ADDRESS: $GATEWAYADDRESS" echo "NETMASK: $NETMASK" echo "BROADCASTIP: $BROADCASTIP" echo "ADDITIONAL_IP_ADDRESSES: $ADD_IP_ADDRESSES" +echo "MAC_ADDRESSES: $MAC_ADDRESSES" echo "NETWORK_INTERFACE: $NETWORK_INTERFACE" echo "---------------------------------------------------------------------" @@ -49,8 +53,9 @@ if [[ $confirmation != [Yy]* ]]; then exit fi -# Split ADD_IP_ADDRESSES into an array +# Split ADD_IP_ADDRESSES and MAC_ADDRESSES into arrays IFS=',' read -ra ADDR <<<"$ADD_IP_ADDRESSES" +IFS=',' read -ra MACS <<<"$MAC_ADDRESSES" # Initialize the interfaces file content interfaces_content=" @@ -89,9 +94,9 @@ iface vmbr0 inet static #WAN " -# Append bridge interfaces for each additional IP +# Append bridge interfaces for each additional IP and MAC address for i in "${!ADDR[@]}"; do - interfaces_content+=$(create_bridge_text "${ADDR[i]}" "$((i + 1))") + interfaces_content+=$(create_bridge_text "${ADDR[i]}" "$((i + 1))" "${MACS[i]}") done # Save the new configuration to a temporary file From f7aee4d25f1c2309ea0b150831796ad311a0dc2f Mon Sep 17 00:00:00 2001 From: Lucky Bassi Date: Fri, 15 Dec 2023 16:58:18 +0100 Subject: [PATCH 07/10] fix(app): fix order, start at 10 --- script/network_config.sh | 68 ++++++++++++++++++++-------------------- 1 file changed, 34 insertions(+), 34 deletions(-) diff --git a/script/network_config.sh b/script/network_config.sh index b332b9c..23762f5 100755 --- a/script/network_config.sh +++ b/script/network_config.sh @@ -8,21 +8,36 @@ prompt_input() { echo "${input:-$default}" } -# Function to create bridge interface text for additional IP +# Function to create bridge interface text for additional IP and internal bridges create_bridge_text() { local ip=$1 local bridge_id=$2 local mac_address=$3 - echo " -auto vmbr${bridge_id} -iface vmbr${bridge_id} inet static + local external_bridge_id=$((10 + (bridge_id - 1) * 2)) + local internal_bridge_id=$((external_bridge_id + 1)) + + # External bridge configuration with MAC address and public IP + local bridge_config=" +auto vmbr${external_bridge_id} +iface vmbr${external_bridge_id} inet static address ${ip} netmask ${NETMASK} bridge_ports none bridge_stp off bridge_fd 0 hwaddress ether ${mac_address} -#LAN${bridge_id}" +# External ${bridge_id}" + + # Internal bridge configuration without an IP, as it's for internal network only + bridge_config+=" +auto vmbr${internal_bridge_id} +iface vmbr${internal_bridge_id} inet manual + bridge_ports none + bridge_stp off + bridge_fd 0 +# Internal ${bridge_id}" + + echo "$bridge_config" } # Collect inputs @@ -67,34 +82,20 @@ auto lo iface lo inet loopback iface lo inet6 loopback -iface ${NETWORK_INTERFACE} inet manual - up ip route add -net up ip route add -net ${GATEWAYADDRESS} netmask ${NETMASK} gw ${GATEWAYADDRESS} vmbr0 - up sysctl -w net.ipv4.ip_forward=1 - up sysctl -w net.ipv4.conf.${NETWORK_INTERFACE}.send_redirects=0 - up sysctl -w net.ipv6.conf.all.forwarding=1 - up ip route add 192.168.0.0/16 via ${ADDR[0]} dev vmbr0 - up ip route add 172.16.0.0/12 via ${ADDR[0]} dev vmbr0 - up ip route add 10.0.0.0/8 via ${ADDR[0]} dev vmbr0 - -iface ${NETWORK_INTERFACE} inet6 static - address 2a01:4f8:110:5143::2 - netmask 64 - gateway fe80::1 - auto vmbr0 iface vmbr0 inet static - address ${MAINSERVERIP} - netmask 32 - gateway ${GATEWAYADDRESS} - broadcast ${BROADCASTIP} - bridge-ports ${NETWORK_INTERFACE} - bridge-stp off - bridge-fd 0 - pointopoint ${GATEWAYADDRESS} -#WAN + address ${MAINSERVERIP} + netmask 32 + gateway ${GATEWAYADDRESS} + broadcast ${BROADCASTIP} + bridge-ports ${NETWORK_INTERFACE} + bridge-stp off + bridge-fd 0 + pointopoint ${GATEWAYADDRESS} +# Main IP configuration " -# Append bridge interfaces for each additional IP and MAC address +# Append bridge interfaces for each additional IP and MAC address and create internal bridges for i in "${!ADDR[@]}"; do interfaces_content+=$(create_bridge_text "${ADDR[i]}" "$((i + 1))" "${MACS[i]}") done @@ -105,31 +106,30 @@ echo "$interfaces_content" > /tmp/new_interfaces # Display the current network configuration echo "---------------------------------------------------------------------" echo "Current network configuration (/etc/network/interfaces):" -echo "" cat /etc/network/interfaces +echo "" # Display the new network configuration echo "---------------------------------------------------------------------" -echo "" echo "New network configuration:" cat /tmp/new_interfaces +echo "" # Show the differences echo "---------------------------------------------------------------------" echo "Configuration differences:" -echo "" diff /etc/network/interfaces /tmp/new_interfaces +echo "" # Confirm before applying changes echo "---------------------------------------------------------------------" -echo "" read -p "Apply this network configuration? [yes/no]: " apply_conf if [[ $apply_conf == [Yy]* ]]; then timestamp=$(date +%Y%m%d-%H%M%S) mv /etc/network/interfaces /etc/network/interfaces.bak-$timestamp mv /tmp/new_interfaces /etc/network/interfaces - echo "The network can be restarted with the following command: /etc/init.d/networking restart" + echo "The network can be restarted with the following command: '/etc/init.d/networking' restart or: 'systemctl restart networking'" else echo "Exiting without applying changes." rm /tmp/new_interfaces From 4473861a27f5cfe245cbc9a1627261f980340662 Mon Sep 17 00:00:00 2001 From: Lucky Bassi Date: Sat, 16 Dec 2023 12:57:32 +0100 Subject: [PATCH 08/10] fix(script): change network config --- script/network_config.sh | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/script/network_config.sh b/script/network_config.sh index 23762f5..c808166 100755 --- a/script/network_config.sh +++ b/script/network_config.sh @@ -13,8 +13,8 @@ create_bridge_text() { local ip=$1 local bridge_id=$2 local mac_address=$3 - local external_bridge_id=$((10 + (bridge_id - 1) * 2)) - local internal_bridge_id=$((external_bridge_id + 1)) + local external_bridge_id=$bridge_id + local internal_bridge_id=$((bridge_id * 100)) # External bridge configuration with MAC address and public IP local bridge_config=" @@ -26,7 +26,8 @@ iface vmbr${external_bridge_id} inet static bridge_stp off bridge_fd 0 hwaddress ether ${mac_address} -# External ${bridge_id}" +# External ${external_bridge_id} +" # Internal bridge configuration without an IP, as it's for internal network only bridge_config+=" @@ -35,7 +36,8 @@ iface vmbr${internal_bridge_id} inet manual bridge_ports none bridge_stp off bridge_fd 0 -# Internal ${bridge_id}" +# Internal ${internal_bridge_id} +" echo "$bridge_config" } @@ -97,7 +99,9 @@ iface vmbr0 inet static # Append bridge interfaces for each additional IP and MAC address and create internal bridges for i in "${!ADDR[@]}"; do - interfaces_content+=$(create_bridge_text "${ADDR[i]}" "$((i + 1))" "${MACS[i]}") + # Increment bridge_id for each additional IP + bridge_id=$((i + 1)) + interfaces_content+=$(create_bridge_text "${ADDR[i]}" "$bridge_id" "${MACS[i]}") done # Save the new configuration to a temporary file @@ -129,7 +133,7 @@ if [[ $apply_conf == [Yy]* ]]; then timestamp=$(date +%Y%m%d-%H%M%S) mv /etc/network/interfaces /etc/network/interfaces.bak-$timestamp mv /tmp/new_interfaces /etc/network/interfaces - echo "The network can be restarted with the following command: '/etc/init.d/networking' restart or: 'systemctl restart networking'" + echo "The network can be restarted with the following command: '/etc/init.d/networking' restart or 'systemctl restart networking'" else echo "Exiting without applying changes." rm /tmp/new_interfaces From 54f5b0a21871ffe62c1c1999e76f066cc4192cf1 Mon Sep 17 00:00:00 2001 From: Lucky Bassi Date: Sat, 16 Dec 2023 13:02:34 +0100 Subject: [PATCH 09/10] fix(script): change naming --- script/network_config.sh | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/script/network_config.sh b/script/network_config.sh index c808166..02f5263 100755 --- a/script/network_config.sh +++ b/script/network_config.sh @@ -16,7 +16,7 @@ create_bridge_text() { local external_bridge_id=$bridge_id local internal_bridge_id=$((bridge_id * 100)) - # External bridge configuration with MAC address and public IP + # WAN bridge configuration with MAC address and public IP local bridge_config=" auto vmbr${external_bridge_id} iface vmbr${external_bridge_id} inet static @@ -26,17 +26,17 @@ iface vmbr${external_bridge_id} inet static bridge_stp off bridge_fd 0 hwaddress ether ${mac_address} -# External ${external_bridge_id} +#WAN ${external_bridge_id} " - # Internal bridge configuration without an IP, as it's for internal network only + # LAN bridge configuration without an IP, as it's for internal network only bridge_config+=" auto vmbr${internal_bridge_id} iface vmbr${internal_bridge_id} inet manual bridge_ports none bridge_stp off bridge_fd 0 -# Internal ${internal_bridge_id} +#LAN ${internal_bridge_id} " echo "$bridge_config" @@ -94,7 +94,7 @@ iface vmbr0 inet static bridge-stp off bridge-fd 0 pointopoint ${GATEWAYADDRESS} -# Main IP configuration +#Main IP configuration " # Append bridge interfaces for each additional IP and MAC address and create internal bridges From 3b49e8f1d6e6e2b7d0339ef7f792f7aee859a582 Mon Sep 17 00:00:00 2001 From: Lucky Bassi Date: Sat, 16 Dec 2023 13:54:47 +0100 Subject: [PATCH 10/10] fix(script): fix eth route --- script/network_config.sh | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/script/network_config.sh b/script/network_config.sh index 02f5263..70f1751 100755 --- a/script/network_config.sh +++ b/script/network_config.sh @@ -74,6 +74,13 @@ fi IFS=',' read -ra ADDR <<<"$ADD_IP_ADDRESSES" IFS=',' read -ra MACS <<<"$MAC_ADDRESSES" +# Generate dynamic routing rules +additional_routes="" +for add_ip in "${ADDR[@]}"; do + additional_routes+=" up ip route add $add_ip dev ${NETWORK_INTERFACE} +" +done + # Initialize the interfaces file content interfaces_content=" ### Hetzner Online GmbH installimage @@ -84,6 +91,17 @@ auto lo iface lo inet loopback iface lo inet6 loopback +# Main network interface configuration +iface ${NETWORK_INTERFACE} inet manual + up ip route add -net ${GATEWAYADDRESS} netmask ${NETMASK} gw ${GATEWAYADDRESS} vmbr0 + up sysctl -w net.ipv4.ip_forward=1 + up sysctl -w net.ipv4.conf.${NETWORK_INTERFACE}.send_redirects=0 + up sysctl -w net.ipv6.conf.all.forwarding=1 +$additional_routes + up ip route add 192.168.0.0/16 via ${MAINSERVERIP} dev vmbr0 + up ip route add 172.16.0.0/12 via ${MAINSERVERIP} dev vmbr0 + up ip route add 10.0.0.0/8 via ${MAINSERVERIP} dev vmbr0 + auto vmbr0 iface vmbr0 inet static address ${MAINSERVERIP}