Gentoo Forums
Gentoo Forums
Gentoo Forums
Quick Search: in
[tip] VSFTPD, dynamic ip, pasv_address
View unanswered posts
View posts from last 24 hours

 
Reply to topic    Gentoo Forums Forum Index Documentation, Tips & Tricks
View previous topic :: View next topic  
Author Message
t0mcat
Tux's lil' helper
Tux's lil' helper


Joined: 12 Feb 2004
Posts: 111
Location: Catania, Italy

PostPosted: Thu Jan 20, 2005 2:05 pm    Post subject: [tip] VSFTPD, dynamic ip, pasv_address Reply with quote

I'm actually using VSFTPD as FTP server, and i'm very statisfied by his features, security, and easy installation/configuration/mainteniance.

The only problem of this daemon is that the pasv mode must be statically locked to an IP in the main daemon configuration (see pasv_address in the man).

So if you have a dynamic IP address and want to use PASV mode (e.g. in case your server is behind a NAT/Firewall), you should change manually the pasv_address directive in the vsftpd.conf to match your external IP address, because by default vsftpd resolves the internal lan IP of the machine.

To solve this issue (that seems to afflict many users, without any clue so far), i've written a small bash script that updates the configuration and eventually restarts the daemon automatically.

Note that this is my first bash script, so i'm sure it can be improved :)

Code:

#!/bin/bash
if [ `/usr/bin/whoami` = 'root' ]
then
        OLDIP=`cat /etc/vsftpd/vsftpd.conf | grep pasv_address |  sed -e 's/pasv_address=\([0-9]\{1,3\}\.[0-9]\{1,3\}\.[0-9]\{1,3\}\.[0-9]\{1,3\}\)/\1/'`
        CURRENTIP=`lynx -dump http://checkip.dyndns.org/ | awk {'print $4'} | grep -e '^[0-9]'`
        if [ "$OLDIP" != "$CURRENTIP" ];
        then
                echo "$(date +'%a %b %d %T %Y') *** Public IP changed from $OLDIP to $CURRENTIP" >> /var/log/vsftpd/vsftpd.log
                sed 's/\(pasv_address=\)\([0-9]\{1,3\}\.[0-9]\{1,3\}\.[0-9]\{1,3\}\.[0-9]\{1,3\}\)/\1'$CURRENTIP'/' /etc/vsftpd/vsftpd.conf > /etc/vsftpd/vsftpd.conf.new &&
                mv /etc/vsftpd/vsftpd.conf.new /etc/vsftpd/vsftpd.conf &&
                echo "$(date +'%a %b %d %T %Y') *** Pasv_address setting updated successfully - restarting daemon" >> /var/log/vsftpd/vsftpd.log
                /etc/init.d/vsftpd restart
# this will spam much output in your log terminal
#       else
#               echo "$(date +'%a %b %d %T %Y') *** IP check OK - IP unchanged" >> /dev/tty12
        fi
else
        echo "Permission denied"
fi


you can put it in the root crontab, and enjoy the self pasv_address updating. :)

hope it helps.
_________________
il gattaccio
a.k.a etienne
Back to top
View user's profile Send private message
yanos
Tux's lil' helper
Tux's lil' helper


Joined: 11 Sep 2003
Posts: 149
Location: montreal, canada

PostPosted: Tue Apr 19, 2005 3:47 am    Post subject: Reply with quote

It works great. Thanks!
Back to top
View user's profile Send private message
Display posts from previous:   
Reply to topic    Gentoo Forums Forum Index Documentation, Tips & Tricks All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum