IPUPDATE

From help.computerisms.ca
Jump to navigation Jump to search
The printable version is no longer supported and may have rendering errors. Please update your browser bookmarks and please use the default browser print function instead.

Include as part of the netup.sh script so that when a dynamic IP address change happens, the system keeps working.

#!/bin/sh
if [[ ! -d /root/scripts/IPINFO ]]; then
        mkdir -p /root/scripts/IPINFO
fi
if [ -e /root/scripts/IPINFO/ipaddr ]; then
        OLDIP=$(cat /root/scripts/IPINFO/ipaddr)
else
        OLDIP=""
fi
if [ -e /root/scripts/IPINFO/bcast ]; then
        OLDBC=$(cat /root/scripts/IPINFO/bcast)
else
        OLDBC=""
fi
if [ -e /root/scripts/IPINFO/gateway ]; then
        OLDGW=$(cat /root/scripts/IPINFO/gateway)
else
        OLDGW=""
fi

while [[ ! -n $CURIP || ! -n $CURBC || ! -n $CURGW ]]; do 
	CURIP=$(ip addr show dev eth0 | grep inet | head -1 | cut -f 6 -d " " | cut -f 1 -d \/)
	CURBC=$(ip addr show dev eth0 | grep inet | head -1 | cut -f 8 -d " " | cut -f 1 -d \/)
	CURGW=$(ip route | grep default | cut -f 3 -d " ")
	sleep 3
done

if [[ $CURIP != $OLDIP ]]; then
        for i in /root/scripts/iptables-restore /etc/ipsec.conf /etc/ipsec.secrets /etc/xl2tpd/xl2tpd.conf; do
                sed -i s/$OLDIP/$CURIP/g $i;
        done
fi

if [[ $CURBC != $OLDBC ]]; then
        for i in /root/scripts/iptables-restore /etc/ipsec.conf /etc/xl2tpd/xl2tpd.conf; do
                sed -i s/$OLDBC/$CURBC/g $i;
        done
fi

if [[ $CURGW != $OLDGW ]]; then
        for i in /root/scripts/iptables-restore /etc/ipsec.conf /etc/xl2tpd/xl2tpd.conf; do
                sed -i s/$OLDGW/$CURGW/g $i;
        done
fi

echo -n "$CURIP" > /root/scripts/IPINFO/ipaddr
echo -n "$CURBC" > /root/scripts/IPINFO/bcast
echo -n "$CURGW" > /root/scripts/IPINFO/gateway

ipsec setup restart