Get WAN IP Address on Edgerouter

WAN interface configured with DHCP so address is changing constantly. Wanted to build a script that would determine IP address and upload to remote server using sftp or scp.

This is incomplete right now, it lacks the upload ability.

Schedule script to run every every 15 minutes using cron.

#!/bin/bash

# Print layer 2 and 3 interface statistics to file
 ifconfig pppoe0 > pppoe.txt

#Find line that includes IP addresses, remove pppoe.txt
 awk '/inet/' pppoe.txt > addresses.txt
 rm pppoe.txt

# Print 2nd field
 awk -F: '{print $2}' addresses.txt > address.txt
 # Remove addresses.txt, no longer needed
 rm addresses.txt

# Extract IP address from string
 temp=$(<address.txt)
 echo "$temp" | grep -o '[0-9]*.[0-9]*.[0-9]*.[0-9]* '
 # Remove address.txt, no longer needed
 rm address.txt

Ubiquiti Edgerouter Site-to-Site VPN with BGP Notes

Following Ubiquiti’s documentation is tricky as it currently refers to EdgeOS 1.7 and with EdgeOS 1.8 we received a new version of Strong Swan which deprecates the show vpn ike sa command.

I discovered this via a Ubiquiti forums thread. I thought it worth repeating as mentioned in there that Edgeos 1.8 the command show vpn ipsec sa now includes any information the deprecated show vpn ike sa provided.