EdgeRouter - 포트포워딩과 목적지 NAT ================================================== download at 2017-09-11T21:06:45Z `origin `_ .. raw:: html
.. raw:: html
 Overview .. raw:: html
.. raw:: html
-------------- 이 문서는 내부 서버의 포트 포워딩과 목적지 NAT를 사용하여 UDP와 TCP 포트에 포트 포워딩 하는 방법에 대하여 서술합니다. |book_25x25.png| **NOTES & REQUIREMENTS:** EdgeOS 1.9.7 펌웨어 이상의 모든 EdgeRouter 모델에서 동작합니다. CLI에 대한 지식과 기본 네트워킹에 대한 지식이 요구됩니다. \ `관련 문서 <#related%20articles>`__ 섹션을 참고하여 더 자세한 내용을 확인하세요. 이 문서에서 사용한 장비: - `EdgeRouter-X (ER-X) `__ - `Ubiquiti Network Management System (UNMS) `__ Table of Contents -------------- #. `네트워크 다이어그램 <#diagram>`__ #. `포트 포워딩 <#policy%20vpn>`__ #. `목적지 NAT <#juniper%20vpn>`__ #. `테스팅 및 검증 <#testing%20verification>`__ #. `관련 문서 <#related%20articles>`__ -------------- 네트워크 다이어그램 -------------- `맨위로 가기 <#top>`__ 네트워크 토폴로지는 아래와 같습니다. 다음은 EdgeRouter에서 사용한 인터페이스입니다: **ER-X** - eth0 (WAN) - 203.0.113.1/29                                       203.0.113.2/29 - eth1 (LAN) - 192.168.1.1/24 |image1| -------------- 포트 포워딩 -------------- `맨위로 가기 <#top>`__ 이 문서에서는 기본 설치 위자드를 통해서 미리 구성된 EdgeRouter (ER)을 사용합니다. 마스커레이드 룰이 적용되어서 LAN의 호스트가 인터넷과 통신이 가능하다고 가정합니다. ER은 TCP 포트 80, 443, 8443을 UNMS 서버 192.168.1.10으로 포워딩하도록 구성합니다. 포트포워딩을 하는 가장 빠른 방법은 GUI의 위자드를 사용하는 방법입니다. 포트 포워딩의 단점은 *WAN 인터페이스의 기본 주소에만 적용이 된다는 점입니다. (203.0.113.1/29)* ER을 예비 주소에도 포워딩 하고자 한다면 NAT를 사용하십시오. |www.png| **GUI STEPS:** 라우터의 웹 관리 포탈(GUI)로 접근합니다. 1. UNMS 서버에 관련 HTTP와 HTTPS 포트를 포워딩하는 룰을 생성합니다. **Firewall/NAT > Port Forwarding** - 상세 옵션 확인하기 - NAT 헤어핀 활성화 - 자동 방화벽 활성화 :: WAN interface: eth0 LAN interface: eth1 |info_i_25x25.png| .. Note:: 단일 LAN 그룹 eth1-4에 switch0 인터페이스를 사용하고 있다면, LAN 인터페이스는 switch0로 설정해야합니다. **+Add Rule 선택** :: Original port: 443 Protocol: TCP Forward-to address: 192.168.1.10 Forward-to port: 443 Description: HTTPS **+Add Rule 선택** :: Original port: 80 Protocol: TCP Forward-to address: 192.168.1.10 Forward-to port: 80 Description: HTTP **+Add Rule 선택** :: Original port: 8443 Protocol: TCP Forward-to address: 192.168.1.10 Forward-to port: 443 Description: HTTPS |info_i_25x25.png| .. Note:: *auto firewall* 기능이 활성화 되어있기 때문에 추가적인 방화벽 룰을 해당 포트에 대하여 추가할 필요가 없습니다. 자신의 상황에 맞는 방화벽 룰을 생성하고 싶다면 목적지 NAT 섹션을 참고하세요. 2. 변경 내역을 적용합니다. |image4| 3. (선택사항) 라우터 웹 관리 수신 포트를 변경합니다. (예제에서는 10080과 10443 포트) **Config Tree > Service > GUI** :: http-port: 10080 https-port: 10443 **Preview > Apply** |info_i_25x25.png| .. Note:: CLI에서 **sudo netstat -anp** 명령어를 사용하여 현재 라우터에서 수신 대기 중인 모든 포트를 확인할 수 있습니다. (포트를 사용중인 프로세스도 확인 가능합니다) |CLI_circle.png| **(대안) CLI 설정:** 커맨드라인 인터페이스에 접근합니다. GUI의 CLI 버튼이나 PuTTY 와 같은 프로그램을 사용합니다. 1. 환경설정 모드로 진입합니다. :: configure 2. UNMS서버에 HTTP와 HTTPS 관련 포트 포워딩 룰을 생성합니다. :: set port-forward auto-firewall enable set port-forward hairpin-nat enable set port-forward wan-interface eth0 set port-forward lan-interface eth1 set port-forward rule 1 description HTTPS set port-forward rule 1 forward-to address 192.168.1.10 set port-forward rule 1 forward-to port 443 set port-forward rule 1 original-port 443 set port-forward rule 1 protocol tcp set port-forward rule 2 description HTTP set port-forward rule 2 forward-to address 192.168.1.10 set port-forward rule 2 forward-to port 80 set port-forward rule 2 original-port 80 set port-forward rule 2 protocol tcp set port-forward rule 3 description HTTPS set port-forward rule 3 forward-to address 192.168.1.10 set port-forward rule 3 forward-to port 443 set port-forward rule 3 original-port 8443 set port-forward rule 3 protocol tcp 3. (선택사항) 라우터 웹 관리 수신 포트를 변경합니다. (예제에서는 10080과 10443 포트) :: set service gui http-port 10080 set service gui https-port 10443 4. 변경 내역을 커밋하고 저장합니다. :: commit ; save 5. (선택사항) 자동 방화벽과 NAT 제외 기능을 확인합니다. 자동 기능은 다음의 룰을 iptables에에 추가합니다: - TCP 포트 80, 443의 인바운드 방향을 허용합니다. - TCP 80, 443, 8443으로 eth0 주소(ADDRv4\_eth0)를 통해서 192.168.1.10으로 접근해오는 트래픽 다음을 통해서 검증이 가능합니다: :: sudo iptables -L -vn Chain UBNT_PFOR_FW_HOOK (1 references) pkts bytes target prot opt in out source destination 33642 3777K UBNT_PFOR_FW_RULES all -- eth0 * 0.0.0.0/0 0.0.0.0/0 Chain UBNT_PFOR_FW_RULES (1 references) pkts bytes target prot opt in out source destination 0 0 ACCEPT tcp -- * * 0.0.0.0/0 192.168.1.10 tcp dpt:443 0 0 ACCEPT tcp -- * * 0.0.0.0/0 192.168.1.10 tcp dpt:80 0 0 ACCEPT tcp -- * * 0.0.0.0/0 192.168.1.10 tcp dpt:443 sudo iptables -t nat -L -vn Chain POSTROUTING (policy ACCEPT 23847 packets, 7267K bytes) pkts bytes target prot opt in out source destination 59437 14M UBNT_PFOR_SNAT_HOOK all -- * * 0.0.0.0/0 0.0.0.0/0 20314 1793K MASQUERADE all -- * eth0 0.0.0.0/0 0.0.0.0/0 /* NAT-5010 */ Chain UBNT_PFOR_DNAT_HOOK (1 references) pkts bytes target prot opt in out source destination 0 0 UBNT_PFOR_DNAT_RULES all -- eth0 * 0.0.0.0/0 0.0.0.0/0 match-set ADDRv4_eth0 dst 0 0 UBNT_PFOR_DNAT_RULES all -- eth1 * 0.0.0.0/0 0.0.0.0/0 match-set ADDRv4_eth0 dst Chain UBNT_PFOR_DNAT_RULES (2 references) pkts bytes target prot opt in out source destination 0 0 DNAT tcp -- * * 0.0.0.0/0 0.0.0.0/0 tcp dpt:443 to:192.168.1.10:443 0 0 DNAT tcp -- * * 0.0.0.0/0 0.0.0.0/0 tcp dpt:80 to:192.168.1.10:80 0 0 DNAT tcp -- * * 0.0.0.0/0 0.0.0.0/0 tcp dpt:8443 to:192.168.1.10:443 Chain UBNT_PFOR_SNAT_RULES (1 references) pkts bytes target prot opt in out source destination 0 0 MASQUERADE tcp -- * eth1 0.0.0.0/0 192.168.1.10 match-set NETv4_eth1 src tcp dpt:443 0 0 MASQUERADE tcp -- * eth1 0.0.0.0/0 192.168.1.10 match-set NETv4_eth1 src tcp dpt:80 0 0 MASQUERADE tcp -- * eth1 0.0.0.0/0 192.168.1.10 match-set NETv4_eth1 src tcp dpt:443 -------------- 목적지 NAT -------------- `맨위로 가기 <#top>`__ 포트 포워딩 룰은 첫번째 섹션에서는 WAN 인터페이스의 메인 주소에만 적용이 가능합니다. 203.0.113.2/29로 향하는 입력 트래픽은 포워딩이 필요합니다. 그러므로 목적지 NAT를 사용하여 요구사항을 충족할 수 있습니다. 포트 포워딩과 달리 목적지 NAT 기능은 방화벽 룰 자동 생성을 지원하지 않습니다. |www.png| **GUI STEPS:** 라우터 웹 관리 포탈 (GUI)에 접속합니다.   1. WAN 인터페이스에 보조 IP 주소를 추가합니다. **Dashboard > eth0 interface > Actions > Config > +Add IP** :: 203.0.113.2/29 |image6|   |info_i_25x25.png| .. Note:: 포워딩에 사용하는 모든 IP 주소는 WAN 인터페이스에 보조 IP 주소를 추가해야합니다. 2. HTTP와 HTTPS 포트 포워딩을 위한 룰을 UNMS 서버에 추가합니다. **Firewall/NAT > NAT > +Add Destination NAT Rule** :: Description: HTTPS Inbound Interface: eth0 Translations Address: 192.168.1.10 Translations Port: 443 Protocol: TCP Dest Address: 203.0.113.2 Dest Port: 443 **Firewall/NAT > NAT > +Add Destination NAT Rule** :: Description: HTTP Inbound Interface: eth0 Translations Address: 192.168.1.10 Translations Port: 80 Protocol: TCP Dest Address: 203.0.113.2 Dest Port: 80 **Firewall/NAT > NAT > +Add Destination NAT Rule** :: Description: HTTPS Inbound Interface: eth0 Translations Address: 192.168.1.10 Translations Port: 443 Protocol: TCP Dest Address: 203.0.113.2 Dest Port: 8443 |image7|   3. UNMS 서버에 트래픽이 접근 가능하도록 HTTP, HTTPS 방화벽 룰을 생성합니다. **Firewall/NAT > Firewall Policies > WAN\_IN > Actions > Edit Ruleset** |info_i_25x25.png| .. Note:: 인바운드 방화벽 룰은 상황에 맞게 수정해야합니다. 네이밍 규칙이 무엇이든지, 올바른 방화벽 룰을 WAN 인터페이스에 적용해야 합니다. **Firewall/NAT > Firewall Policies > [rule-name] > Actions > Interfaces** 를 통해서 직접 설정할 수있습니다. **+Add New Rule** :: Description: HTTPS Action: Accept Protocol: TCP Destination Port: 443 **+Add New Rule** :: Description: HTTP Action: Accept Protocol: TCP Destination Port: 80 |info_i_25x25.png| .. Note:: 목적지 NAT 세팅에서 ‘Translations’ 아래에 있는 포트만 허용하면 됩니다. 즉, 서버에서 변환되는 포트만 변환하면 됩니다. 그러므로 TCP 포트 8443을 허용하는 룰은 필요하지 않으며, HTTPS 룰도 필요하지 않습니다. |image8| .. raw:: html
.. raw:: html
  .. raw:: html
.. raw:: html
|image9| |CLI_circle.png| **(대안) CLI 설정:** 커맨드라인 인터페이스에 접근합니다. GUI의 CLI 버튼이나 PuTTY 와 같은 프로그램을 사용합니다. 1. 환경설정 모드로 진입합니다. :: configure 2. WAN 인터페이스에 보조 IP 주소를 추가합니다. :: set interfaces ethernet eth0 address 203.0.113.2/29 3. UNMS 서버에 HTTP와 HTTPS 관련 포트를 포워딩하도록 룰을 추가합니다. :: set service nat rule 1 description HTTPS set service nat rule 1 destination address 203.0.113.2 set service nat rule 1 destination port 443 set service nat rule 1 inbound-interface eth0 set service nat rule 1 inside-address address 192.168.1.10 set service nat rule 1 inside-address port 443 set service nat rule 1 log disable set service nat rule 1 protocol tcp set service nat rule 1 type destination set service nat rule 2 description HTTP set service nat rule 2 destination address 203.0.113.2 set service nat rule 2 destination port 80 set service nat rule 2 inbound-interface eth0 set service nat rule 2 inside-address address 192.168.1.10 set service nat rule 2 inside-address port 80 set service nat rule 2 log disable set service nat rule 2 protocol tcp set service nat rule 2 type destination set service nat rule 3 description HTTPS set service nat rule 3 destination address 203.0.113.2 set service nat rule 3 destination port 8443 set service nat rule 3 inbound-interface eth0 set service nat rule 3 inside-address address 192.168.1.10 set service nat rule 3 inside-address port 443 set service nat rule 3 log disable set service nat rule 3 protocol tcp set service nat rule 3 type destination 4. UNMS 서버에 HTTP와 HTTPS 트래픽을 접근 허용하도록 방화벽 룰을 생성합니다. :: set firewall name WAN_IN rule 21 action accept set firewall name WAN_IN rule 21 description HTTPS set firewall name WAN_IN rule 21 destination port 443 set firewall name WAN_IN rule 21 log disable set firewall name WAN_IN rule 21 protocol tcp set firewall name WAN_IN rule 22 action accept set firewall name WAN_IN rule 22 description HTTP set firewall name WAN_IN rule 22 destination port 80 set firewall name WAN_IN rule 22 log disable set firewall name WAN_IN rule 22 protocol tcp 5. 변경 내역을 커밋하고 저장합니다. :: commit ; save -------------- 테스팅 및 검증 -------------- `맨위로 가기 <#top>`__ 포트 포워딩, 목적지 NAT 룰의 환경설정을 완료하였다면 다음 명령어를 통해서 검증 할 수 있습니다. 1. 포트 포워딩 룰의 상태 검증하기: |image10| .. raw:: html
.. raw:: html
2. 목적지 NAT 룰의 카운터 검증: .. raw:: html
.. raw:: html
  .. raw:: html
.. raw:: html
|image11| 3. 포트포워딩 변환 / 목적지 NAT 룰 검증: :: show nat translations destination detail Pre-NAT src Pre-NAT dst Post-NAT src Post-NAT dst 192.0.2.1:1547 203.0.113.2:80 192.0.2.1:1547 192.168.1.10:80 tcp: dnat: 203.0.113.2 ==> 192.168.1.10 timeout: 48 use: 1 192.0.2.1:1566 203.0.113.2:8443 192.0.2.1:1566 192.168.1.10:443 tcp: dnat: 203.0.113.2:8443 ==> 192.168.1.10:443 timeout: 117 use: 1 192.0.2.1:1594 203.0.113.2:443 192.0.2.1:1594 192.168.1.10:443 tcp: dnat: 203.0.113.2 ==> 192.168.1.10 timeout: 104 use: 1 4. ER의 외부 WAN 인터페이스에서 HTTP, HTTPS로 도착하는 패킷 캡처: :: sudo tcpdump -i eth0 -n tcp dst port 80 or port 443 or port 8443 IP 192.0.2.1.1672 > 203.0.113.2.80: Flags [.], ack 339, win 255, length 0 IP 192.0.2.1.1641 > 203.0.113.2.443: Flags [.], ack 8356, win 255, length 0 IP 203.0.113.2.443 > 192.0.2.1.1642: Flags [F.], seq 999, ack 959, win 245, length IP 192.0.2.1.1667 > 203.0.113.2.8443: Flags [.], ack 868, win 253, length 0 IP 203.0.113.2.8443 > 192.0.2.1.1662: Flags [F.], seq 29493, ack 1416, win 254, length 0 |info_i_25x25.png| .. Note:: 실시간 캡처의 결과입니다. 아무런 결과를 얻을 수 없다면 클라이언트가 패킷을 생성하지 않거나 업스트림 트래픽이 차단당했을 수도 있습니다. 5. 목적지 NAT를 사용할 때 방화벽에 접근하였는지 검증합니다: :: show firewall name WAN_IN statistics IPv4 Firewall "WAN_IN" [WAN to internal] Active on (eth0,IN) rule packets bytes action description ---- ------- ----- ------ ----------- 10 95 9427 ACCEPT Allow established/related 20 0 0 DROP Drop invalid state 21 17 884 ACCEPT HTTPS 22 2 104 ACCEPT HTTP 10000 6 336 DROP DEFAULT ACTION -------------- 관련 문서 -------------- `맨위로 가기 <#top>`__ - `네트워킹 개론 - SSH를 사용하여 커넥션을 생성하는 방법 `__ .. raw:: html
.. raw:: html
.. |book_25x25.png| image:: /hc/article_attachments/115018511588/book_25x25.png .. |image1| image:: /hc/article_attachments/115020953307/mceclip0.png .. |www.png| image:: /hc/article_attachments/115018779668/www.png .. |info_i_25x25.png| image:: /hc/article_attachments/115018681307/info_i_25x25.png .. |image4| image:: /hc/article_attachments/115020954567/mceclip1.png .. |CLI_circle.png| image:: /hc/article_attachments/115018681247/CLI_circle.png .. |image6| image:: /hc/article_attachments/115020955947/mceclip2.png .. |image7| image:: /hc/article_attachments/115020956827/mceclip3.png .. |image8| image:: /hc/article_attachments/115020956927/mceclip4.png .. |image9| image:: /hc/article_attachments/115021018608/mceclip6.png .. |image10| image:: /hc/article_attachments/115020957407/mceclip8.png .. |image11| image:: /hc/article_attachments/115021018968/mceclip9.png