서버로 들어오는 트래픽을 다른 Target에게 라우팅 할 때 설정하는 방법
1. iptable-services 설치
# CentOS, AmazonLinux
yum install iptables-services
# Ubuntu
apt install iptables-persistent
2. NAT Table 설정
# CentOS, AmazonLinux : /etc/sysconfig/iptables
# Ubuntu : /etc/iptables/rules.v4
*nat
-A PREROUTING -i eth0 -p tcp -m tcp --dport 8022 -j DNAT --to-destination 10.0.2.176:22
-A POSTROUTING -j MASQUERADE
COMMIT
- -A PREROUTING : 패킷이 들어오는 즉시 라우팅 처리
- -i eth0 : 패킷을 처리할 인터페이스 지정 (eth0 인터페이스로 들어오는 패킷에 적용)
- -p tcp : 전체 패킷 중에 TCP 프로토콜만 대상으로 지정
- -m tcp --dport 8022 : TCP 관련된 패킷 중 Destination Port가 8022인 경우만 대상으로 지정
- -j DNAT : 패킷의 목적지 IP ADDRESS정보 수정 (Destination NAT)
- --to-destination 10.0.2.176:22 : 패킷의 목적지 IP ADDRESS를 10.0.7.176으로 포트를 22로 변경
- -A POSTROUTING : 패킷이 나가는 과정에 라우팅 처리
- -j MASQUERADE : 패킷의 출발지 IP 정보를 서버의 네트워크 인터페이스 값으로 변경
3. Kernel Parameter 조정
# vim /etc/sysctl.conf
net.ipv4.ip_forward=1
4. iptables 재실행
# CentOS, AmazonLinux
systemctl restart iptables
# Ubuntu
iptables-restore < /etc/iptables/rules.v4 # 메모리에 로드(재부팅시 삭제)
systemctl restart iptables
systemctl restart netfilter-persistent
'Infrastructure & Systems > Linux' 카테고리의 다른 글
[Linux] SSH config 파일 설정 (0) | 2024.11.25 |
---|---|
[Linux] Server Command Logging (0) | 2024.11.23 |
[Linux] Syslog의 Facility와 Priority Level (1) | 2024.11.22 |
[Linux] History Log Timestamp 설정 (0) | 2024.11.20 |
[Linux] systemd (System Daemon) (0) | 2024.11.19 |