Debian Setup Script: Unterschied zwischen den Versionen
Zur Navigation springen
Zur Suche springen
| (4 dazwischenliegende Versionen desselben Benutzers werden nicht angezeigt) | |||
| Zeile 1: | Zeile 1: | ||
=Das Script= | =Das Script= | ||
*cat /usr/local/sbin/debian-setup.sh | *cat /usr/local/sbin/debian-setup.sh | ||
| − | <pre> | + | <pre> |
#!/bin/bash | #!/bin/bash | ||
# Standardwerte setzen | # Standardwerte setzen | ||
| Zeile 40: | Zeile 40: | ||
hostnamectl set-hostname $FQDN | hostnamectl set-hostname $FQDN | ||
| + | |||
cat<<HERE > /etc/network/interfaces | cat<<HERE > /etc/network/interfaces | ||
# This file describes the network interfaces available on your system | # This file describes the network interfaces available on your system | ||
| Zeile 59: | Zeile 60: | ||
HERE | HERE | ||
</pre> | </pre> | ||
| + | |||
=Rechte anpassen= | =Rechte anpassen= | ||
*chmod +x /usr/local/sbin/debian-setup.sh | *chmod +x /usr/local/sbin/debian-setup.sh | ||
| + | |||
| + | = Netzkonfiguration Beispiel = | ||
| + | |||
| + | {| class="wikitable" style="background-color: #f2f2f2;" | ||
| + | ! Parameter !! Wert !! Erläuterung | ||
| + | |- | ||
| + | | '''Netzwerk (NIC)''' || br0 || Netzwerkebrücke | ||
| + | |- | ||
| + | | '''IP''' || 192.168.6.50+XX || Statische IP | ||
| + | |- | ||
| + | | '''CIDR''' || 24 || Classless Inter-Domain Routing Präfixlänge | ||
| + | |- | ||
| + | | '''GW''' || 192.168.6.254 || GATEWAY | ||
| + | |- | ||
| + | | '''NS''' || 1.1.1.1 || Resolver | ||
| + | |- | ||
| + | | '''FQDN''' || test.it2XX.int || Fully Qualified Domain Name | ||
| + | |- | ||
| + | | '''SHORT''' || test || Short Name | ||
| + | |- | ||
| + | | '''DOM''' || it2XX.int|| Domain Name | ||
| + | |} | ||
| + | =Anwendung= | ||
| + | *debian-setup.sh -f test.it2XX.int -a 192.168.6.50+XX/24 -g 192.168.6.254 -n 1.1.1.1 | ||
| + | *reboot | ||
| + | ;dann per ssh einloggen | ||
Aktuelle Version vom 4. Mai 2026, 09:59 Uhr
Das Script
- cat /usr/local/sbin/debian-setup.sh
#!/bin/bash
# Standardwerte setzen
FQDN=""
ADDR=""
GW=""
NS=""
# Optionen mit getopts parsen
while getopts "f:a:g:n:" opt; do
case $opt in
f) FQDN="$OPTARG" ;;
a) ADDR="$OPTARG" ;;
g) GW="$OPTARG" ;;
n) NS="$OPTARG" ;;
*) echo "Ungültige Option" >&2; exit 1 ;;
esac
done
# Gültigkeit prüfen
if [[ -z "$FQDN" || -z "$ADDR" || -z "$GW" || -z "$NS" ]]; then
echo "Fehlende Argumente für statische Konfiguration! Nutzung:"
echo "$0 -f <FQDN> -a <IP/CIDR> -g <Gateway> -n <Nameserver>"
exit 1
fi
# SHORT und DOM aus FQDN berechnen
SHORT=$(echo "$FQDN" | cut -d'.' -f1)
DOM=$(echo "$FQDN" | cut -d'.' -f2-)
echo FQDN : $FQDN
echo ADDR : $ADDR
echo GW : $GW
echo NS : $NS
echo SHORT : $SHORT
echo DOM : $DOM
hostnamectl set-hostname $FQDN
cat<<HERE > /etc/network/interfaces
# This file describes the network interfaces available on your system
# and how to activate them. For more information, see interfaces(5).
source /etc/network/interfaces.d/*
# The loopback network interface
auto lo
iface lo inet loopback
# The primary network interface
auto enp0s3
iface enp0s3 inet static
address $ADDR
gateway $GW
dns-nameservers $NS
dns-search $DOM
HERE
Rechte anpassen
- chmod +x /usr/local/sbin/debian-setup.sh
Netzkonfiguration Beispiel
| Parameter | Wert | Erläuterung |
|---|---|---|
| Netzwerk (NIC) | br0 | Netzwerkebrücke |
| IP | 192.168.6.50+XX | Statische IP |
| CIDR | 24 | Classless Inter-Domain Routing Präfixlänge |
| GW | 192.168.6.254 | GATEWAY |
| NS | 1.1.1.1 | Resolver |
| FQDN | test.it2XX.int | Fully Qualified Domain Name |
| SHORT | test | Short Name |
| DOM | it2XX.int | Domain Name |
Anwendung
- debian-setup.sh -f test.it2XX.int -a 192.168.6.50+XX/24 -g 192.168.6.254 -n 1.1.1.1
- reboot
- dann per ssh einloggen