skip to content

A hosting provider's FTP server sits on 10.0.5.20 behind NAT and answers PASV with '227 Entering Passive Mode (10,0,5,20,234,96)'; why do Internet clients hang, and what fixes it?

level: seniorimportance: must knowfreq 27%

answer

  1. address inside the payload
  2. RFC 1918 in the reply
  3. advertise the public address
  4. pin and forward a port range

basics

~20 s

The 227 reply hands Internet clients the server's private address 10.0.5.20, which they cannot reach. Configure the server to advertise its public address and a fixed passive port range, then forward and open that range on the NAT and firewall.

solid answer

~50 s

FTP writes addresses into its payload. The server builds the `227 Entering Passive Mode` reply from its own socket address, so behind NAT it advertises `10,0,5,20`, an RFC 1918 address, and an Internet client dials a host it cannot route to. Unless a NAT FTP helper rewrites the reply, the client waits until the connection attempt times out. The fix is on the server: tell it the public address to advertise and pin its passive ports to a small range, for example vsftpd's `pasv_address`, `pasv_min_port` and `pasv_max_port`, or ProFTPD's `MasqueradeAddress` and `PassivePorts` (each one server's settings). Then forward exactly that range, plus 21, from the public address to the server and allow it on the firewall. Size the range for peak concurrent data connections with headroom, and give the public address as a number rather than a name that resolves to the inside address.

code

ini · 5 lines
ini
# vsftpd.conf (vsftpd's settings) on 10.0.5.20
pasv_enable=YES
pasv_address=203.0.113.10
pasv_min_port=60000
pasv_max_port=60199

go deeper

for a junior

Recall that the 227 reply carries an IP address as well as a port, and that a private address there is useless to a client on the Internet.

for a middle

Explain why header NAT cannot fix an address in the payload, and which two server settings, the advertised address and the passive range, solve it.

for a senior

Walk through the full change: server settings, forwarding and firewall rules for the exact range, range sizing, the inside-client hairpin issue, and why EPSV clients behaved differently.

for a principal

Decide whether a multi-tenant FTP estate should own a fixed public address and range per server, and what that costs in address space and firewall change control.

## Why the reply is wrong In passive mode the client sends `PASV` and the server answers with `227 Entering Passive Mode (h1,h2,h3,h4,p1,p2)`: an IPv4 address and a port, written as comma-separated decimal bytes. The server fills in the address of the interface the control connection arrived on. On a host with a **private address** behind a **NAT** (network address translation, which rewrites addresses in packet headers at the network edge), that is the private address. In the scenario, the server at `10.0.5.20` is published to the Internet as `203.0.113.10`, with port 21 forwarded to it. The control connection works because the NAT rewrites packet headers. But the reply text itself says: 1. C: `PASV` 2. S: `227 Entering Passive Mode (10,0,5,20,234,96)` 3. The client opens TCP to `10.0.5.20`, port 60000 (234 x 256 + 96). 4. That address is not routable on the Internet, so the attempt goes nowhere and the client eventually times out. Header translation cannot help: the address sits in the **payload**, as ASCII text. Only an FTP helper (an application-level gateway) on the NAT that parses the control connection and rewrites the text would fix it, and a server should not depend on one. ## The server-side fix Two settings, both implementation-specific: | Need | vsftpd setting | ProFTPD directive | |---|---|---| | Advertise the public address | `pasv_address=203.0.113.10` (numeric unless `pasv_addr_resolve=YES`) | `MasqueradeAddress 203.0.113.10` | | Use a fixed passive range | `pasv_min_port=60000`, `pasv_max_port=60199` | `PassivePorts 60000 60199` | Defaults matter: in vsftpd `pasv_address` defaults to the address of the incoming connected socket and both port bounds default to 0, meaning any port. ProFTPD's NAT notes say plainly that without `PassivePorts` you would have to forward every port from 1024 to 65535. Then configure the network to match: - forward TCP 21 and TCP 60000-60199 from `203.0.113.10` to `10.0.5.20`; - allow the same ports inbound on the stateful firewall; - disable or bypass any FTP helper on that path if it would rewrite the already correct address again. After the change the reply reads `227 Entering Passive Mode (203,0,113,10,234,96)`, and the client's connection arrives at the forwarded range. ## Sizing the range Each concurrent passive data connection holds one port from the range: one per active upload, download or directory listing. A port can also stay briefly unusable after a transfer closes. - Start from peak concurrent transfers across all customers, not from the customer count. - Add headroom for listings that clients run alongside transfers and for ports still recovering from closed connections. - ProFTPD documents the failure when a range is too small: clients see delays or cannot transfer, and the daemon falls back to a kernel-assigned port and logs it; that port will usually not be forwarded, so the transfer fails anyway. A range of a few hundred ports suits a modest server; a busy multi-tenant one may need thousands. The point is that the range is **known**, forwarded and opened exactly, rather than "everything above 1023". ## Traps after the fix - **A DNS name that resolves inside.** ProFTPD's FAQ warns that `MasqueradeAddress ftp.example.com` resolved at startup inside the LAN yields the internal address again; use the numeric public address. - **Inside clients now get the public address.** Customers or staff on the LAN receive `203.0.113.10`, which works only if the NAT hairpins. ProFTPD answers this with a `<VirtualHost>` for the LAN address that omits `MasqueradeAddress`, or with per-client classes in `mod_ifsession`. - **Clients that use `EPSV`.** The `229 Entering Extended Passive Mode (|||60000|)` reply carries only the port, and the client reuses the control connection's address, so such clients may have worked before the fix if the port happened to be forwarded. That is a hint, not a reason to skip the address setting. - **The same-address check.** vsftpd by default (`pasv_promiscuous=NO`) refuses a passive data connection that comes from a different IP address than the control connection; a client NAT that spreads one client's connections across several public addresses trips it. ## The judgment being tested The interviewer wants to hear that FTP's addresses live in the payload, that the server must be told what the outside sees, and that a pinned, forwarded and firewalled range replaces "open everything". Saying when you would still use a helper, and why you would not depend on one, separates experience from recitation.

  • Why might clients using EPSV have worked while PASV clients hung?
    The `229 Entering Extended Passive Mode (|||60000|)` reply carries only a port; RFC 2428 says the client reuses the control connection's address. Those clients dial `203.0.113.10`, the public address they already reached, so if the port is forwarded they succeed. PASV clients dial the private address written into the 227 reply.
  • After setting MasqueradeAddress, staff on the provider's LAN cannot list directories. Why, and what fixes it?
    They now receive the public address too, and reaching it from inside works only if the NAT hairpins. With ProFTPD, add a `<VirtualHost>` for the LAN address without `MasqueradeAddress`, or use `mod_ifsession` classes to give internal clients the inside address, so each population is told the address it can reach.
  • What happens when the passive range is smaller than the peak number of concurrent transfers?
    New passive requests find no free port in the range. ProFTPD documents delays or failed transfers and a fallback to a kernel-assigned port, which it logs; that port is outside the forwarded range, so the client's connection is dropped at the NAT or firewall. Size the range from peak concurrent data connections plus headroom.

A business card printed with an internal desk extension: callers outside the building cannot dial it. The fix is printing the public switchboard number and having reception route a fixed block of direct lines to the desk.

  • Port forwarding 21 on the NAT is enough for passive transfers
  • The NAT rewrites every address in the packet, payload included, automatically
  • Open 1024-65535 to the server because the passive port cannot be predicted
  • Point the advertised address at a DNS name that resolves to the inside address
  • Size the passive range by the number of customer accounts