본문 바로가기
자격증

[리눅스마스터 1급] 11-1. 파일 서비스 (NFS)

by LimSeongHyeon 2025. 4. 29.


개요


NFS

설치 및 활성화
# NFS 설치
$ dnf install -y rpcbind nfs-utils

# 서버 데몬 활성화
$ systemctl enable --now nfs-server
$ systemctl enable --now rpcbind
$ systemctl enable --now nfs-mountd
$ systemctl enable --now nfs-idmapd

# 방화벽 설정
$ firewall-cmd --permanent --add-service=nfs
$ firewall-cmd --permanent --add-service=mountd
$ firewall-cmd --permanent --add-service=rpc-bind
$ firewall-cmd --reload

 


공유 디렉터리 설정

$ sudo mkdir -p /srv/nfs/share
$ sudo chown nobody:nobody /srv/nfs/share
$ sudo chmod 755 /srv/nfs/share

 


 

/etc/exports

NFS 서버의 공유 대상 디렉터리와 접근 권한을 설정하는 파일.
더보기
EXAMPLE
       # sample /etc/exports file
       /               master(rw) trusty(rw,no_root_squash)
       /projects       proj*.local.domain(rw)
       /usr            *.local.domain(ro) @trusted(rw)
       /home/joe       pc001(rw,all_squash,anonuid=150,anongid=100)
       /pub            *(ro,insecure,all_squash)
       /srv/www        -sync,rw server @trusted @external(ro)
       /foo            2001:db8:9:e54::/64(rw) 192.0.2.0/24(rw)
       /build          buildhost[0-9].local.domain(rw)

       The first line exports the entire filesystem to machines master and trusty.  In addition to write  access,  all  uid  squashing  is
       turned  off  for  host  trusty.  The  second  and third entry show examples for wildcard hostnames and netgroups (this is the entry
       `@trusted'). The fourth line shows the entry for the PC/NFS client discussed above. Line 5 exports the public FTP directory to  ev‐
       ery  host in the world, executing all requests under the nobody account. The insecure option in this entry also allows clients with
       NFS implementations that don't use a reserved port for NFS.  The sixth line exports a directory read-write to the machine  'server'
       as  well  as  the  `@trusted' netgroup, and read-only to netgroup `@external', all three mounts with the `sync' option enabled. The
       seventh line exports a directory to both an IPv6 and an IPv4 subnet. The eighth line demonstrates a character class wildcard match.

 

 

Options

옵션 설명 참고 내용
rw 읽기 및 쓰기 허용 (read/write)  
ro 읽기 전용 (read-only)  
sync 요청이 즉시 디스크에 기록됨  속도↓, 안정성↑
async 디스크 쓰기를 지연함 속도↑, 안정성↓
no_root_squash 클라이언트 root 계정을 서버 root로 허용 위험 주로 테스트용
root_squash 클라이언트 root → 서버 nobody로 매핑  
all_squash 모든 사용자 → 서버 nobody로 매핑  
no_all_squash 사용자 ID 매핑 안 함 (기본값)  
anonuid=<UID> 익명 사용자(uid) 지정 all_squash와 함께 사용
anongid=<GID> 익명 사용자(gid) 지정 all_squash와 함께 사용
subtree_check 하위 디렉토리 일관성 확인 (기본값) 속도↓
no_subtree_check 하위 디렉토리 체크 생략 속도↑

 

 

root

root에 대한 접근을 어떻게 처리할지 선택한다. root_squash는 root의 권한을 nobody로 강등시킨다. 때문에 보안적으로 안전하며 통상 해당 옵션을 사용한다. 반면, no_root_squash는 root 권한을 그대로 인정하므로 테스트 환경에서 주로 사용한다.

 

 

 

all (others)

all(others)에 대해 어떻게 처리할지 선택한다. all_squash는 Others로 접근하는 모든 사용자를 nobody로 강등시킨다. 해당 설정은 주로 공유 스토리지와 같은 환경에서 사용된다. 반면, no_all_squash는 others에 대한 별도의 강등 없이 그대로의 UID를 인정한다.

 

 

Example

/srv/nfs/share 192.168.5.0/24(rw,sync,no_root_squash)
/shared 디렉토리를 공유할 것이다. 182.168.5.0/24 영역에서의 요청만 허용 할 것이며, 읽기 및 쓰기 허용, 동기 처리, 클라이언트 root 계정을 서버 root로 허용할 것이다.

 


 

변경사항 적용

# /etc/exports 재적용
$ sudo exportfs -rav

# (필요시) 부팅 시, 자동 실행
$ sudo systemctl enable --now nfs-server

 

 

서비스 구동 상태 확인

명령어 설명 예시
exportfs -v 서버가 /etc/exports가 문제없이 설정되었는지 확인하기 위해 현재 공유 설정을 출력한다. $ exportfs -v 192.168.5.13
showmount -e 클라이언트가 서버에게 "export된 디렉터리를 알려주세요." 물으면 서버가 rpc.mountd의 export 테이블을 기준으로 응답한다. $ showmount -e 192.168.5.13
rpcinfo -p 클라이언트가 서버에게 "운영중인 모든 RPC 서비스를 알려주세요." 묻고 이를 서버가 응답한다. $ rpcinfo -p 192.168.5.13
nfsstat 서버는 서버의, 클라이언트는 클라이언트의 NFS 및 RPC에 대한 통계 정보를 표시한다. $ nfsstat
더보기
방화벽 열기
$ sudo firewall-cmd --permanent --add-service=nfs
$ sudo firewall-cmd --reload

 

클라이언트 마운트
$ sudo mount -t nfs 192.168.5.10:/srv/nfs/share /mnt

 

/etc/fstab (부팅시 자동 마운트)

192.168.5.13:/nfsdata /ndata nfs timeo=15,soft,retrans=300

 


문제

설정

 

NFS 서버에서 공유 대상 디렉터리 및 접근 제한을 설정하는 파일의 절대 경로를 입력하세요.

더보기

/etc/exports

 

특정 네트워크(192.168.12.31)를 사용하는 개발자가 특정 경로(/srv/nfs/share)에 대해서 비동기 처리의 읽기 및 쓰기를 테스트 하려고 한다. 이때 적절한 설정 값을 입력하세요.

더보기

/srv/nfs/share 192.168.12.31(rw, async, no_root_squash)

 

 

특정 경로(/srv/nfs/share)로 특정 네트워크 대역(192.168.12.0/24)에서 접근하는 클라이언트는 읽기 및 쓰기가 가능하고, 비동기 처리로 이루어지며, root 권한을 허용하지 않는 설정을 입력하세요.

더보기

/srv/nfs/share 192.168.12.0/24(rw, async, root_squash)

 

특정 경로(/srv/nfs/share)로 특정 네트워크 대역(192.168.12.0/24)에서 접근하는 클라이언트는 읽기만 가능하고, 동기 처리로 이루어지며, 모두 nobody 권한으로 강등 시키는 설정을 입력하세요.

더보기

/srv/nfs/share 192.168.12.0/24(r, sync, all_squash)


 

적용

 

NFS 서버의 설정파일을 재적용 하는 명령어를 입력하세요.

더보기

$ exportfs -rav

 

클라이언트에서 서버(192.168.5.10)의 특정 경로(/srv/nfs/share)를 /mnt 디렉터리에 마운트 하는 명령어를 입력하세요.

더보기

mount -t nfs 192.168.5.10:/srv/nfs/share /mnt

 

클라이언트가 NFS 서버(192.168.5.10)의 공유 디렉터리(/nfs/share)/mnt에 자동으로 마운트하도록 설정하려고 한다. 마운트 방식은 NFS, 소프트 마운트, 타임아웃 15초, 재전송 횟수 300회이다. 수정 해야하는 파일과 해당 설정 값을 입력하세요.

더보기

/etc/fstab

192.168.5.10:/nfs/share /mnt nfs timeo=15,soft,retrans=300

 


 

확인

 

NFS 서버에서 /etc/exports의 적용 결과를 출력하는 명령어를 입력하세요.

더보기

$ exportfs -v

 

클라이언트에서 NFS 서버(192.168.5.10)에 등록된 모든 RPC 서비스를 확인하는 명령어를 입력하세요.

더보기

$ rpcinfo -p 192.168.5.10

 

클라이언트 혹은 서버에서 RPC 호출 관련 통계(상태) 정보를 확인하는 명령어를 입력하세요.

더보기

$ nfsstat -r

 

클라이언트에서 NFS 서버(192.168.5.10)에서 공유된 디렉터리 목록을 확인하는 명령어를 입력하세요

더보기

$ showmount -e 192.168.5.10