Rocky9 문서 원본 보기
←
Rocky9
둘러보기로 이동
검색으로 이동
문서 편집 작업을 수행할 권한이 없습니다. 다음 이유를 확인해주세요:
요청한 작업은 다음 중 하나의 권한을 가진 사용자에게 제한됩니다:
관리자
, 문서 편집자.
문서의 원본을 보거나 복사할 수 있습니다.
= Rocky Linux 9 초기 설치 및 기본 서버 설정 가이드 = == 문서 개요 == 본 문서는 Rocky Linux 9 또는 RHEL 9 계열 운영체제를 처음 설치한 후 기본 서버로 사용하기 위한 초기 설정 절차를 단계별로 설명한다. 다음 순서로 진행한다. # 운영체제 설치 # 설치 직후 기본 확인 # CLI에서 IP 주소 설정 # 네트워크 인터페이스 본딩 설정 # 구형 ifcfg 파일 형식 적용 # 호스트 이름 설정 # SSH 기본 설정 # SSH 특정 계정 접속 제한 # SSH 포트 변경 # firewalld 포트 허용 # firewalld 비활성화 및 iptables 전환 # 서비스 상태 및 포트 확인 # SSH 및 SFTP 접속 테스트 # Samba 파일 공유 설정 # 전체 설정 최종 점검 본 문서의 명령어는 기본적으로 root 계정으로 실행하는 것을 기준으로 한다. 일반 계정으로 실행할 경우 명령어 앞에 sudo를 추가한다. <syntaxhighlight lang="bash"> sudo 명령어 </syntaxhighlight> == 1. 운영체제 설치 == === 1.1 설치 이미지 준비 === Rocky Linux 설치 이미지는 일반적으로 다음 두 종류를 사용한다. {| class="wikitable" |- ! 이미지 종류 ! 설명 ! 권장 용도 |- | DVD ISO | 운영체제 설치에 필요한 대부분의 패키지가 포함되어 있다. | 인터넷 연결이 제한된 환경 |- | Boot ISO | 최소 설치 이미지이며 설치 중 인터넷 저장소에 연결한다. | 인터넷 연결이 가능한 환경 |} 서버 환경에서는 일반적으로 DVD ISO 사용을 권장한다. === 1.2 설치 USB 제작 === Windows 환경에서는 Rufus, Ventoy 등의 프로그램을 사용하여 설치 USB를 만들 수 있다. 설치 대상 디스크의 기존 데이터는 모두 삭제될 수 있으므로 설치 전에 반드시 필요한 자료를 백업한다. === 1.3 BIOS 또는 UEFI 설정 === {| class="wikitable" |- ! 항목 ! 권장 설정 |- | Boot Mode | UEFI |- | Secure Boot | 일반적으로 활성화 가능 |- | SATA Mode | AHCI |- | Virtualization | 가상화 사용 시 활성화 |- | Boot Priority | USB 설치 장치를 첫 번째로 설정 |} === 1.4 설치 화면 진입 === 설치 USB 또는 ISO로 부팅한 후 다음 항목을 선택한다. <syntaxhighlight lang="text"> Install Rocky Linux 9 </syntaxhighlight> === 1.5 설치 대상 디스크 설정 === 초심자는 자동 파티션 구성을 사용할 수 있다. 서버 용도로 별도 파티션을 구성하려면 다음 예시를 참고한다. {| class="wikitable" |- ! 마운트 지점 ! 권장 용도 ! 예시 크기 |- | /boot/efi | UEFI 부트 영역 | 600 MiB |- | /boot | 커널 및 부트로더 | 1 GiB |- | / | 운영체제 루트 영역 | 40 GiB 이상 |- | /var | 로그 및 서비스 데이터 | 사용 목적에 따라 결정 |- | /home | 사용자 홈 디렉터리 | 사용 목적에 따라 결정 |- | swap | 메모리 보조 공간 | 메모리 및 용도에 따라 결정 |} 로그 서버, DB 서버, 웹 서버는 /var 사용량이 크게 증가할 수 있으므로 별도 볼륨으로 분리하는 것이 좋다. === 1.6 소프트웨어 선택 === 서버 용도에서는 다음 설치 유형을 권장한다. <syntaxhighlight lang="text"> Minimal Install </syntaxhighlight> GUI가 필요한 경우 다음을 선택할 수 있다. <syntaxhighlight lang="text"> Server with GUI </syntaxhighlight> === 1.7 root 비밀번호 및 사용자 생성 === 설치 과정에서 root 비밀번호를 설정하고, 관리용 일반 계정을 함께 생성하는 것을 권장한다. 예시: <syntaxhighlight lang="text"> 사용자 이름: admin 관리자 권한: 활성화 </syntaxhighlight> 설치 완료 후 시스템을 재부팅한다. == 2. 설치 직후 기본 확인 == === 2.1 운영체제 버전 확인 === <syntaxhighlight lang="bash"> cat /etc/os-release uname -r hostnamectl </syntaxhighlight> === 2.2 현재 사용자 확인 === <syntaxhighlight lang="bash"> whoami </syntaxhighlight> root 계정으로 전환: <syntaxhighlight lang="bash"> sudo -i </syntaxhighlight> === 2.3 패키지 업데이트 === <syntaxhighlight lang="bash"> dnf update -y </syntaxhighlight> 커널이 업데이트되었으면 재부팅한다. <syntaxhighlight lang="bash"> reboot </syntaxhighlight> == 3. CLI에서 IP 주소 설정 == Rocky Linux 9는 NetworkManager를 기본 네트워크 관리 서비스로 사용한다. CLI에서는 주로 nmcli 명령어를 사용한다. === 3.1 네트워크 인터페이스 확인 === <syntaxhighlight lang="bash"> ip address ip -br address nmcli device status </syntaxhighlight> === 3.2 네트워크 연결 프로파일 확인 === <syntaxhighlight lang="bash"> nmcli connection show </syntaxhighlight> 장치 이름과 연결 프로파일 이름은 다를 수 있다. === 3.3 DHCP 설정 === 연결 프로파일 이름이 ens192인 경우: <syntaxhighlight lang="bash"> nmcli connection modify ens192 ipv4.method auto nmcli connection modify ens192 ipv4.addresses "" nmcli connection modify ens192 ipv4.gateway "" nmcli connection modify ens192 ipv4.dns "" nmcli connection up ens192 </syntaxhighlight> 확인: <syntaxhighlight lang="bash"> ip -br address show ens192 ip route cat /etc/resolv.conf </syntaxhighlight> === 3.4 고정 IP 설정 === 예시 환경: {| class="wikitable" |- ! 항목 ! 설정값 |- | 연결 프로파일 | ens192 |- | IP 주소 | 192.168.10.20 |- | 서브넷 | /24 |- | 기본 게이트웨이 | 192.168.10.1 |- | DNS 서버 | 192.168.10.1, 8.8.8.8 |} 설정: <syntaxhighlight lang="bash"> nmcli connection modify ens192 \ ipv4.method manual \ ipv4.addresses 192.168.10.20/24 \ ipv4.gateway 192.168.10.1 \ ipv4.dns "192.168.10.1 8.8.8.8" nmcli connection modify ens192 connection.autoconnect yes nmcli connection up ens192 </syntaxhighlight> 원격 SSH 접속 상태에서 IP 주소를 변경하면 접속이 끊길 수 있다. 가능하면 콘솔, iLO, iDRAC, IPMI, VMware 콘솔 등 별도의 관리 경로를 확보한 후 변경한다. === 3.5 설정 결과 확인 === <syntaxhighlight lang="bash"> ip -br address ip route ping -c 4 192.168.10.1 ping -c 4 8.8.8.8 ping -c 4 google.com </syntaxhighlight> 8.8.8.8 통신은 되지만 도메인 이름 통신이 되지 않으면 DNS 설정을 확인한다. === 3.6 네트워크 설정 상세 확인 === <syntaxhighlight lang="bash"> nmcli connection show ens192 nmcli -f ipv4 connection show ens192 </syntaxhighlight> == 4. 네트워크 인터페이스 본딩 설정 == 네트워크 본딩은 두 개 이상의 물리 인터페이스를 하나의 논리 인터페이스로 묶어 장애 절체 또는 부하 분산을 구성하는 기능이다. === 4.1 본딩 설정 전 주의사항 === 본딩 설정 중 네트워크가 중단될 수 있으므로 반드시 콘솔 접속 수단을 확보한다. 기존 설정 백업: <syntaxhighlight lang="bash"> BACKUP_DIR="/root/network-backup-$(date +%Y%m%d_%H%M%S)" mkdir -p "$BACKUP_DIR" cp -a /etc/NetworkManager/system-connections "$BACKUP_DIR/" 2>/dev/null cp -a /etc/sysconfig/network-scripts "$BACKUP_DIR/" 2>/dev/null nmcli connection show > "$BACKUP_DIR/nmcli-connection.txt" ip address > "$BACKUP_DIR/ip-address.txt" ip route > "$BACKUP_DIR/ip-route.txt" </syntaxhighlight> === 4.2 본딩 모드 종류 === {| class="wikitable" |- ! 모드 ! 이름 ! 동작 방식 ! 스위치 설정 ! 권장 용도 |- | mode=0 | balance-rr | 패킷을 순차적으로 각 인터페이스에 전송 | 정적 포트 채널 필요 | 특수 부하 분산 |- | mode=1 | active-backup | 하나의 링크만 사용하고 장애 시 예비 링크로 전환 | 일반적으로 불필요 | 서버 이중화 |- | mode=2 | balance-xor | MAC 기반으로 송신 인터페이스 선택 | 정적 포트 채널 필요 | 고정 방식 부하 분산 |- | mode=3 | broadcast | 모든 링크로 동일 패킷 전송 | 환경에 따라 필요 | 특수 고가용성 |- | mode=4 | 802.3ad | LACP 기반 부하 분산 | LACP 포트 채널 필수 | 대역폭 확장 및 이중화 |- | mode=5 | balance-tlb | 송신 부하 분산 | 일반적으로 불필요 | 제한된 스위치 환경 |- | mode=6 | balance-alb | 송수신 부하 분산 | 일반적으로 불필요 | 제한된 스위치 환경 |} 일반적인 서버에서는 active-backup 또는 802.3ad를 주로 사용한다. === 4.3 구성 예시 === {| class="wikitable" |- ! 항목 ! 설정값 |- | 첫 번째 인터페이스 | ens192 |- | 두 번째 인터페이스 | ens224 |- | 본딩 인터페이스 | bond0 |- | 본딩 모드 | active-backup |- | IP 주소 | 192.168.10.20/24 |- | 기본 게이트웨이 | 192.168.10.1 |- | DNS 서버 | 192.168.10.1, 8.8.8.8 |- | 우선 인터페이스 | ens192 |} 확인: <syntaxhighlight lang="bash"> ip -br link nmcli device status nmcli connection show </syntaxhighlight> === 4.4 active-backup 본딩 생성 === <syntaxhighlight lang="bash"> nmcli connection add \ type bond \ con-name bond0 \ ifname bond0 \ bond.options "mode=active-backup,miimon=100,primary=ens192" </syntaxhighlight> 첫 번째 포트 추가: <syntaxhighlight lang="bash"> nmcli connection add \ type ethernet \ con-name bond0-port1 \ ifname ens192 \ master bond0 \ slave-type bond </syntaxhighlight> 두 번째 포트 추가: <syntaxhighlight lang="bash"> nmcli connection add \ type ethernet \ con-name bond0-port2 \ ifname ens224 \ master bond0 \ slave-type bond </syntaxhighlight> === 4.5 bond0 고정 IP 설정 === <syntaxhighlight lang="bash"> nmcli connection modify bond0 \ ipv4.method manual \ ipv4.addresses 192.168.10.20/24 \ ipv4.gateway 192.168.10.1 \ ipv4.dns "192.168.10.1 8.8.8.8" \ ipv6.method disabled \ connection.autoconnect yes nmcli connection modify bond0-port1 connection.autoconnect yes nmcli connection modify bond0-port2 connection.autoconnect yes </syntaxhighlight> 지원되는 경우: <syntaxhighlight lang="bash"> nmcli connection modify bond0 connection.autoconnect-ports 1 </syntaxhighlight> 구형 속성명만 지원하는 경우: <syntaxhighlight lang="bash"> nmcli connection modify bond0 connection.autoconnect-slaves 1 </syntaxhighlight> === 4.6 본딩 활성화 === <syntaxhighlight lang="bash"> nmcli connection up bond0-port1 nmcli connection up bond0-port2 nmcli connection up bond0 </syntaxhighlight> === 4.7 DHCP 본딩 설정 === <syntaxhighlight lang="bash"> nmcli connection modify bond0 \ ipv4.method auto \ ipv4.addresses "" \ ipv4.gateway "" \ ipv4.dns "" nmcli connection up bond0 </syntaxhighlight> === 4.8 802.3ad LACP 본딩 설정 === 스위치에서 LACP 포트 채널 구성이 먼저 완료되어 있어야 한다. <syntaxhighlight lang="bash"> nmcli connection add \ type bond \ con-name bond0 \ ifname bond0 \ bond.options "mode=802.3ad,miimon=100,lacp_rate=fast,xmit_hash_policy=layer3+4" </syntaxhighlight> 포트 추가: <syntaxhighlight lang="bash"> nmcli connection add \ type ethernet \ con-name bond0-port1 \ ifname ens192 \ master bond0 \ slave-type bond nmcli connection add \ type ethernet \ con-name bond0-port2 \ ifname ens224 \ master bond0 \ slave-type bond </syntaxhighlight> IP 설정: <syntaxhighlight lang="bash"> nmcli connection modify bond0 \ ipv4.method manual \ ipv4.addresses 192.168.10.20/24 \ ipv4.gateway 192.168.10.1 \ ipv4.dns "192.168.10.1 8.8.8.8" \ connection.autoconnect yes </syntaxhighlight> 활성화: <syntaxhighlight lang="bash"> nmcli connection up bond0-port1 nmcli connection up bond0-port2 nmcli connection up bond0 </syntaxhighlight> 단일 TCP 세션 하나의 속도가 물리 링크 합산 속도로 증가하는 방식은 아니다. === 4.9 본딩 상태 확인 === <syntaxhighlight lang="bash"> nmcli device status nmcli connection show ip -br address show bond0 cat /proc/net/bonding/bond0 </syntaxhighlight> 주요 확인 항목: {| class="wikitable" |- ! 항목 ! 확인 내용 |- | Bonding Mode | 설정한 본딩 모드 |- | Currently Active Slave | 현재 활성 인터페이스 |- | MII Status | 물리 링크 up/down 상태 |- | Slave Interface | 본딩 포함 인터페이스 |- | Link Failure Count | 링크 장애 횟수 |- | Aggregator ID | LACP 링크가 같은 Aggregator인지 확인 |} === 4.10 active-backup 절체 테스트 === <syntaxhighlight lang="bash"> grep "Currently Active Slave" /proc/net/bonding/bond0 ping 192.168.10.1 </syntaxhighlight> 다른 콘솔에서 활성 인터페이스를 내린다. <syntaxhighlight lang="bash"> ip link set ens192 down </syntaxhighlight> 절체 확인: <syntaxhighlight lang="bash"> grep "Currently Active Slave" /proc/net/bonding/bond0 </syntaxhighlight> 복구: <syntaxhighlight lang="bash"> ip link set ens192 up nmcli device status cat /proc/net/bonding/bond0 </syntaxhighlight> === 4.11 물리 링크 확인 === <syntaxhighlight lang="bash"> ethtool ens192 | grep -E 'Speed|Duplex|Link detected' ethtool ens224 | grep -E 'Speed|Duplex|Link detected' </syntaxhighlight> == 5. 구형 ifcfg 파일 형식 적용 == 일부 구형 콜서버, PBX, CTI 또는 제조사 애플리케이션은 다음 경로의 설정 파일을 직접 확인하는 경우가 있다. <syntaxhighlight lang="text"> /etc/sysconfig/network-scripts/ifcfg-bond0 /etc/sysconfig/network-scripts/ifcfg-ens192 /etc/sysconfig/network-scripts/ifcfg-ens224 </syntaxhighlight> Rocky Linux 9에서는 ifcfg 파일을 사용하더라도 실제 네트워크 제어는 NetworkManager가 수행한다. NetworkManager를 비활성화하고 구형 network 서비스를 활성화하는 방식은 사용하지 않는다. === 5.1 현재 프로파일 저장 위치 확인 === <syntaxhighlight lang="bash"> nmcli -f NAME,UUID,TYPE,DEVICE,FILENAME connection show </syntaxhighlight> === 5.2 ifcfg-rh 플러그인 확인 === <syntaxhighlight lang="bash"> NetworkManager --version nmcli --version find /usr/lib64/NetworkManager /usr/lib/NetworkManager \ -type f -iname '*ifcfg*' 2>/dev/null rpm -qa | grep -E '^NetworkManager|ifcfg' nmcli connection help | grep -A5 migrate </syntaxhighlight> === 5.3 keyfile을 ifcfg 형식으로 변환 === 변환 전 백업: <syntaxhighlight lang="bash"> BACKUP_DIR="/root/network-profile-backup-$(date +%Y%m%d_%H%M%S)" mkdir -p "$BACKUP_DIR" cp -a /etc/NetworkManager/system-connections "$BACKUP_DIR/" cp -a /etc/sysconfig/network-scripts "$BACKUP_DIR/" 2>/dev/null </syntaxhighlight> 변환: <syntaxhighlight lang="bash"> nmcli connection migrate --plugin ifcfg-rh id bond0 nmcli connection migrate --plugin ifcfg-rh id bond0-port1 nmcli connection migrate --plugin ifcfg-rh id bond0-port2 </syntaxhighlight> 결과 확인: <syntaxhighlight lang="bash"> nmcli -f NAME,TYPE,DEVICE,FILENAME connection show ls -l /etc/sysconfig/network-scripts/ifcfg-* </syntaxhighlight> === 5.4 실제 인터페이스명 파일이 필요한 경우 === 일부 프로그램은 다음 파일명을 요구할 수 있다. <syntaxhighlight lang="text"> ifcfg-ens192 ifcfg-ens224 </syntaxhighlight> 프로파일 이름 변경: <syntaxhighlight lang="bash"> nmcli connection modify bond0-port1 connection.id ens192 nmcli connection modify bond0-port2 connection.id ens224 </syntaxhighlight> 다시 변환: <syntaxhighlight lang="bash"> nmcli connection migrate --plugin ifcfg-rh id ens192 nmcli connection migrate --plugin ifcfg-rh id ens224 </syntaxhighlight> 확인: <syntaxhighlight lang="bash"> nmcli -f NAME,DEVICE,FILENAME connection show ls -l /etc/sysconfig/network-scripts/ifcfg-* </syntaxhighlight> === 5.5 ifcfg-bond0 예시 === <syntaxhighlight lang="ini"> TYPE=Bond BONDING_MASTER=yes NAME=bond0 DEVICE=bond0 ONBOOT=yes BOOTPROTO=none IPADDR=192.168.10.20 PREFIX=24 GATEWAY=192.168.10.1 DNS1=192.168.10.1 DNS2=8.8.8.8 BONDING_OPTS="mode=active-backup miimon=100 primary=ens192" IPV6INIT=no </syntaxhighlight> === 5.6 ifcfg-ens192 예시 === <syntaxhighlight lang="ini"> TYPE=Ethernet NAME=ens192 DEVICE=ens192 ONBOOT=yes BOOTPROTO=none MASTER=bond0 SLAVE=yes </syntaxhighlight> === 5.7 ifcfg-ens224 예시 === <syntaxhighlight lang="ini"> TYPE=Ethernet NAME=ens224 DEVICE=ens224 ONBOOT=yes BOOTPROTO=none MASTER=bond0 SLAVE=yes </syntaxhighlight> === 5.8 ifcfg 파일 직접 작성 === 기존 설정 백업: <syntaxhighlight lang="bash"> cp -a /etc/sysconfig/network-scripts \ /root/network-scripts-backup-$(date +%Y%m%d_%H%M%S) </syntaxhighlight> 파일 작성 후 권한 설정: <syntaxhighlight lang="bash"> chmod 600 /etc/sysconfig/network-scripts/ifcfg-bond0 chmod 600 /etc/sysconfig/network-scripts/ifcfg-ens192 chmod 600 /etc/sysconfig/network-scripts/ifcfg-ens224 nmcli connection reload nmcli -f NAME,DEVICE,TYPE,FILENAME connection show </syntaxhighlight> 동일 장치의 keyfile과 ifcfg 파일이 함께 존재하면 중복 프로파일이 생성될 수 있다. === 5.9 중복 프로파일 확인 === <syntaxhighlight lang="bash"> nmcli -f NAME,UUID,DEVICE,TYPE,FILENAME connection show </syntaxhighlight> 사용하지 않는 프로파일 삭제: <syntaxhighlight lang="bash"> nmcli connection delete 사용하지_않는_프로파일명 nmcli connection reload </syntaxhighlight> === 5.10 keyfile 형식으로 복원 === <syntaxhighlight lang="bash"> cp -a /etc/sysconfig/network-scripts \ /root/ifcfg-backup-$(date +%Y%m%d_%H%M%S) nmcli connection migrate --plugin keyfile id bond0 nmcli connection migrate --plugin keyfile id ens192 nmcli connection migrate --plugin keyfile id ens224 nmcli -f NAME,DEVICE,TYPE,FILENAME connection show nmcli connection reload </syntaxhighlight> == 6. 호스트 이름 설정 == === 6.1 현재 호스트 이름 확인 === <syntaxhighlight lang="bash"> hostname hostnamectl </syntaxhighlight> === 6.2 호스트 이름 변경 === <syntaxhighlight lang="bash"> hostnamectl set-hostname rocky-file01 </syntaxhighlight> FQDN 형식: <syntaxhighlight lang="bash"> hostnamectl set-hostname rocky-file01.example.local </syntaxhighlight> 확인: <syntaxhighlight lang="bash"> hostnamectl hostname </syntaxhighlight> === 6.3 /etc/hosts 등록 === 백업: <syntaxhighlight lang="bash"> cp -a /etc/hosts /etc/hosts.bak.$(date +%Y%m%d_%H%M%S) </syntaxhighlight> 편집: <syntaxhighlight lang="bash"> vi /etc/hosts </syntaxhighlight> 예시: <syntaxhighlight lang="text"> 127.0.0.1 localhost localhost.localdomain ::1 localhost localhost.localdomain 192.168.10.20 rocky-file01.example.local rocky-file01 </syntaxhighlight> 확인: <syntaxhighlight lang="bash"> getent hosts rocky-file01 </syntaxhighlight> == 7. SSH 기본 설정 == === 7.1 SSH 서버 설치 확인 === <syntaxhighlight lang="bash"> rpm -q openssh-server </syntaxhighlight> 미설치 시: <syntaxhighlight lang="bash"> dnf install -y openssh-server </syntaxhighlight> === 7.2 SSH 서비스 시작 === <syntaxhighlight lang="bash"> systemctl enable --now sshd systemctl status sshd systemctl is-active sshd systemctl is-enabled sshd </syntaxhighlight> === 7.3 설정 파일 백업 === <syntaxhighlight lang="bash"> cp -a /etc/ssh/sshd_config \ /etc/ssh/sshd_config.bak.$(date +%Y%m%d_%H%M%S) </syntaxhighlight> 추가 설정 파일 생성: <syntaxhighlight lang="bash"> vi /etc/ssh/sshd_config.d/10-custom.conf </syntaxhighlight> === 7.4 기본 보안 설정 예시 === <syntaxhighlight lang="apache"> PermitRootLogin no MaxAuthTries 5 LoginGraceTime 60 X11Forwarding no </syntaxhighlight> 문법 검사: <syntaxhighlight lang="bash"> sshd -t </syntaxhighlight> 설정 적용: <syntaxhighlight lang="bash"> systemctl reload sshd </syntaxhighlight> 기존 SSH 세션을 닫기 전에 새 터미널에서 접속 성공 여부를 확인한다. == 8. SSH 접속 계정 제한 == === 8.1 관리 계정 생성 === <syntaxhighlight lang="bash"> useradd admin passwd admin usermod -aG wheel admin id admin </syntaxhighlight> === 8.2 특정 계정만 접속 허용 === <syntaxhighlight lang="bash"> vi /etc/ssh/sshd_config.d/10-custom.conf </syntaxhighlight> 설정: <syntaxhighlight lang="apache"> AllowUsers admin </syntaxhighlight> 여러 계정: <syntaxhighlight lang="apache"> AllowUsers admin operator backupuser </syntaxhighlight> 그룹 기준: <syntaxhighlight lang="apache"> AllowGroups wheel </syntaxhighlight> 문법 검사 및 적용: <syntaxhighlight lang="bash"> sshd -t systemctl reload sshd </syntaxhighlight> == 9. SSH 포트 변경 == 예시로 SSH 포트를 2222번으로 변경한다. === 9.1 SSH 설정 변경 === <syntaxhighlight lang="bash"> vi /etc/ssh/sshd_config.d/10-custom.conf </syntaxhighlight> <syntaxhighlight lang="apache"> Port 2222 </syntaxhighlight> 문법 검사: <syntaxhighlight lang="bash"> sshd -t </syntaxhighlight> === 9.2 SELinux 포트 등록 === <syntaxhighlight lang="bash"> dnf install -y policycoreutils-python-utils semanage port -l | grep ssh semanage port -a -t ssh_port_t -p tcp 2222 </syntaxhighlight> 이미 등록된 포트라면: <syntaxhighlight lang="bash"> semanage port -m -t ssh_port_t -p tcp 2222 </syntaxhighlight> === 9.3 firewalld 포트 허용 === <syntaxhighlight lang="bash"> firewall-cmd --permanent --add-port=2222/tcp firewall-cmd --reload firewall-cmd --list-ports </syntaxhighlight> === 9.4 SSH 재시작 및 확인 === <syntaxhighlight lang="bash"> systemctl restart sshd systemctl status sshd ss -lntp | grep 2222 </syntaxhighlight> 새 포트 접속 테스트: <syntaxhighlight lang="bash"> ssh -p 2222 admin@192.168.10.20 </syntaxhighlight> 정상 접속 후 기존 22번 허용 제거: <syntaxhighlight lang="bash"> firewall-cmd --permanent --remove-service=ssh firewall-cmd --reload </syntaxhighlight> == 10. firewalld 기본 사용법 == === 10.1 상태 확인 === <syntaxhighlight lang="bash"> systemctl status firewalld systemctl is-active firewalld systemctl is-enabled firewalld </syntaxhighlight> 시작: <syntaxhighlight lang="bash"> systemctl enable --now firewalld </syntaxhighlight> === 10.2 존 및 설정 확인 === <syntaxhighlight lang="bash"> firewall-cmd --get-active-zones firewall-cmd --get-default-zone firewall-cmd --list-all </syntaxhighlight> === 10.3 서비스 허용 === <syntaxhighlight lang="bash"> firewall-cmd --permanent --add-service=ssh firewall-cmd --permanent --add-service=http firewall-cmd --permanent --add-service=https firewall-cmd --permanent --add-service=samba firewall-cmd --reload </syntaxhighlight> === 10.4 포트 번호 허용 === <syntaxhighlight lang="bash"> firewall-cmd --permanent --add-port=8080/tcp firewall-cmd --permanent --add-port=514/tcp firewall-cmd --permanent --add-port=514/udp firewall-cmd --reload </syntaxhighlight> === 10.5 허용 설정 제거 === <syntaxhighlight lang="bash"> firewall-cmd --permanent --remove-port=8080/tcp firewall-cmd --permanent --remove-service=http firewall-cmd --reload </syntaxhighlight> === 10.6 특정 IP 대역만 SSH 허용 === <syntaxhighlight lang="bash"> firewall-cmd --permanent \ --add-rich-rule='rule family="ipv4" source address="192.168.10.0/24" port port="22" protocol="tcp" accept' firewall-cmd --permanent --remove-service=ssh firewall-cmd --reload firewall-cmd --list-rich-rules </syntaxhighlight> == 11. firewalld 비활성화 및 iptables 전환 == Rocky Linux 9에서는 firewalld 사용을 우선 권장한다. 기존 운영 환경이 iptables 규칙으로 표준화된 경우에만 전환을 고려한다. === 11.1 기존 방화벽 규칙 백업 === <syntaxhighlight lang="bash"> firewall-cmd --list-all-zones > /root/firewalld-backup-$(date +%Y%m%d_%H%M%S).txt nft list ruleset > /root/nftables-backup-$(date +%Y%m%d_%H%M%S).txt </syntaxhighlight> === 11.2 iptables 서비스 설치 === <syntaxhighlight lang="bash"> dnf install -y iptables-services rpm -q iptables-services </syntaxhighlight> === 11.3 firewalld 비활성화 === <syntaxhighlight lang="bash"> systemctl disable --now firewalld systemctl is-active firewalld systemctl is-enabled firewalld </syntaxhighlight> === 11.4 iptables 기본 규칙 작성 === <syntaxhighlight lang="bash"> vi /etc/sysconfig/iptables </syntaxhighlight> 예시: <syntaxhighlight lang="text"> *filter :INPUT DROP [0:0] :FORWARD DROP [0:0] :OUTPUT ACCEPT [0:0] -A INPUT -i lo -j ACCEPT -A INPUT -m conntrack --ctstate ESTABLISHED,RELATED -j ACCEPT -A INPUT -p icmp -j ACCEPT -A INPUT -p tcp --dport 22 -j ACCEPT -A INPUT -p udp --dport 137 -j ACCEPT -A INPUT -p udp --dport 138 -j ACCEPT -A INPUT -p tcp --dport 139 -j ACCEPT -A INPUT -p tcp --dport 445 -j ACCEPT -A INPUT -m conntrack --ctstate INVALID -j DROP COMMIT </syntaxhighlight> SSH 포트를 2222번으로 변경했다면 다음과 같이 수정한다. <syntaxhighlight lang="text"> -A INPUT -p tcp --dport 2222 -j ACCEPT </syntaxhighlight> === 11.5 iptables 서비스 시작 === <syntaxhighlight lang="bash"> systemctl enable --now iptables systemctl status iptables iptables -L -n -v --line-numbers service iptables save </syntaxhighlight> 또는: <syntaxhighlight lang="bash"> iptables-save > /etc/sysconfig/iptables </syntaxhighlight> == 12. 서비스 정상 유무 확인 == === 12.1 systemctl 확인 === <syntaxhighlight lang="bash"> systemctl status sshd systemctl status smb systemctl status nmb systemctl is-active sshd systemctl is-active smb systemctl is-enabled sshd systemctl is-enabled smb </syntaxhighlight> === 12.2 실패한 서비스 확인 === <syntaxhighlight lang="bash"> systemctl --failed journalctl -u sshd -n 50 --no-pager journalctl -u smb -n 50 --no-pager </syntaxhighlight> === 12.3 설정 문법 검사 === <syntaxhighlight lang="bash"> sshd -t testparm </syntaxhighlight> == 13. 서비스 포트 리스닝 확인 == <syntaxhighlight lang="bash"> ss -lntup ss -lntp ss -lnup ss -lntp | grep ':22' ss -lntp | grep ':2222' ss -lntup | grep -E ':137|:138|:139|:445' </syntaxhighlight> 확인 항목: {| class="wikitable" |- ! 항목 ! 설명 |- | LISTEN | 연결 대기 상태 |- | 0.0.0.0:22 | 모든 IPv4 인터페이스에서 수신 |- | [::]:22 | 모든 IPv6 인터페이스에서 수신 |- | 127.0.0.1 | 로컬 서버에서만 접근 가능 |- | users | 해당 포트를 사용하는 프로세스 |} == 14. 외부에서 포트 오픈 여부 확인 == === 14.1 Linux에서 nc 사용 === <syntaxhighlight lang="bash"> dnf install -y nmap-ncat nc -zv 192.168.10.20 22 nc -zv 192.168.10.20 2222 nc -zv 192.168.10.20 445 </syntaxhighlight> === 14.2 Windows PowerShell에서 확인 === <syntaxhighlight lang="powershell"> Test-NetConnection 192.168.10.20 -Port 22 Test-NetConnection 192.168.10.20 -Port 2222 Test-NetConnection 192.168.10.20 -Port 445 </syntaxhighlight> == 15. SSH 접속 테스트 == 기본 포트: <syntaxhighlight lang="bash"> ssh admin@192.168.10.20 </syntaxhighlight> 변경 포트: <syntaxhighlight lang="bash"> ssh -p 2222 admin@192.168.10.20 </syntaxhighlight> SSH 장애 확인 순서: # 서버 IP 통신 확인 # SSH 서비스 상태 확인 # SSH 설정 문법 확인 # SSH 포트 리스닝 확인 # 방화벽 규칙 확인 # SELinux 포트 등록 확인 # SSH 로그 확인 <syntaxhighlight lang="bash"> ping -c 4 192.168.10.20 systemctl status sshd sshd -t ss -lntp | grep sshd firewall-cmd --list-all semanage port -l | grep ssh journalctl -u sshd -n 100 --no-pager </syntaxhighlight> == 16. SFTP 접속 테스트 == SFTP는 SSH 서비스를 사용하며 별도 FTP 서버가 필요하지 않다. 기본 포트: <syntaxhighlight lang="bash"> sftp admin@192.168.10.20 </syntaxhighlight> 변경 포트: <syntaxhighlight lang="bash"> sftp -P 2222 admin@192.168.10.20 </syntaxhighlight> 주요 명령: {| class="wikitable" |- ! 명령어 ! 설명 |- | pwd | 서버 현재 디렉터리 |- | lpwd | 로컬 현재 디렉터리 |- | ls | 서버 파일 목록 |- | lls | 로컬 파일 목록 |- | get 파일명 | 파일 다운로드 |- | put 파일명 | 파일 업로드 |- | exit | 종료 |} FileZilla 설정: {| class="wikitable" |- ! 항목 ! 설정값 |- | 프로토콜 | SFTP - SSH File Transfer Protocol |- | 호스트 | 192.168.10.20 |- | 포트 | 22 또는 변경한 SSH 포트 |- | 사용자 | admin |- | 비밀번호 | 해당 계정 비밀번호 |} == 17. Samba 파일 공유 설정 == === 17.1 Samba 설치 === <syntaxhighlight lang="bash"> dnf install -y samba samba-client rpm -q samba rpm -q samba-client </syntaxhighlight> === 17.2 공유 계정 생성 === <syntaxhighlight lang="bash"> useradd -m shareuser passwd shareuser smbpasswd -a shareuser smbpasswd -e shareuser pdbedit -L </syntaxhighlight> === 17.3 공유 디렉터리 생성 === <syntaxhighlight lang="bash"> mkdir -p /data/share chown -R shareuser:shareuser /data/share chmod 2770 /data/share ls -ld /data/share </syntaxhighlight> === 17.4 Samba 설정 백업 === <syntaxhighlight lang="bash"> cp -a /etc/samba/smb.conf \ /etc/samba/smb.conf.bak.$(date +%Y%m%d_%H%M%S) </syntaxhighlight> === 17.5 Samba 설정 === <syntaxhighlight lang="bash"> vi /etc/samba/smb.conf </syntaxhighlight> <syntaxhighlight lang="ini"> [global] workgroup = WORKGROUP security = user map to guest = never server min protocol = SMB2 server role = standalone server [share] comment = Shared Folder path = /data/share browseable = yes writable = yes read only = no valid users = shareuser create mask = 0660 directory mask = 0770 </syntaxhighlight> 문법 검사: <syntaxhighlight lang="bash"> testparm </syntaxhighlight> === 17.6 SELinux 설정 === <syntaxhighlight lang="bash"> dnf install -y policycoreutils-python-utils semanage fcontext -a -t samba_share_t "/data/share(/.*)?" restorecon -Rv /data/share ls -ldZ /data/share </syntaxhighlight> === 17.7 Samba 서비스 시작 === <syntaxhighlight lang="bash"> systemctl enable --now smb systemctl enable --now nmb systemctl status smb systemctl status nmb </syntaxhighlight> 최신 Windows 환경에서 IP 주소 또는 DNS 이름으로 직접 접근하는 경우 smb 서비스만으로도 동작할 수 있다. === 17.8 방화벽 허용 === <syntaxhighlight lang="bash"> firewall-cmd --permanent --add-service=samba firewall-cmd --reload firewall-cmd --list-services </syntaxhighlight> === 17.9 Samba 포트 확인 === <syntaxhighlight lang="bash"> ss -lntup | grep -E ':137|:138|:139|:445' </syntaxhighlight> {| class="wikitable" |- ! 포트 ! 프로토콜 ! 용도 |- | 137 | UDP | NetBIOS 이름 서비스 |- | 138 | UDP | NetBIOS 데이터그램 |- | 139 | TCP | NetBIOS 세션 서비스 |- | 445 | TCP | SMB 직접 통신 |} === 17.10 서버 내부 테스트 === <syntaxhighlight lang="bash"> smbclient -L localhost -U shareuser smbclient //localhost/share -U shareuser </syntaxhighlight> === 17.11 Windows에서 접속 === <syntaxhighlight lang="text"> \\192.168.10.20\share </syntaxhighlight> 호스트 이름으로 접근: <syntaxhighlight lang="text"> \\rocky-file01\share </syntaxhighlight> Windows 자격 증명 초기화: <syntaxhighlight lang="batch"> net use * /delete /y </syntaxhighlight> 네트워크 드라이브 연결: <syntaxhighlight lang="batch"> net use Z: \\192.168.10.20\share /user:shareuser </syntaxhighlight> === 17.12 Samba 장애 확인 순서 === # 서버 IP 통신 확인 # smb 서비스 상태 확인 # TCP 445 포트 리스닝 확인 # 방화벽 허용 확인 # Samba 설정 문법 확인 # Samba 계정 확인 # Linux 디렉터리 권한 확인 # SELinux 컨텍스트 확인 # Samba 로그 확인 <syntaxhighlight lang="bash"> ping -c 4 192.168.10.20 systemctl status smb ss -lntp | grep ':445' firewall-cmd --list-all testparm pdbedit -L ls -ld /data/share ls -ldZ /data/share journalctl -u smb -n 100 --no-pager ausearch -m AVC -ts recent </syntaxhighlight> == 18. 전체 설정 최종 점검 == === 18.1 시스템 정보 === <syntaxhighlight lang="bash"> cat /etc/os-release hostnamectl timedatectl </syntaxhighlight> === 18.2 네트워크 === <syntaxhighlight lang="bash"> ip -br address ip route nmcli device status nmcli connection show ping -c 4 192.168.10.1 </syntaxhighlight> 본딩 사용 시: <syntaxhighlight lang="bash"> cat /proc/net/bonding/bond0 nmcli -f NAME,UUID,DEVICE,TYPE,FILENAME connection show </syntaxhighlight> === 18.3 SSH === <syntaxhighlight lang="bash"> systemctl is-active sshd systemctl is-enabled sshd sshd -t ss -lntp | grep sshd journalctl -u sshd -n 30 --no-pager </syntaxhighlight> === 18.4 방화벽 === firewalld 사용 시: <syntaxhighlight lang="bash"> systemctl is-active firewalld firewall-cmd --get-active-zones firewall-cmd --list-all </syntaxhighlight> iptables 사용 시: <syntaxhighlight lang="bash"> systemctl is-active iptables iptables -L -n -v --line-numbers iptables-save </syntaxhighlight> === 18.5 Samba === <syntaxhighlight lang="bash"> systemctl is-active smb systemctl is-enabled smb testparm pdbedit -L ss -lntup | grep -E ':137|:138|:139|:445' ls -ldZ /data/share </syntaxhighlight> == 19. 구축 완료 후 권장 사항 == === 19.1 root 원격 로그인 차단 === <syntaxhighlight lang="apache"> PermitRootLogin no </syntaxhighlight> === 19.2 관리자 계정 사용 === <syntaxhighlight lang="bash"> usermod -aG wheel admin </syntaxhighlight> === 19.3 불필요한 서비스 비활성화 === <syntaxhighlight lang="bash"> systemctl --type=service --state=running systemctl disable --now 서비스명 </syntaxhighlight> === 19.4 정기 업데이트 === <syntaxhighlight lang="bash"> dnf check-update dnf update -y </syntaxhighlight> === 19.5 시간 동기화 확인 === <syntaxhighlight lang="bash"> timedatectl chronyc tracking chronyc sources -v </syntaxhighlight> 서울 시간대 설정: <syntaxhighlight lang="bash"> timedatectl set-timezone Asia/Seoul </syntaxhighlight> === 19.6 주요 설정 백업 === <syntaxhighlight lang="bash"> tar czvf /root/rocky-basic-config-$(date +%Y%m%d).tar.gz \ /etc/NetworkManager/system-connections \ /etc/sysconfig/network-scripts \ /etc/hosts \ /etc/hostname \ /etc/ssh \ /etc/firewalld \ /etc/sysconfig/iptables \ /etc/samba/smb.conf 2>/dev/null </syntaxhighlight> == 20. 전체 작업 순서 요약 == <syntaxhighlight lang="text"> 1. Rocky Linux 9 설치 2. 설치 후 패키지 업데이트 3. 네트워크 인터페이스 확인 4. 단일 NIC 또는 본딩 구성 5. 고정 IP 및 DNS 설정 6. 필요 시 ifcfg 형식으로 변환 7. 게이트웨이와 외부 통신 확인 8. 호스트 이름 설정 9. 관리자 계정 생성 10. SSH 서비스 확인 11. root 직접 로그인 차단 12. 필요 시 SSH 허용 계정 제한 13. 필요 시 SSH 포트 변경 14. SELinux에 변경 포트 등록 15. 방화벽 포트 허용 16. SSH와 SFTP 접속 테스트 17. Samba 패키지 설치 18. Samba 계정 및 공유 디렉터리 생성 19. Samba 설정 파일 작성 20. SELinux 컨텍스트 설정 21. Samba 방화벽 허용 22. Windows에서 공유 접속 테스트 23. 전체 설정 파일 백업 </syntaxhighlight> == 21. 빠른 점검 명령어 모음 == <syntaxhighlight lang="bash"> # OS 버전 cat /etc/os-release # 호스트 이름 hostnamectl # IP 주소 ip -br address # 라우팅 ip route # NetworkManager nmcli device status nmcli connection show # 본딩 cat /proc/net/bonding/bond0 # SSH 상태 systemctl status sshd # SSH 문법 sshd -t # 포트 리스닝 ss -lntup # firewalld firewall-cmd --list-all # iptables iptables -L -n -v --line-numbers # Samba 문법 testparm # Samba 계정 pdbedit -L # Samba 서비스 systemctl status smb # 실패한 서비스 systemctl --failed # 최근 부팅 오류 journalctl -p err -b --no-pager </syntaxhighlight> == 관련 문서 == * Rocky Linux 9 사용자 및 그룹 관리 * Rocky Linux 9 패키지 관리 * Rocky Linux 9 systemd 서비스 관리 * Rocky Linux 9 firewalld 상세 설정 * Rocky Linux 9 SSH 키 인증 설정 * Rocky Linux 9 SELinux 기본 관리 * Rocky Linux 9 Samba 고급 설정 * Rocky Linux 9 로그 확인 및 장애 분석
Rocky9
문서로 돌아갑니다.
둘러보기 메뉴
개인 도구
로그인
associated-pages
문서
토론
한국어
보기
읽기
원본 보기
역사 보기
더 보기
검색
둘러보기
대문
최근 바뀜
임의 문서로
미디어위키 도움말
특수 문서 목록
도구
여기를 가리키는 문서
가리키는 글의 최근 바뀜
문서 정보