Metainformationen zur Seite
  •  

Unterschiede

Hier werden die Unterschiede zwischen zwei Versionen angezeigt.

Link zu dieser Vergleichsansicht

Beide Seiten der vorigen RevisionVorhergehende Überarbeitung
archiv:4_x:server:knowledgebase:change-ip [07.06.2023 15:41] – gelöscht - Externe Bearbeitung (Unbekanntes Datum) 127.0.0.1archiv:4_x:server:knowledgebase:change-ip [07.06.2023 15:41] (aktuell) – ↷ Seite von archiv:4_x:ucware:server:knowledgebase:change-ip nach archiv:4_x:server:knowledgebase:change-ip verschoben richard.neubert
Zeile 1: Zeile 1:
 +====== change-ip.sh ======
 +
 +Das Skript //change-ip.sh// ändert die IP-Adresse der UCware-Konfiguration. Die Systemkonfiguration (''%%/etc/interfaces%%'') bleibt dabei unangestastet.
 +
 +===== Kurzanleitung =====
 +
 +  - //change-ip.sh// auf die UCware kopieren.
 +  - Die Berechtigung zum Ausführen setzen:
 +
 +<code>
 +chmod +x change-ip.sh
 +</code>
 +  - Skript unter dem Benutzer root ausführen:
 +
 +<code>
 +sudo ./change-ip.sh
 +</code>
 +Das Skript fragt jetzt dialoggesteuert nach der neuen IP-Adresse und konfiguriert anschließend die UCWare um.
 +
 +Um auch die reale IP-Adresse der UCware zu ändern, muss die Datei ''%%/etc/network/interfaces%%'' noch manuell angepasst werden.
 +
 +===== Best Practice =====
 +
 +Die Netzwerkeinstellungen in der ''%%/etc/network/interfaces%%'' ändern und mit ''%%ifdown eth0; ifup eth1%%'' aktivieren. Wird anschließend ''%%change-ip.sh%%'' gestatrtet, wird die aktuelle IP-Adresse automatisch vorgeschlagen.
 +
 +
 +<file bash change-ip.sh>
 +#!/bin/bash
 +
 +export LANG="C"
 +LOGFILE="/var/log/ipinstaller.log"
 +
 +# handle ctrl+c / cancel
 +function handle_exit() {
 +   if [[ $1 -ne 0 ]]; then
 +      export DIALOGRC
 +      export DIALOGOPTS='--backtitle "IPinstaller" --title "Error"'
 +      dialog --msgbox "IPinstaller was interrupted!" 8 40
 +      clear
 +      exit 1
 +   fi
 +}
 +
 +# check for root privileges
 +[ "$(id -u)" -eq 0 ] || { echo "This installer needs root privileges, please re-run with sudo. Exiting."; exit 1; }
 +
 +apt-get install --assume-yes --quiet --no-install-recommends --no-install-suggests dialog subnetcalc pwgen wget debconf-utils gzip >$LOGFILE 2>&1
 +
 +# set up dialog
 +TMPFILE=$(mktemp --quiet)
 +DIALOGRC=$(mktemp --quiet)
 +echo "screen_color = (WHITE,GREEN,ON)" > $DIALOGRC
 +export DIALOGRC
 +export DIALOGOPT#!/bin/bash
 +
 +export LANG="C"
 +LOGFILE="/var/log/ipinstaller.log"
 +
 +# handle ctrl+c / cancel
 +function handle_exit() {
 +   if [[ $1 -ne 0 ]]; then
 +      export DIALOGRC
 +      export DIALOGOPTS='--backtitle "IPinstaller" --title "Error"'
 +      dialog --msgbox "IPinstaller was interrupted!" 8 40
 +      clear
 +      exit 1
 +   fi
 +}
 +
 +# check for root privileges
 +[ "$(id -u)" -eq 0 ] || { echo "This installer needs root privileges, please re-run with sudo. Exiting."; exit 1; }
 +
 +apt-get install --assume-yes --quiet --no-install-recommends --no-install-suggests dialog subnetcalc pwgen wget debconf-utils gzip >$LOGFILE 2>&1
 +
 +# set up dialog
 +TMPFILE=$(mktemp --quiet)
 +DIALOGRC=$(mktemp --quiet)
 +echo "screen_color = (WHITE,GREEN,ON)" > $DIALOGRC
 +export DIALOGRC
 +export DIALOGOPTS='--backtitle "IPinstaller"'
 +
 +trap "rm -f $TMPFILE $DIALOGRC" 0 1 2 5 15
 +
 +# the disclaimer
 +dialog --msgbox "This installer will configure automatically your UCware VoIP config" 8 40
 +
 +# get the VoIP interface, so we can suggest its IP later
 +INTERFACE="eth0"
 +export DIALOGOPTS='--backtitle "UCware installer" --title "Network configuration"'
 +dialog --inputbox "Please enter the name of the VoIP interface" 8 40 "$INTERFACE" 2>$TMPFILE
 +INTERFACE=$(awk 'NR==1 {print;exit}' $TMPFILE)
 +
 +# basic variable initialization
 +IP=$(ifconfig $INTERFACE | grep "inet addr" | cut -d ':' -f 2 | cut -d ' ' -f 1)
 +NETMASK=$(ifconfig $INTERFACE | grep "inet addr" | cut -d ':' -f 4 | cut -d ' ' -f 1)
 +NTPSERVER="0.de.pool.ntp.org"
 +DNSSERVER="8.8.8.8"
 +
 +# IP configuration, uses subnetcalc for validation and processing
 +IPVALID=1
 +while [[ $IPVALID -ne 0 ]]; do
 +   dialog  --separate-widget $'\n' \
 +         --inputbox "Please enter the VoIP network IP" 8 40 "$IP" \
 +         --inputbox "Please enter the VoIP network netmask" 8 40 "$NETMASK" 2>$TMPFILE
 +   handle_exit $?
 +
 +   # read answers
 +   IP=$(awk 'NR==1 {print;exit}' $TMPFILE)
 +   NETMASK=$(awk 'NR==2 {print;exit}' $TMPFILE)
 +
 +   # extrapolate router, broadcast, dhcp range
 +   SUBNETCALC=$(subnetcalc $IP $NETMASK)
 +   IPVALID=$?
 +
 +   if [[ $IPVALID -ne 0 ]]; then
 +      dialog --title "Network configuration" --msgbox "Invalid IP configuration, please try again" 8 40
 +   else
 +      IP=$(echo "$SUBNETCALC" | awk '/Address/ {print $3}')
 +      NETMASK=$(echo "$SUBNETCALC" | awk '/Netmask/ {print $3}')
 +      BROADCAST=$(echo "$SUBNETCALC" | awk '/Broadcast/ {print $3}')
 +      ROUTER=$(echo "$SUBNETCALC" | awk '/Host Range/ {print $5}')
 +      NET=$(echo "$SUBNETCALC" | awk '/Network/ {print $3}')
 +      DHCPMIN="${NET%.*}.100"
 +      DHCPMAX="${NET%.*}.250"
 +   fi
 +done
 +
 +# Gateway and DHCP configuration
 +dialog  --title "Network configuration" --separate-widget $'\n' \
 +      --inputbox "Please enter the VoIP network gateway IP" 8 40 "$ROUTER" \
 +      --inputbox "Please enter the VoIP DHCP range minimum" 8 40 "$DHCPMIN" \
 +      --inputbox "Please enter the VoIP DHCP range maximum" 8 40 "$DHCPMAX" 2>$TMPFILE
 +handle_exit $?
 +ROUTER=$(awk 'NR==1 {print;exit}' $TMPFILE)
 +DHCPMIN=$(awk 'NR==2 {print;exit}' $TMPFILE)
 +DHCPMAX=$(awk 'NR==3 {print;exit}' $TMPFILE)
 +
 +# present summary, ask user to confirm values
 +dialog --title "Summary" --yesno "VoIP net address: $IP/$NETMASK
 +
 +Router: $ROUTER
 +Broadcast: $BROADCAST
 +DHCP range: $DHCPMIN - $DHCPMAX
 +
 +This UCware server will be configured using those settings, proceed?" 18 50
 +
 +PROCEED=$?
 +
 +if [[ "$PROCEED" -ne 0 ]]; then
 +   dialog --title "Error" --msgbox "Not continuing due to user abort." 8 40
 +   clear
 +   exit 1
 +fi
 +
 +export DIALOGOPTS='--backtitle "IPinstaller" --title "Installation in progress"'
 +dialog --infobox "Configuring ip configs ..." 8 40
 +
 +DBPW=$(/opt/ucware/sbin/gs-get-conf DB_MASTER_PWD)
 +DBUSER=$(/opt/ucware/sbin/gs-get-conf DB_MASTER_USER)
 +
 +mysql --user=$DBUSER --password=$DBPW <<< "USE \`asterisk\`; UPDATE \`hosts\` SET \`host\`='$IP' WHERE \`id\`='1';"
 +
 +OLDINTERFACE=$(awk '/INTERFACES=/ {print}' /etc/default/isc-dhcp-server | cut -d '"' -f2)
 +OLDNETMASK=$(awk '/netmask/ {print $3 " " $4}' /etc/dhcp/dhcpd.conf)
 +
 +zcat /usr/share/doc/ucware-core/misc/dhcpd-3-example.conf.gz > /etc/dhcp/dhcpd.conf
 +sed --in-place "s/192.168.1.130/$IP/" /etc/dhcp/dhcpd.conf
 +sed --in-place "s/broadcast-address 192.168.1.255/broadcast-address $BROADCAST/" /etc/dhcp/dhcpd.conf
 +sed --in-place "s/routers 192.168.1.1/routers $ROUTER/" /etc/dhcp/dhcpd.conf
 +sed --in-place "s/domain-name-servers 192.168.1.1/domain-name-servers $IP/" /etc/dhcp/dhcpd.conf
 +sed --in-place "s/subnet-mask 255.255.255.0/subnet-mask $NETMASK/" /etc/dhcp/dhcpd.conf
 +sed --in-place "s/netmask 255.255.255.0/netmask $NETMASK/" /etc/dhcp/dhcpd.conf
 +sed --in-place "s/subnet 192.168.1.0/subnet $NET/" /etc/dhcp/dhcpd.conf
 +sed --in-place "s/range 192.168.1.2 192.168.1.129/range $DHCPMIN $DHCPMAX/" /etc/dhcp/dhcpd.conf
 +sed --in-place "s/[[:space:]]*range 192.168.1.131 192.168.1.254;//" /etc/dhcp/dhcpd.conf
 +
 +sed -i "s/INTERFACES=\"$OLDINTERFACE\"/INTERFACES=\"$INTERFACE\"/" /etc/default/isc-dhcp-server
 +
 +OLDPROVHOST=$(awk -F '$' '/PROV_HOST/ {print $2; exit;}' /etc/ucware/ucware.php)
 +OLDNTPSERVER=$(awk -F '$' '/NTP_SERVER/ {print $2;}' /etc/ucware/ucware.php)
 +OLDBUTTONDAEMONHOST=$(awk -F '$' '/BUTTONDAEMON_HOST/ {print $2; exit;}' /etc/ucware/ucware.php)S
 +
 +sed --in-place "s/$OLDPROVHOST/PROV_HOST = '$IP';/" /etc/ucware/ucware.php
 +sed --in-place "s/$OLDNTPSERVER/NTP_SERVER = '$IP';/" /etc/ucware/ucware.php
 +sed --in-place "s/$OLDBUTTONDAEMONHOST/BUTTONDAEMON_HOST = '$IP';/" /etc/ucware/ucware.php
 +
 +
 +PERMIT=$()
 +sed --in-place "s|permit[\s]*=[\s]*$OLDPROVHOST/$OLDNETMASK|permit = $NET/$NETMASK|" /etc/ucware/asterisk/manager.conf.d-available/ucwared.conf
 +sed --in-place "s/$OLDPROVHOST/$IP/" /opt/ucwared/ucwared.conf
 +
 +
 +echo "VoIP net interface: $INTERFACE
 +VoIP net address: $IP/$NETMASK
 +Router: $ROUTER
 +DHCP range: $DHCPMIN - $DHCPMAX
 +SQL password for ucware: $SQLPASS
 +SQL password for root: $SQLROOTPASS
 +UCware package user: $UCUSER
 +UCware package password: $UCPASS
 +NTP server: $NTPSERVER
 +DNS server: $DNSSERVER" > /var/log/ucware/choices.log
 +
 +service isc-dhcp-server restart
 +service asterisk restart
 +service ucwared restart
 +
 +</file>