IPUPDATE: Difference between revisions
Jump to navigation
Jump to search
No edit summary |
No edit summary |
||
Line 1: | Line 1: | ||
Include as part of the netup.sh script so that when a dynamic IP address change happens, the system keeps working | |||
<pre> | <pre> | ||
#!/bin/sh | #!/bin/sh |
Revision as of 00:49, 9 June 2015
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