What is NFS (Network File System)?
Learn how NFS mounts remote directories, translates file calls into RPCs, and uses close-to-open consistency.
Expected Interview Answer
NFS (Network File System) is a protocol that lets a client machine mount a directory exported by a remote server and access its files using the same system calls as a local file system, making the network largely transparent to applications.
An NFS server exports one or more directories, and a client mounts an exported path onto a local mount point, after which reads, writes, and directory listings on that mount point are transparently translated into remote procedure calls (RPCs) sent to the server rather than local disk I/O. Early NFS versions (v2, v3) were stateless at the protocol level — each RPC carried enough information to be handled independently, which simplified server crash recovery since the server did not need to remember open-file state — while NFSv4 introduced stateful operations like open and lock leases along with built-in strong authentication and compound RPCs that batch multiple operations into one round trip for better performance. Because multiple clients can mount the same export and cache file data locally for speed, NFS must define a consistency model (typically close-to-open consistency, where a client is only guaranteed to see another client’s changes after that client closes the file) to bound how stale a client’s cache can get. Performance depends heavily on network latency and the chosen caching and locking strategy, which is why NFS is well suited to internal, trusted, low-latency networks rather than as a general-purpose replacement for local disk.
- Lets applications access remote files through unmodified local system calls
- Statelessness in early versions simplified server crash recovery
- NFSv4 adds locking, leases, and strong authentication for correctness
- Close-to-open consistency gives a predictable, bounded staleness guarantee
AI Mentor Explanation
NFS is like a groundskeeper at one stadium remotely maintaining a scoreboard so that any away broadcaster’s screen shows the exact same numbers as if the scoreboard were local, with every update sent as a small message rather than the broadcaster maintaining its own copy. Early versions treated each update message independently so a crashed scoreboard server could resume without remembering who was watching, while newer versions add locks so two broadcasters do not overwrite the same score at once. A broadcaster only trusts its cached view of the score as current right after refreshing it, mirroring close-to-open consistency.
Step-by-Step Explanation
Step 1
Server exports a directory
The NFS server designates one or more directories as exports, available to authorized client hosts.
Step 2
Client mounts the export
The client attaches the remote export to a local mount point using the NFS protocol.
Step 3
File operations become RPCs
Reads, writes, and directory calls on the mount point are translated into RPCs sent to the server.
Step 4
Consistency is bounded
Close-to-open consistency (or NFSv4 leases/locks) governs when one client’s changes become visible to another.
What Interviewer Expects
- Clear explanation of mount, export, and RPC translation
- Understanding of statelessness in early NFS vs statefulness in NFSv4
- Knowledge of close-to-open consistency as the caching guarantee
- Awareness that NFS suits trusted, low-latency internal networks
Common Mistakes
- Thinking NFS gives the exact same guarantees as a local file system at all times
- Confusing NFS with a general-purpose distributed file system like HDFS
- Not knowing why statelessness simplified early NFS server crash recovery
- Assuming NFSv4 has no meaningful improvements over NFSv3
Best Answer (HR Friendly)
“NFS (Network File System) lets a computer mount a folder that actually lives on a remote server and work with its files exactly like they were on the local disk, without the application needing to know the difference. Early versions were designed so the server did not have to remember who had files open, which made crash recovery simple, while newer versions add proper locking and stronger security. It works best on fast, trusted internal networks rather than as a substitute for local storage.”
Code Example
struct nfs_read_args {
char file_handle[64];
off_t offset;
size_t count;
};
ssize_t nfs_read(const char *mount_path, off_t offset, void *buf, size_t count) {
struct nfs_read_args args;
resolve_file_handle(mount_path, args.file_handle);
args.offset = offset;
args.count = count;
/* looks like a local read() to the calling application, but this
actually sends an RPC to the NFS server and blocks for a reply */
return send_rpc_and_wait(NFS_PROC_READ, &args, buf, count);
}Follow-up Questions
- What is close-to-open consistency and why does NFS use it?
- How does NFSv4 differ from NFSv3 in state management?
- Why was statelessness important in early NFS server design?
- What are the security implications of exporting an NFS directory without strong authentication?
MCQ Practice
1. What does an NFS client do when it mounts a remote export?
Mounting attaches the export to a local path; subsequent file operations become RPC calls to the NFS server rather than local disk I/O.
2. Why were early NFS versions designed to be stateless?
A stateless server could crash and restart without needing to reconstruct which clients had which files open, since each RPC was self-contained.
3. What consistency model does NFS typically use for cached file data?
Close-to-open consistency guarantees a client sees another client’s changes only after that client has closed the file, bounding staleness predictably.
Flash Cards
What is NFS? — A protocol letting a client mount and access a remote server’s exported directory as if it were local.
How are NFS file operations implemented under the hood? — As remote procedure calls (RPCs) sent to the server.
Why were early NFS versions stateless? — To simplify server crash recovery since no open-file state needed to be tracked.
What consistency model does NFS use? — Close-to-open consistency, guaranteeing visibility of changes after a file is closed.