Laravel Community Tools by
Tighten
Nova Packages
Laravel Tricks
Forge Recipes
Forge Recipes
Staff Picks
All Recipes
Login
Staff Picks
All Recipes
Login
Back to Recipes
Install Floating IP
2 years ago
internetztube
un-tested
Clone
bash
Copy
#!/bin/sh # Install (Hetzner Cloud) Floating IP on Ubuntu 20.4 or Ubuntu 22.04 machine. # Run this script as root user! # Make sure to update IP_ADDRESS! IP_ADDRESS="" # https://docs.hetzner.com/de/cloud/floating-ips/persistent-configuration/ # Check if the script is being run as root or with sudo privileges if [ "$(id -u)" -ne 0 ]; then echo "This script requires root or sudo privileges to run." exit 1 fi is_ipv4() { echo "$1" | grep -E -q "^[0-9]+\.[0-9]+\.[0-9]+\.[0-9]+$" } is_ipv6() { echo "$1" | grep -E -q "^[a-fA-F0-9:]+$" } ip_type() { if is_ipv4 "$1"; then echo "4" elif is_ipv6 "$1"; then echo "6" else echo "Invalid" fi } is_ip_valid() { if is_ipv4 "$1" || is_ipv6 "$1"; then return 0 else return 1 fi } if ! is_ip_valid "$IP_ADDRESS"; then echo "Invalid IP Address!" exit 1 fi echo "$IP_ADDRESS" IP_TYPE=$(ip_type "$IP_ADDRESS") UBUNTU_VERSION=$(lsb_release -a 2>/dev/null | grep "Release" | awk '{print $2}') if [ "$UBUNTU_VERSION" = "20.04" ] || [ "$UBUNTU_VERSION" = "22.04" ]; then echo "Nice! You're running Ubuntu 20.04 or 22.04!" FILE_NAME="/etc/netplan/60-floating-ip-$IP_ADDRESS.yaml" FILE_CONTENT="network: version: 2 renderer: networkd ethernets: eth0: addresses: - $IP_ADDRESS/$([ "$IP_TYPE" = "4" ] && echo "32" || echo "64") " touch "$FILE_NAME" echo "$FILE_CONTENT" > "$FILE_NAME" echo "File created! $FILE_NAME" sudo netplan apply else echo "Your Ubuntu Version is not supported!" fi
Comments
No comments yet.
Log in
to leave a comment.