Got it — you have a Linux host that connects to an FTP server using a hardcoded URL, and you want to redirect that connection to another FTP server without changing the hardcoded URL. Here are a few approaches to achieve this:
1. Use /etc/hosts to map the FTP server hostname to a different IP
If the URL uses a hostname (not an IP address), you can override that hostname to point to the new FTP server’s IP using the hosts file:
This way, when your Linux host tries to connect to original.ftp.server.com, it will be redirected at the DNS resolution level to 192.168.1.50 (your new FTP server).
2. Use a firewall or proxy to redirect FTP traffic
If the FTP server URL is an IP address and you cannot change the /etc/hosts or if you want to handle redirection transparently, you can intercept the traffic and redirect it using:
- iptables (for IPv4) — redirect outgoing connections to the old FTP server IP to the new FTP server IP.
- A transparent proxy specialized for FTP traffic.
Example with iptables (assuming FTP server IP is 10.0.0.1 and new FTP server 10.0.0.2):
sudo iptables -t nat -A OUTPUT -p tcp -d 10.0.0.1 --dport 21 -j DNAT --to-destination 10.0.0.2:21
sudo iptables -t nat -A POSTROUTING -p tcp -d 10.0.0.2 --dport 21 -j MASQUERADE
Note:
- This only redirects control channel (port 21). FTP data channels complicate things due to separate ports or active/passive modes.
- FTP is tricky for NAT because it uses multiple ports dynamically; for transparent proxying, consider using
ftp-proxy or an FTP-aware proxy.
3. Run a local FTP proxy or FTP server that forwards requests
You can deploy a lightweight FTP proxy server (like ftp-proxy from iptables package, or use tools like rinetd, or a simple TCP forwarding tool), listening on the expected FTP server IP or name/local port, and forwarding connections to the new FTP server.
Summary
- If the URL is hostname-based: Modify
/etc/hosts.
- If hardcoded IP: Use
iptables DNAT rules or an FTP proxy.
- For complex setups: A transparent FTP proxy is recommended.
If you want, I can help with detailed steps for the method that suits you best! Could you also share:
- Is the FTP URL hostname or IP?
- Can you edit
/etc/hosts?
- Is this client Linux host running this?
- Is the FTP service using active or passive mode?
That info will help me tailor the solution.