0

Using a Linux/Windows PC, I want to download a file from a Windows server. However, I want to use a Raspberry Pi in between to act as a Jump Server.

Linux/Windows (client)------> Pi (jump server)---------->Windows Server

Therefore, I want to do:

tftp -g -t i -f $PATH_FILE $RASPBERRY_PI_IP

How do I need to configure the Pi so when I do that, I get the file from the server?

I found this command and run it in the Linux client:

ssh -L 69:WINDOWS_SERVER_IP:69 pi@RASPBERRY_PI_IP

However, what this does it's to log me in the Pi from the Linux client and what I want to do is just to send the command to download the file.

Update: I did the exact configuration @Ingo suggested in his answer but, from the Pi, if I do put /home/pi/test.py, I'm getting Transfer timed out. Also, I enabled the TFTP client in the mswin-client and if I do tftp Pi_address put C:\Users\Downloads\adapter.png, I get Connect request failed. One thing I noticed is that I can ping the Pi from the mswin-client but not the mswin-client from the Pi...and I can pint Pi<->mswin-server on both directions. What could it be wrong?

Thanks!!

2
  • Is tftp the only program you want to use?
    – Ingo
    Mar 3, 2020 at 19:31
  • @Ingo yes, maybe I need to use sftp instead temporary because tftp is not available at the moment. Thanks!
    – itd
    Mar 4, 2020 at 22:13

1 Answer 1

1

With specific services like tftp you can use port forwarding on the Raspberry Pi to forward the network traffic to the MS Windows computer. For my example I will use interface eth0. Just change it if you use another interface, e.g. wlan0. Then ensure from the RasPi that you can ping all involved devices. I will use these names:

rpi ~$ ping client
rpi ~$ ping raspberrypi
rpi ~$ ping mswin-server

You can map these names to ip addresses in /etc/hosts.

tftp uses port 69 by default. If you want to use other ports you should find the places in the example where to change it. To enable port forwarding we use iptables but first we have to enable ip forwarding, so we have to do:

rpi ~$ echo '1' | sudo tee /proc/sys/net/ipv4/ip_forward
rpi ~$ sudo iptables -t nat -A PREROUTING -p udp -i eth0 --dport 69 -j DNAT --to-destination mswin-server:69
rpi ~$ sudo iptables -A FORWARD -p udp -d mswin-server --dport 69 -m state --state NEW,ESTABLISHED,RELATED -j ACCEPT

With tftp-hpa for example you should now be able to get files on client from mswin-server, if using the default port 69, with:

client ~$ tftp raspberrypi -c get hello.txt

To make all this persistent first uncomment #net.ipv4.ip_forward=1 in /etc/sysctl.conf. Then use this unit file to create a new service:

rpi ~$ sudo systemctl --force --full edit port-forwarding.service

In the empty editor insert these statements, save them, and quit the editor:

[Unit]
Description=Port forwarding
BindsTo=systemd-networkd.service
After=systemd-networkd.service
# If you use dhcpcd instead of systemd-networkd change to
#BindsTo=dhcpcd.service
#After=dhcpcd.service

[Service]
Type=oneshot
RemainAfterExit=yes
ExecStart=/usr/sbin/iptables -t nat -A PREROUTING -p udp -i eth0 --dport 69 -j DNAT --to-destination mswin-server:69
ExecStartPost=/usr/sbin/iptables -A FORWARD -p udp -d mswin-server --dport 69 -m state --state NEW,ESTABLISHED,RELATED -j ACCEPT

ExecStopPost=-/usr/sbin/iptables -D FORWARD -p udp -d mswin-server --dport 69 -m state --state NEW,ESTABLISHED,RELATED -j ACCEPT
ExecStopPost=-/usr/sbin/iptables -t nat -D PREROUTING -p udp -i eth0 --dport 69 -j DNAT --to-destination mswin-server:69

[Install]
WantedBy=systemd-networkd.service
# If you use dhcpcd instead of systemd-networkd change to
#WantedBy=dhcpcd.service

Reboot.

10
  • thanks a lot! however, after following all the steps, I do "client ~$ tftp mswin-server_USER@raspberrypi_IP -c get hello.txt" and it doesn't work. it tries to connect to the raspberry (I know because of the correct password I to input). Am I missing something?
    – itd
    Mar 7, 2020 at 7:49
  • @itd Is file hello.txt available on mswin-server? Can you get it on the RasPi with tftp from mswin-server? What tftp program are you using on Linux?
    – Ingo
    Mar 7, 2020 at 10:22
  • Actually, I'm using sftp, so I did everything that you said but set port 22 instead of 69 and wrote "sftp" insted of "tftp"...but it should behave the same, right?
    – itd
    Mar 8, 2020 at 18:30
  • @itd No, sftp does not use the trivial-ftp protocol. sftp uses the default ftp protocol in addition with an encrypted secure component: two reasons why it does not work (wrong protocol and encrypted). Please install and use tftp-hpa. Are you sure that on the mswin-server is a trivial-ftp server running?
    – Ingo
    Mar 8, 2020 at 23:45
  • I have a Filezilla server running on mswin-server. Let me know if I can try a different one, please. Also, if you know a client for Windows, my testing should be much more easier :)
    – itd
    Mar 11, 2020 at 9:40

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.