Skip to content

Instantly share code, notes, and snippets.

@Pl4n3
Last active January 15, 2025 14:19
Show Gist options
  • Select an option

  • Save Pl4n3/e86fd627644430824d850f5d714c3137 to your computer and use it in GitHub Desktop.

Select an option

Save Pl4n3/e86fd627644430824d850f5d714c3137 to your computer and use it in GitHub Desktop.
Fix perl-ftp by priorizing ipv4 over ipv6

Fix perl-ftp by prioritizing ipv4 over ipv6

  1. On a Linuxserver Ftp.put didnt work, gave error. Tests revealed, that only active mode was bugged, passive mode upload went through.
    Can't call method "sockdomain" on an undefined value at /usr/share/perl/5.36/Net/FTP.pm line 913.
    
  2. Similar error occurs here: https://www.perlmonks.org/?node_id=1106790. Overwriting Net::FTP LocalAddr => $ftp->sockhost, as described there, removed error, but ftp.put still didnt work. Something with the ip-config 'ifconfig' was wrong, 'ping localhost' showed ipv6.
  3. Tested disabling ipv6 as described in https://bobcares.com/blog/debian-12-disable-ipv6/. This way ipv6 is disabled only for the session, not after 'reboot'. Now ping was ipv4, ifconfig didnt show ipv6 and ftp.put works.
    sudo sysctl -w net.ipv6.conf.all.disable_ipv6=1
    sudo sysctl -w net.ipv6.conf.default.disable_ipv6=1
    
  4. Reenabled ipv6, in 'ifconfig' ipv6 returned, but one ipv6 line was missing. The line returned after 'reboot'.
    sudo sysctl -w net.ipv6.conf.all.disable_ipv6=0
    sudo sysctl -w net.ipv6.conf.default.disable_ipv6=0
    
  5. To keep ipv6 enabled, an approach is to priorize ipv4 over ipv6. Explained in https://weblog.lkiesow.de/20220311-make-linux-prefer-ipv4.html, this can be done by editing /etc/gai.conf. In the file all lines were commented out. Its needed to uncomment the whole block label and precedence, except the last line for which another line with priority 100 is uncommented. After the edit, without 'reboot' needed, ping shows ipv4 and ftp.put works.
    #precedence ::ffff:0:0/96  10
    #    For sites which prefer IPv4 connections change the last line to
    precedence ::ffff:0:0/96  100
    

Conclusion: Who is to blame, is this a perl-ftp bug, that priority ipv6 cannot be handled? In any case, a nullpointer exception shouldnt occur. It would be interesting to test commandline ftp, if it can do active mode put with initial config.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment