#!/usr/bin/env bash ################################################################################ # This is property of eXtremeSHOK.com # You are free to use, modify and distribute, however you may not remove this notice. # Copyright (c) Adrian Jon Kriel :: admin@extremeshok.com ################################################################################ # # Script updates can be found at: https://github.com/extremeshok/xshok-proxmox # # License: BSD (Berkeley Software Distribution) # ################################################################################ # ## CREATES A ROUTED vmbr0 AND NAT vmbr1 NETWORK CONFIGURATION FOR PROXMOX # Autodetects the correct settings (interface, gatewat, netmask, etc) # Supports IPv4 and IPv6, Private Network uses 10.10.10.1/24 # # Also installs and properly configures the isc-dhcp-server to allow for DHCP on the vmbr1 (NAT) # # ROUTED (vmbr0): # All traffic is routed via the main IP address and uses the MAC address of the physical interface. # VM's can have multiple IP addresses and they do NOT require a MAC to be set for the IP via service provider # # NAT (vmbr1): # Allows a VM to have internet connectivity without requiring its own IP address # Assignes 10.10.10.100 - 10.10.10.200 via DHCP # # Public IP's can be assigned via DHCP, adding a host define to the /etc/dhcp/hosts.public file # # Tested on OVH and Hetzner based servers # # ALSO CREATES A NAT Private Network as vmbr1 # # NOTE: WILL OVERWRITE /etc/network/interfaces # A backup will be created as /etc/network/interfaces.timestamp # ################################################################################ # # THERE ARE NO USER CONFIGURABLE OPTIONS IN THIS SCRIPT # ################################################################################ # Set the local export LANG="en_US.UTF-8" export LC_ALL="C" network_interfaces_file="/etc/network/interfaces" #Detect and install dependencies if ! type "dhcpd" >& /dev/null; then /usr/bin/env DEBIAN_FRONTEND=noninteractive apt-get -y -o Dpkg::Options::='--force-confdef' install isc-dhcp-server fi if ! [ -f "network-addiprange.sh" ]; then echo "Downloading network-addiprange.sh script" curl -O https://raw.githubusercontent.com/extremeshok/xshok-proxmox/master/networking/network-addiprange.sh && chmod +x network-addiprange.sh fi if ! grep -q '#!/usr/bin/env bash' "network-addiprange.sh"; then echo "ERROR: network-addiprange.sh is invalid" fi if ! [ -f "/etc/sysctl.d/99-networking.conf" ]; then echo "Creating /etc/sysctl.d/99-networking.conf" cat > /etc/sysctl.d/99-networking.conf < "$network_interfaces_file" <> /etc/pve/datacenter.cfg ### Load extra files, ie for extra gateways source /etc/network/interfaces.d/* EOF default_v6="$(ip -6 addr show dev "$default_interface" | awk '/global/ { print $2}')" default_v6ip=${default_v6%/*} default_v6mask=${default_v6#*/} default_v6gateway="$(ip -6 route | awk '/default/ { print $3 }')" if [ "$default_v6ip" != "" ] && [ "$default_v6mask" != "" ] && [ "$default_v6gateway" != "" ]; then cat >> "$network_interfaces_file" << EOF ### IPv6 ### iface ${default_interface} inet6 static address ${default_v6ip} netmask ${default_v6mask} gateway ${default_v6gateway} iface vmbr0 inet6 static address ${default_v6ip} netmask 64 EOF fi cat >> "$network_interfaces_file" << EOF ### Extra IP/IP Ranges ### # Use ./network-addiprange.sh script to add ip/ip ranges or edit the examples below # ## Example add IP range 176.9.216.192/27 # up route add -net 94.130.239.192 netmask 255.255.255.192 dev vmbr0 ## Example add IP 176.9.123.158 # up route add -net 176.9.123.158 netmask 255.255.255.255 dev vmbr0 EOF # Configure isc-dhcp-server if [ -f "/etc/default/isc-dhcp-server" ] ; then cp /etc/default/isc-dhcp-server "/etc/default/isc-dhcp-server.$(date +"%Y-%m-%d_%H-%M-%S")" fi if [ -f "/etc/dhcp/dhcpd.conf" ] ; then cp /etc/dhcp/dhcpd.conf "/etc/dhcp/dhcpd.conf.$(date +"%Y-%m-%d_%H-%M-%S")" fi cat > /etc/default/isc-dhcp-server < /etc/dhcp/dhcpd.conf < "/etc/dhcp/hosts.public" <