Initial commit: Server documentation

- XDP Firewall setup guide
- Network performance tuning guide

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
kaffa
2026-01-15 17:00:54 +09:00
commit 76b5d0c26f
3 changed files with 318 additions and 0 deletions

23
README.md Normal file
View File

@@ -0,0 +1,23 @@
# Server Documentation
npm-linode-1 서버 설정 문서
## 문서 목록
| 문서 | 설명 |
|------|------|
| [xdp-firewall-setup.md](./xdp-firewall-setup.md) | XDP 기반 DDoS 방어 설정 |
| [network-tuning.md](./network-tuning.md) | 커널 네트워크 성능 튜닝 |
## 서버 정보
- **호스트명**: npm-linode-1
- **위치**: Linode
- **용도**: Nginx Proxy Manager, Reverse Proxy
## 방어 구조
```
인터넷 → Cloudflare (250 req/10s) → Linode DDoS (~40Gbps) → XDP (250 Pps)
L7 Rate Limit 업스트림 필터링 L3/L4 필터
```

117
network-tuning.md Normal file
View File

@@ -0,0 +1,117 @@
# 네트워크 성능 튜닝
이 서버의 커널 네트워크 최적화 설정 문서
## 설정 파일
`/etc/sysctl.d/99-network-performance.conf`
## 적용된 설정
### 소켓 버퍼 크기
| 항목 | 값 | 설명 |
|------|-----|------|
| `net.core.rmem_max` | 16MB | 최대 수신 버퍼 |
| `net.core.wmem_max` | 16MB | 최대 송신 버퍼 |
| `net.core.rmem_default` | 1MB | 기본 수신 버퍼 |
| `net.core.wmem_default` | 1MB | 기본 송신 버퍼 |
| `net.core.optmem_max` | 64KB | 옵션 메모리 |
### TCP 버퍼 (min, default, max)
| 항목 | 값 | 설명 |
|------|-----|------|
| `net.ipv4.tcp_rmem` | 4KB / 1MB / 16MB | TCP 수신 버퍼 |
| `net.ipv4.tcp_wmem` | 4KB / 1MB / 16MB | TCP 송신 버퍼 |
### 백로그 설정
| 항목 | 값 | 설명 |
|------|-----|------|
| `net.core.netdev_max_backlog` | 65,535 | 네트워크 장치 큐 크기 |
| `net.ipv4.tcp_max_syn_backlog` | 65,535 | SYN 큐 크기 |
### 연결 관리
| 항목 | 값 | 설명 |
|------|-----|------|
| `net.ipv4.tcp_fin_timeout` | 10초 | FIN-WAIT-2 타임아웃 |
| `net.ipv4.tcp_keepalive_time` | 600초 | Keepalive 시작 시간 |
| `net.ipv4.tcp_keepalive_intvl` | 30초 | Keepalive 간격 |
| `net.ipv4.tcp_keepalive_probes` | 5 | Keepalive 재시도 횟수 |
| `net.ipv4.ip_local_port_range` | 1024-65535 | 로컬 포트 범위 |
### 성능 최적화
| 항목 | 값 | 설명 |
|------|-----|------|
| `net.ipv4.tcp_fastopen` | 3 | TCP Fast Open 양방향 |
| `net.core.default_qdisc` | fq | Fair Queue 스케줄러 |
| `net.ipv4.tcp_congestion_control` | bbr | BBR 혼잡 제어 |
## 명령어
### 현재 설정 확인
```bash
# 전체 네트워크 설정
/sbin/sysctl -a | grep -E "net.core|net.ipv4.tcp"
# 특정 설정 확인
/sbin/sysctl net.ipv4.tcp_congestion_control
/sbin/sysctl net.core.rmem_max
```
### 설정 재적용
```bash
sudo /sbin/sysctl -p /etc/sysctl.d/99-network-performance.conf
```
### 설정 수정
```bash
# 파일 수정
sudo nano /etc/sysctl.d/99-network-performance.conf
# 적용
sudo /sbin/sysctl -p /etc/sysctl.d/99-network-performance.conf
```
## BBR 혼잡 제어
BBR (Bottleneck Bandwidth and Round-trip propagation time)은 Google이 개발한 TCP 혼잡 제어 알고리즘입니다.
### 장점
- 높은 처리량
- 낮은 지연 시간
- 패킷 로스에 강함
- 버퍼블로트 방지
### 확인
```bash
# 현재 사용 중인 알고리즘
/sbin/sysctl net.ipv4.tcp_congestion_control
# 사용 가능한 알고리즘
/sbin/sysctl net.ipv4.tcp_available_congestion_control
```
## 효과
| 항목 | 개선 |
|------|------|
| 동시 연결 | 더 많은 연결 처리 가능 |
| 대용량 전송 | 버퍼 증가로 속도 향상 |
| SYN Flood | 큰 백로그로 저항력 증가 |
| 지연 시간 | BBR로 latency 감소 |
| 연결 정리 | 빠른 타임아웃으로 리소스 회수 |
## 관련 문서
- [XDP Firewall 설정](./xdp-firewall-setup.md)
- [Linux Network Tuning Guide](https://www.kernel.org/doc/Documentation/networking/ip-sysctl.txt)
- [BBR Congestion Control](https://cloud.google.com/blog/products/networking/tcp-bbr-congestion-control-comes-to-gcp-your-internet-just-got-faster)

178
xdp-firewall-setup.md Normal file
View File

@@ -0,0 +1,178 @@
# XDP Firewall 설정
이 서버의 XDP 기반 DDoS 방어 설정 문서
## 개요
- **도구**: [XDP-Firewall](https://github.com/gamemann/XDP-Firewall)
- **설치 위치**: `/home/admin/XDP-Firewall`
- **설정 파일**: `/etc/xdpfw/xdpfw.conf`
- **모드**: DRV/native (고성능)
## 방어 구조
```
인터넷 → Cloudflare (250 req/10s) → Linode DDoS (~40Gbps) → XDP (250 Pps)
L7 Rate Limit 업스트림 필터링 L3/L4 필터
```
## 현재 설정
### 컴파일 옵션 (`src/common/config.h`)
| 항목 | 값 | 설명 |
|------|-----|------|
| MAX_BLOCK | 2,000,000 | 최대 차단 IP 수 |
| MAX_RL_IP | 2,000,000 | IP Rate Limit 맵 크기 |
| MAX_RL_FLOW | 2,000,000 | Flow Rate Limit 맵 크기 |
| ENABLE_RL_IP | 활성화 | IP 기반 Rate Limit |
| ENABLE_RL_FLOW | 활성화 | Flow 기반 Rate Limit |
### 필터 규칙 (26개)
| 순서 | 대상 | 동작 |
|------|------|------|
| 1-2 | Tailscale (100.64.0.0/10, fd7a:115c:a1e0::/48) | 허용 |
| 3-17 | Cloudflare IPv4 (15개 대역) | 허용 |
| 18-24 | Cloudflare IPv6 (7개 대역) | 허용 |
| 25 | 250 Pps 초과 | 60초 차단 |
| 26 | 나머지 | 허용 |
### Rate Limit 설정
- **임계값**: 250 Pps per IP
- **차단 시간**: 60초
- **근거**: [XDP DDoS Protection 레퍼런스](https://www.srodi.com/posts/ddos-mitication-with-ebpf-xdp/)에서 250 Pps 권장, 여유 있게 250으로 설정
## 명령어
### 서비스 관리
```bash
# 상태 확인
sudo systemctl status xdpfw.service
# 재시작
sudo systemctl restart xdpfw.service
# 로그 확인
sudo tail -f /var/log/xdpfw.log
# 필터 목록 보기
sudo xdpfw -l
```
### 패킷 통계 확인
```bash
# 실시간 통계
sudo bpftool map dump name map_stats
# 차단된 IP 확인
sudo bpftool map dump name map_block
```
### 동적 규칙 추가/삭제
```bash
# 특정 IP 차단 (60초)
sudo xdpfw-add -m 2 -d 1.2.3.4 -e 60
# 특정 IP 차단 해제
sudo xdpfw-del -m 2 -d 1.2.3.4
# Rate Limit 규칙 추가
sudo xdpfw-add -m 0 --pps 1000 --action 0 --block-time 30
```
## 화이트리스트
### Tailscale
- IPv4: `100.64.0.0/10`
- IPv6: `fd7a:115c:a1e0::/48`
### Cloudflare IPv4
```
173.245.48.0/20
103.21.244.0/22
103.22.200.0/22
103.31.4.0/22
141.101.64.0/18
108.162.192.0/18
190.93.240.0/20
188.114.96.0/20
197.234.240.0/22
198.41.128.0/17
162.158.0.0/15
104.16.0.0/13
104.24.0.0/14
172.64.0.0/13
131.0.72.0/22
```
### Cloudflare IPv6
```
2400:cb00::/32
2606:4700::/32
2803:f800::/32
2405:b500::/32
2405:8100::/32
2a06:98c0::/29
2c0f:f248::/32
```
## 성능
| 항목 | 수치 |
|------|------|
| XDP 처리 능력 | 2-5M Pps |
| 최대 차단 IP | 2,000,000개 |
| 메모리 사용 | ~1GB (BPF 맵) |
| CPU 사용 | 최소 (커널 바이패스) |
## 방어 능력
| 시나리오 | 방어 가능 IP 수 |
|----------|-----------------|
| 250 Pps/IP 공격 | ~10,000개 |
| 1,000 Pps/IP 공격 | ~5,000개 |
| 5,000 Pps/IP 공격 | ~1,000개 |
## 재컴파일 방법
설정 변경 후 재컴파일 필요:
```bash
cd /home/admin/XDP-Firewall
# 설정 수정
nano src/common/config.h
# 재컴파일
sudo systemctl stop xdpfw.service
make clean && make
sudo make install
sudo systemctl start xdpfw.service
```
## Cloudflare IP 업데이트
Cloudflare IP가 변경되면 설정 업데이트 필요:
```bash
# 최신 IP 확인
curl https://www.cloudflare.com/ips-v4/
curl https://www.cloudflare.com/ips-v6/
# 설정 수정
sudo nano /etc/xdpfw/xdpfw.conf
# 적용
sudo systemctl restart xdpfw.service
```
## 참고 자료
- [XDP-Firewall GitHub](https://github.com/gamemann/XDP-Firewall)
- [Cloudflare L4Drop](https://blog.cloudflare.com/l4drop-xdp-ebpf-based-ddos-mitigations/)
- [Red Hat XDP Filter Guide](https://docs.redhat.com/en/documentation/red_hat_enterprise_linux/9/html/configuring_firewalls_and_packet_filters/using-xdp-filter-for-high-performance-traffic-filtering-to-prevent-ddos-attacks_firewall-packet-filters)