OpenWrt의 서버를 WAN에 노출해야 합니까, 아니면 WAN에서 포트 전달을 사용하여 LAN에만 노출해야 합니까?

OpenWrt의 서버를 WAN에 노출해야 합니까, 아니면 WAN에서 포트 전달을 사용하여 LAN에만 노출해야 합니까?

라우터 뒤의 컴퓨터에 서버를 설치하고 인터넷에서 서버 연결을 허용하려면 두 가지 작업을 수행해야 합니다. 첫째, 서버 시스템에서 방화벽을 열어 들어오는 연결을 허용합니다. 둘째, 연결이 WAN에서 LAN(특히 서버 시스템)으로 이동할 수 있도록 라우터에 포트 전달 규칙을 설정합니다.

하지만 문제의 서버 시스템이 OpenWrt에서 실행되는 라우터 자체인 경우 어떻게 해야 합니까?

두 가지 옵션을 생각할 수 있습니다.

옵션 A. 라우터를 LAN의 다른 컴퓨터처럼 취급하십시오. 라우터에 서버를 설치한 후 방화벽을 열어 LAN 내에서 서버로 들어오는 연결을 허용하세요. (LuCI > 네트워크 > 방화벽 > 트래픽 규칙에서 수행되는 것으로 생각됩니다.) 그런 다음 WAN에서 LAN(특히 서버)으로의 포트 전달 규칙을 설정합니다. (LuCI > 네트워크 > 방화벽 > 포트 전달.)

옵션 B. LuCI의 트래픽 규칙 탭을 사용하여 WAN에서 서버로 직접 연결하기 위한 방화벽을 엽니다.

질문은 다음과 같습니다

  1. 이것이 내가 고려할 수 있는 두 가지 옵션이라고 생각하는 것이 옳습니까?

  2. 양측의 장단점은 무엇입니까?

  3. 표준 관행은 무엇입니까?

문제의 서버는 VPN 서버(예: Wireguard) 또는 OpenSSH일 수 있으며 Dropbear 대신 설치할 수 있습니다. 그러나 OpenWrt에 A/V 스트림 서버를 설치한 경우에도 동일한 질문이 발생할 수 있습니다(가능하다고 가정). 즉, 나는 이 질문이 특정 소프트웨어(Wireguard 등)에 국한되지 않고 위의 두 가지 옵션에 대한 일반적인 질문으로 남아 있기를 바랍니다.

저는 OpenWrt와 Linux를 처음 사용합니다. 저는 불과 며칠 전까지만 해도 OpenWrt가 존재하는지 몰랐습니다. 옵션 A가 이상할 수도 있고(아무도 하지 않는 일) 이전에 OpenWrt와 같은 것을 본 적이 없고 "일반 라우터" 용어로만 생각할 수 있기 때문에 내 두뇌가 그것을 생각했을 수도 있습니다.

사실, 옵션 A가 이러한 이점을 가질 수 있다고 생각하게 됩니다. 사실 이전에 포트 포워딩을 해본 적이 있지만 Linux 방화벽은 처음입니다. 그래서 교통 규칙을 정리할 수도 있고, 문제가 LAN에서만 발생하는 것이 더 나을 것입니다.

조언해주세요. 감사해요.

부록

옵션 A(왼쪽)와 B(오른쪽)를 보여주는 LuCI 스크린샷입니다. 왼쪽 패널에서는 포트 12000이 LAN에 열려 있다고 가정합니다(기본 정책 또는 특정 트래픽 규칙에 따라). 192.168.1.1. 라우터의 LAN IP 주소입니다.

여기에 이미지 설명을 입력하세요

답변1

(일부 브라우저에서는 명확하지 않지만 각 파일 경로는 링크입니다.)

SSH의 경우 표준 관행은 다음을 지정하는 것입니다.DNAT내부 네트워크에 [포트 전달] 규칙을 적용합니다. VPN 서버의 경우 서버 포트에 대한 WAN 액세스를 허용하는 규칙을 만듭니다.

  • 와이어가드 위키
  • SSH:
    • /etc/config/firewall:
      #
      
          ##::[[---  OpenWrt WAN Firewall Config  ---]]::##
      
      #===========================================================
                    ##----- NAT Redirects -----##
      #===========================================================
      
      # SSH #
      #-----------------------------------------------------------
      config redirect
          option  target          'DNAT'
          option  proto           'tcp'
          option  src             'wan'
          option  src_dport       60501
          option  dest            'lan'
          option  dest_ip         192.168.1.1
          option  dest_port       22
          option  name            'Allow Redirect WAN → LAN (SSH)'
      
      config redirect
          option  target          'DNAT'
          option  proto           'tcp'
          option  src             'vpn'
          option  src_dport       60502
          option  dest            'lan'
          option  dest_ip         192.168.1.1
          option  dest_port       22
          option  name            'Allow Redirect Wireguard → LAN (SSH)'
      
      #===========================================================
                        ##----- VPN Zones -----##
      #===========================================================
      
      # Wireguard #
      #-----------------------------------------------------------
      config zone
          option  name            'vpn'
          option  network         'vpn'
          option  input           'ACCEPT'
          option  forward         'ACCEPT'
          option  output          'ACCEPT'
          option  log             1
      
      # Rules:
      #-----------------------------------------------------------
      config rule
          option  target          'ACCEPT'
          option  proto           'tcp udp'
          option  src             'wan'
          option  dest            '*'
          option  dest_port       51820
          option  name            'Allow Forwarded Wireguard → Router'
      
      config rule
          option  target          'ACCEPT'
          option  proto           'tcp'
          option  src             'vpn'
          option  dest            '*'
          option  dest_port       60502
          option  name            'Allow Wireguard → Router (SSH)'
      

    • /etc/config/dropbear:
      #
      
            ##::[[---  OpenWrt DropBear Config  ---]]::##
      
      #===========================================================
                       ##----- Default -----##
      #===========================================================
      
      # Server #
      #-----------------------------------------------------------
      config dropbear
          option  enable            1
          option  Interface         'lan'
          option  PasswordAuth      'off'
          option  RootPasswordAuth  'off'
          option  IdleTimeout       0
          option  Port              22
          option  RootLogin         1
          option  SSHKeepAlive      300
          option  verbose           1
      

    • /etc/ssh/sshd_config: (맞춤형)
      #
      
          ##::[[---  OpenWrt OpenSSH SSHd Config  ---]]::##
      
      #===========================================================
                    ##----- Global Options -----##
      #===========================================================
      
        # Please verify, as all algorithms may not supported:
      
          # Ciphers:                  # HostKey & KeyTypes
            ## ssh -Q cipher            ## ssh -Q key
      
          # Kex [Key Exchange]        # MAC [Message Authentication Code]
            ## ssh -Q kex               ## ssh -Q mac
      
      
      # Connection #
      #-----------------------------------------------------------
      AddressFamily                     = inet
      ListenAddress                     = 192.168.1.1:22
      
      
      # Encryption #
      #-----------------------------------------------------------
      AuthorizedKeysFile                = /root/.ssh/authorized_keys
      
      HostKey                           = /etc/ssh/ssh_host_ed25519_key
      HostKey                           = /etc/ssh/ssh_host_rsa_key
      
      
      # Authentication #
      #-----------------------------------------------------------
      AllowUsers                        = root
      AllowGroups                       = root
      
      ChallengeResponseAuthentication   = no
      PasswordAuthentication            = no
      PermitEmptyPasswords              = no
      
      StrictModes                       = yes
      PubkeyAuthentication              = yes
      
      LoginGraceTime                    = 30
      
      MaxAuthTries                      = 3
      MaxSessions                       = 10
      MaxStartups                       = 3:30:10
      
      PermitRootLogin                   = prohibit-password
      
      
      # Reliability #
      #-----------------------------------------------------------
      ClientAliveCountMax               = 3
      ClientAliveInterval               = 600
      
      TCPKeepAlive                      = yes
      
      UseDNS                            = yes
      
      
      # Security #
      #-----------------------------------------------------------
      AllowAgentForwarding              = yes
      AllowTcpForwarding                = yes
      
      GatewayPorts                      = clientspecified
      PermitTunnel                      = yes
      
      Subsystem   sftp                  = /usr/lib/sftp-server
      
      RekeyLimit                        = 500M 60m
      
      
      # Logging #
      #-----------------------------------------------------------
      SyslogFacility                    = AUTH
      LogLevel                          = VERBOSE
      
      PidFile                           = /tmp/run/sshd.pid
      
      
      # Ciphers and ReKeying #
      #-----------------------------------------------------------
      FingerprintHash                   = sha256
      
      Ciphers                           = [email protected],[email protected],aes128-ctr,aes128-cbc,aes192-ctr,aes192-cbc,aes256-ctr,aes256-cbc,[email protected]
      
      HostKeyAlgorithms                 = ssh-ed25519,ssh-rsa,ecdsa-sha2-nistp256,ecdsa-sha2-nistp384,ecdsa-sha2-nistp521
      
      HostbasedAcceptedKeyTypes         = ssh-ed25519,ssh-rsa,ecdsa-sha2-nistp256,ecdsa-sha2-nistp384,ecdsa-sha2-nistp521
      
      KexAlgorithms                     = [email protected],curve25519-sha256,ecdh-sha2-nistp256,ecdh-sha2-nistp384,ecdh-sha2-nistp521,diffie-hellman-group-exchange-sha256
      
      MACs                              = [email protected],[email protected],hmac-sha2-256,hmac-sha2-512
      
      PubkeyAcceptedKeyTypes            = ssh-ed25519,ssh-rsa,ecdsa-sha2-nistp256,ecdsa-sha2-nistp384,ecdsa-sha2-nistp521
      

  • 루시:
    1. https://<router IP>회로망 (왼쪽 메뉴)방화벽
    2. 교통 규칙
      1. 추가하다:
        이름: Allow Forwarded Wireguard → Router
        규약: TCP UDP
        소스 영역: wan
        대상 지역: Any zone (forward)
        대상 포트: 51820
        행동: accept
        구하다
      2. 추가하다:
        이름: Allow Wireguard → Router (SSH)
        규약: TCP
        소스 영역: vpn
        대상 지역: Any zone (forward)
        대상 포트: 60502
        행동: accept
        구하다

    3. 포트 포워딩
      1. 추가하다:
        이름: Allow Redirect WAN → LAN (SSH)
        규약: TCP
        소스 영역: wan
        외부 포트: 60501
        대상 지역: lan
        내부 IP 주소: 192.168.1.1
        내부 포트: 22
        행동: accept
        구하다
      2. 추가하다:
        이름: Allow Redirect VPN → LAN (SSH)
        규약: TCP
        소스 영역: vpn
        외부 포트: 60502
        대상 지역: lan
        내부 IP 주소: 192.168.1.1
        내부 포트: 22
        행동: accept
        구하다

    4. 저장 및 적용

관련 정보