14장. 대체 경로를 정의하도록 정책 기반 라우팅 구성
기본적으로 RHEL의 커널은 라우팅 테이블을 사용하여 대상 주소를 기반으로 네트워크 패킷을 전달할 위치를 결정합니다. 정책 기반 라우팅을 사용하면 복잡한 라우팅 시나리오를 구성할 수 있습니다. 예를 들어 소스 주소, 패킷 메타데이터 또는 프로토콜과 같은 다양한 기준에 따라 패킷을 라우팅할 수 있습니다.
14.1. nmcli
를 사용하여 특정 서브넷에서 다른 기본 게이트웨이로 트래픽 라우팅
정책 기반 라우팅을 사용하여 특정 서브넷의 트래픽에 대해 다른 기본 게이트웨이를 구성할 수 있습니다. 예를 들어 기본적으로 기본 경로를 사용하여 모든 트래픽을 인터넷 공급자 A로 라우팅하는 라우터로 RHEL을 구성할 수 있습니다. 그러나 내부 워크스테이션 서브넷에서 수신된 트래픽은 공급자 B로 라우팅됩니다.
이 절차에서는 다음 네트워크 토폴로지를 가정합니다.
사전 요구 사항
-
시스템은
NetworkManager
를 사용하여 기본값인 네트워크를 구성합니다. 절차에서 설정하려는 RHEL 라우터에는 다음 네 가지 네트워크 인터페이스가 있습니다.
-
enp7s0
인터페이스는 공급자 A의 네트워크에 연결되어 있습니다. 공급자의 네트워크의 게이트웨이 IP는198.51.100.2
이며 네트워크는/30
네트워크 마스크를 사용합니다. -
enp1s0
인터페이스는 공급자 B의 네트워크에 연결되어 있습니다. 공급자의 네트워크의 게이트웨이 IP는192.0.2.2
이며 네트워크는/30
네트워크 마스크를 사용합니다. -
enp8s0
인터페이스는 내부 워크스테이션이 있는10.0.0.0/24
서브넷에 연결되어 있습니다. -
enp9s0
인터페이스는 회사의 서버가 있는203.0.113.0/24
서브넷에 연결되어 있습니다.
-
-
내부 워크스테이션 서브넷의 호스트는
10.0.0.1
을 기본 게이트웨이로 사용합니다. 이 절차에서는 이 IP 주소를 라우터의enp8s0
네트워크 인터페이스에 할당합니다. -
서버 서브넷의 호스트는
203.0.113.1
을 기본 게이트웨이로 사용합니다. 이 절차에서는 라우터의enp9s0
네트워크 인터페이스에 이 IP 주소를 할당합니다. -
firewalld
서비스가 활성화 및 활성화됩니다.
프로세스
A를 공급자로 네트워크 인터페이스를 구성합니다.
nmcli connection add type ethernet con-name Provider-A ifname enp7s0 ipv4.method manual ipv4.addresses 198.51.100.1/30 ipv4.gateway 198.51.100.2 ipv4.dns 198.51.100.200 connection.zone external
# nmcli connection add type ethernet con-name Provider-A ifname enp7s0 ipv4.method manual ipv4.addresses 198.51.100.1/30 ipv4.gateway 198.51.100.2 ipv4.dns 198.51.100.200 connection.zone external
Copy to Clipboard Copied! nmcli connection add
명령은 NetworkManager 연결 프로필을 생성합니다. 명령은 다음 옵션을 사용합니다.-
type ethernet
: 연결 유형이 이더넷임을 정의합니다. -
con-name <connection_name
> : 프로필 이름을 설정합니다. 혼동을 피하기 위해 의미 있는 이름을 사용하십시오. -
ifname & lt;network_device&
gt; : 네트워크 인터페이스를 설정합니다. -
ipv4.method 수동
: 정적 IP 주소를 구성할 수 있습니다. -
ipv4.addresses < IP_address> / <subnet_mask
> : IPv4 주소와 서브넷 마스크를 설정합니다. -
ipv4.gateway & lt;IP_address&
gt; : 기본 게이트웨이 주소를 설정합니다. -
ipv4.dns <IP_of_DNS_server
> : DNS 서버의 IPv4 주소를 설정합니다. -
connection.zone <firewalld_zone
> : 네트워크 인터페이스를 정의된firewalld
영역에 할당합니다.firewalld
는외부
영역에 할당된 인터페이스에 대해 자동으로 마스커레이딩을 활성화합니다.
-
네트워크 인터페이스를 공급자 B로 구성합니다.
nmcli connection add type ethernet con-name Provider-B ifname enp1s0 ipv4.method manual ipv4.addresses 192.0.2.1/30 ipv4.routes "0.0.0.0/0 192.0.2.2 table=5000" connection.zone external
# nmcli connection add type ethernet con-name Provider-B ifname enp1s0 ipv4.method manual ipv4.addresses 192.0.2.1/30 ipv4.routes "0.0.0.0/0 192.0.2.2 table=5000" connection.zone external
Copy to Clipboard Copied! 이 명령은
ipv4.gateway
대신ipv4.routes
매개변수를 사용하여 기본 게이트웨이를 설정합니다. 이 연결의 기본 게이트웨이를 기본값과 다른 라우팅 테이블(5000
)에 할당해야 합니다. 연결이 활성화되면 NetworkManager가 이 새 라우팅 테이블을 자동으로 생성합니다.네트워크 인터페이스를 내부 워크스테이션 서브넷으로 구성합니다.
nmcli connection add type ethernet con-name Internal-Workstations ifname enp8s0 ipv4.method manual ipv4.addresses 10.0.0.1/24 ipv4.routes "10.0.0.0/24 table=5000" ipv4.routing-rules "priority 5 from 10.0.0.0/24 table 5000" connection.zone trusted
# nmcli connection add type ethernet con-name Internal-Workstations ifname enp8s0 ipv4.method manual ipv4.addresses 10.0.0.1/24 ipv4.routes "10.0.0.0/24 table=5000" ipv4.routing-rules "priority 5 from 10.0.0.0/24 table 5000" connection.zone trusted
Copy to Clipboard Copied! 이 명령은
ipv4.routes
매개변수를 사용하여 ID5000
이 있는 라우팅 테이블에 정적 경로를 추가합니다.10.0.0.0/24
서브넷의 이 정적 경로는 로컬 네트워크 인터페이스의 IP를 사용하여 다음 홉으로 공급자 B(192.0.2.1
)를 제공합니다.또한 명령에서는
ipv4.routing-rules
매개변수를 사용하여10.0.0.0/24
서브넷에서 테이블5000
으로 트래픽을 라우팅하는 우선순위5
가 있는 라우팅 규칙을 추가합니다. 낮은 값은 높은 우선 순위를 갖습니다.ipv4.routing-rules
ip rule add
명령과 동일합니다.네트워크 인터페이스를 서버 서브넷으로 구성합니다.
nmcli connection add type ethernet con-name Servers ifname enp9s0 ipv4.method manual ipv4.addresses 203.0.113.1/24 connection.zone trusted
# nmcli connection add type ethernet con-name Servers ifname enp9s0 ipv4.method manual ipv4.addresses 203.0.113.1/24 connection.zone trusted
Copy to Clipboard Copied!
검증
내부 워크스테이션 서브넷의 RHEL 호스트에서 다음을 수행합니다.
traceroute
패키지를 설치합니다.dnf install traceroute
# dnf install traceroute
Copy to Clipboard Copied! traceroute
유틸리티를 사용하여 인터넷의 호스트에 대한 경로를 표시합니다.traceroute redhat.com
# traceroute redhat.com traceroute to redhat.com (209.132.183.105), 30 hops max, 60 byte packets 1 _gateway (10.0.0.1) 0.337 ms 0.260 ms 0.223 ms 2 192.0.2.2 (192.0.2.2) 0.884 ms 1.066 ms 1.248 ms ...
Copy to Clipboard Copied! 명령의 출력은 라우터가 공급자 B의 네트워크인
192.0.2.1
을 통해 패킷을 보내는 것을 표시합니다.
서버 서브넷의 RHEL 호스트에서 다음을 수행합니다.
traceroute
패키지를 설치합니다.dnf install traceroute
# dnf install traceroute
Copy to Clipboard Copied! traceroute
유틸리티를 사용하여 인터넷의 호스트에 대한 경로를 표시합니다.traceroute redhat.com
# traceroute redhat.com traceroute to redhat.com (209.132.183.105), 30 hops max, 60 byte packets 1 _gateway (203.0.113.1) 2.179 ms 2.073 ms 1.944 ms 2 198.51.100.2 (198.51.100.2) 1.868 ms 1.798 ms 1.549 ms ...
Copy to Clipboard Copied! 명령의 출력은 라우터가 공급자 A의 네트워크인
198.51.100.2
를 통해 패킷을 전송한다는 것을 표시합니다.
문제 해결 단계
RHEL 라우터에서 다음을 수행합니다.
규칙 목록을 표시합니다.
ip rule list
# ip rule list 0: from all lookup local 5: from 10.0.0.0/24 lookup 5000 32766: from all lookup main 32767: from all lookup default
Copy to Clipboard Copied! 기본적으로 RHEL에는
로컬
테이블, 기본 ,기본값
에 대한 규칙이 포함되어 있습니다.표
5000
에 경로를 표시합니다.ip route list table 5000
# ip route list table 5000 default via 192.0.2.2 dev enp1s0 proto static metric 100 10.0.0.0/24 dev enp8s0 proto static scope link src 192.0.2.1 metric 102
Copy to Clipboard Copied! 인터페이스 및 방화벽 영역을 표시합니다.
firewall-cmd --get-active-zones
# firewall-cmd --get-active-zones external interfaces: enp1s0 enp7s0 trusted interfaces: enp8s0 enp9s0
Copy to Clipboard Copied! 외부
영역에 masquerading이 활성화되어 있는지 확인합니다.firewall-cmd --info-zone=external
# firewall-cmd --info-zone=external external (active) target: default icmp-block-inversion: no interfaces: enp1s0 enp7s0 sources: services: ssh ports: protocols: masquerade: yes ...
Copy to Clipboard Copied!