IPUPDATE: Difference between revisions
Jump to navigation
Jump to search
(Created page with "<pre> #!/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/IP...") |
No edit summary |
||
(5 intermediate revisions by 2 users not shown) | |||
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 | ||
if [ !-d /root/scripts/IPINFO ]; then | if [[ ! -d /root/scripts/IPINFO ]]; then | ||
mkdir -p /root/scripts/IPINFO | mkdir -p /root/scripts/IPINFO | ||
fi | fi | ||
Line 14: | Line 16: | ||
OLDBC="" | OLDBC="" | ||
fi | fi | ||
if [ -e /root/scripts/IPINFO/ | if [ -e /root/scripts/IPINFO/gateway ]; then | ||
OLDGW=$(cat /root/scripts/IPINFO/gateway) | OLDGW=$(cat /root/scripts/IPINFO/gateway) | ||
else | else | ||
OLDGW="" | OLDGW="" | ||
fi | fi | ||
while [[ ! -n $CURIP || ! -n $CURBC || ! -n $CURGW ]]; do sleep 3 | 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 | if [[ $CURIP != $OLDIP ]]; then | ||
for i in /root/scripts/iptables-restore /etc/ipsec.conf /etc/ipsec.secrets /etc/xl2tpd/xl2tpd.conf; do | 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; | sed -i s/$OLDIP/$CURIP/g $i; | ||
Line 31: | Line 35: | ||
fi | fi | ||
if [[$CURBC != $OLDBC ]]; then | if [[ $CURBC != $OLDBC ]]; then | ||
for i in /root/scripts/iptables-restore /etc/ipsec.conf /etc/xl2tpd/xl2tpd.conf; do | for i in /root/scripts/iptables-restore /etc/ipsec.conf /etc/xl2tpd/xl2tpd.conf; do | ||
sed -i s/$OLDBC/$CURBC/g $i; | sed -i s/$OLDBC/$CURBC/g $i; | ||
Line 37: | Line 41: | ||
fi | fi | ||
if [[$CURGW != $OLDGW ]]; then | if [[ $CURGW != $OLDGW ]]; then | ||
for i in /root/scripts/iptables-restore /etc/ipsec.conf /etc/xl2tpd/xl2tpd.conf; do | for i in /root/scripts/iptables-restore /etc/ipsec.conf /etc/xl2tpd/xl2tpd.conf; do | ||
sed -i s/$OLDGW/$CURGW/g $i; | sed -i s/$OLDGW/$CURGW/g $i; | ||
Line 46: | Line 50: | ||
echo -n "$CURBC" > /root/scripts/IPINFO/bcast | echo -n "$CURBC" > /root/scripts/IPINFO/bcast | ||
echo -n "$CURGW" > /root/scripts/IPINFO/gateway | echo -n "$CURGW" > /root/scripts/IPINFO/gateway | ||
ipsec setup restart | |||
</pre> | </pre> |
Latest revision as of 18:33, 30 September 2020
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