OpenVPN을위한 UFW ufw config ufw –force reset #

OpenVPN에 ufw (복잡한 방화벽)를 구성하고 싶습니다.

연결은 OpenVPN을 통해서만 허용됩니다. 다른 모든 것은 차단해야합니다. 따라서 OpenVPN이 연결되어 있지 않으면 인터넷이 없습니다! 이 스크립트를 온라인에서 찾았으며 그것이 충분한 지 알고 싶습니다. 아니면 더 많은 규칙을 추가해야합니까?

#!/bin/bash
###########################################
#          Created by Thomas Butz         #
#   E-Mail: btom1990(at)googlemail.com    #
#  Feel free to copy & share this script  #
###########################################

# Adapt this value to your config!
VPN_DST_PORT=3478

# Don't change anything beyond this point
###########################################

# Check for root priviliges
if [[ $EUID -ne 0 ]]; then
   printf "Please run as root:\nsudo %s\n" "${0}"
   exit 1
fi


# Reset the ufw config
ufw --force reset

# let all incoming traffic pass
ufw default allow incoming
# and block outgoing by default
ufw default deny outgoing

# Every communiction via VPN is considered to be safe
ufw allow out on tun0

# Don't block the creation of the VPN tunnel
ufw allow out $VPN_DST_PORT
# Don't block DNS queries
ufw allow out 53

# Allow local IPv4 connections
ufw allow out to 10.0.0.0/8
ufw allow out to 172.16.0.0/12
ufw allow out to 192.168.0.0/16
# Allow IPv4 local multicasts
ufw allow out to 224.0.0.0/24
ufw allow out to 239.0.0.0/8

# Allow local IPv6 connections
ufw allow out to fe80::/64
# Allow IPv6 link-local multicasts
ufw allow out to ff01::/16
# Allow IPv6 site-local multicasts
ufw allow out to ff02::/16
ufw allow out to ff05::/16

# Enable the firewall
ufw enable

출처 : http://pastebin.com/AUHh6KnV



답변

구성이 더 제한적일 수 있습니다

ufw --force reset

ufw default deny incoming # Use the VPN tunnel for all traffic
ufw default deny outgoing

ufw allow out on tun0
ufw allow in on tun0

ufw allow out $port/$protocol # e.g. 1234/udp, depending on your OpenVPN client config

# Prefer resolved hosts to connect to your VPN, enable only if your VPN provider doesn't give you that option
#ufw allow out 53

# Allow local IPv4 connections, enable as needed, set specific IPs or tighter subnet masks if possible
#ufw allow out to 10.0.0.0/8
#ufw allow out to 172.16.0.0/12
#ufw allow out to 192.168.0.0/16
# Allow IPv4 local multicasts
#ufw allow out to 224.0.0.0/24
#ufw allow out to 239.0.0.0/8
# Allow local IPv6 connections
#ufw allow out to fe80::/64
# Allow IPv6 link-local multicasts
#ufw allow out to ff01::/16
# Allow IPv6 site-local multicasts
#ufw allow out to ff02::/16
#ufw allow out to ff05::/16

# Enable the firewall
ufw enable


답변

다음 두 명령을 사용하지 않는 것이 좋습니다 .

ufw allow incoming
ufw default allow in on tun0

허용하면 방화벽을 갖는 목적을 상실합니다. 리턴 패킷을 수신하려면 “tun0에서 허용”이 필요하지 않습니다. 전 세계가 귀하에게 연결하도록 허용하는 것과 비교하여 요청한 연결 만 수신하려고합니다. 허용하면이 작업이 수행됩니다. 아래 제안 된 구성을 테스트하고 참조하십시오.

다음은 방화벽과 함께 사용하기위한 일련의 UFW 명령의 예입니다.

sudo ufw enable
sudo ufw --force reset
sudo ufw default deny incoming
sudo ufw default deny outgoing
sudo ufw allow out on tun0
sudo ufw allow out on eth0 to any port 53,1197 proto udp
sudo ufw allow out on wlan0 to any port 53,1197 proto udp
sudo ufw status verbose

결과 예 :

Status: active
Logging: on (low)
Default: deny (incoming), deny (outgoing), disabled (routed)
New profiles: skip

To                         Action      From
--                         ------      ----
Anywhere                   ALLOW OUT   Anywhere on tun0
53,1197/udp                ALLOW OUT   Anywhere on eth0
53,1197/udp                ALLOW OUT   Anywhere on wlan0
Anywhere (v6)              ALLOW OUT   Anywhere (v6) on tun0
53,1197/udp (v6)           ALLOW OUT   Anywhere (v6) on eth0
53,1197/udp (v6)           ALLOW OUT   Anywhere (v6) on wlan0

참고 :-인터페이스가 다를 수 있습니다 (예 : 우분투 16.12는 eno1 및 wlp3s0b1 사용). 실제 인터페이스를 보려면 “ifconfig”명령을 사용하십시오. -1197 UDP는 상당히 기본값이지만 VPN (예 : 443 TCP)에 맞게 변경해야 할 수도 있습니다. -나는 보통 ipv6를 삭제합니다 (sudo ufw delete 4, x3 반복)

기능 :-VPN 터널을 통한 아웃 바운드 연결을 허용하면서 이더넷 / wifi의 VPN 터널 및 DNS 연결을 제외한 모든 것을 차단합니다. DNS 문제에 대한 아래의 경고.

경고 :이 예에서는 DNS 요청에 대해 53을 허용하므로 openvpn (예 : vpn.somevpnprovider.com)이 IP 주소를 요청하고 연결할 수 있습니다. 트레이드 오프는 DNS 유출 가능성이 있습니다. dnsleaktest.com을 사용하여 VPN 설정이 DNS 요청을 터널링하는지 확인하십시오. 주의 / 편집증의 경우 53에서 허용을 건너 뛰고 대신 방화벽을 해제하여 연결 한 다음 다시 연결하십시오. 내 VPN 때문에 방화벽을 완전히 잊어 버릴 가능성이 높기 때문에 그렇게하지 않기로 선택합니다 (예 : openvpn이 잘못 구성되면 DNS가 누출 될 수 있습니다).


답변