Below is a script that checks the current external IP address, and if it has changed since last check, updates the pasv_address line in the vsftpd.conf file.
I'm using Debian Stretch. For dig you may need to install dnsutils like so:
apt-get install dnsutilsCreate the shell script file:
vi /root/vsftpd-pasv_address.sh#!/bin/bash
[[ -f /root/last_ip.txt ]] && last_ip=$( /dev/null)
if [ $? -ne 0 ]
then
    # Exit if the dig command failed
    exit 1
fi
# If not empty and IP changed
if [[ -n "$this_ip" && "$last_ip" != "$this_ip" ]]
then
    echo $(date +"%Y-%m-%d %T") "Old IP: $last_ip"
    echo $(date +"%Y-%m-%d %T") "New IP: $this_ip"
    echo "$this_ip" > /root/last_ip.txt
    sed -ri "s/^(pasv_address=*).*$/\1${this_ip}/" /etc/vsftpd.conf
    /etc/init.d/vsftpd restart
fi
exit 0Make the file executable:
chmod +x /root/vsftpd-pasv_address.shI added the following cronjob:
*/10 * * * * /root/vsftpd-pasv_address.shThe script will run every 10 minutes, and update vsftpd.conf if your external IP address changes.
Category: 
