Difference between revisions of "Firewall VPN"

Line 23: Line 23:
 
IP_LAN_VPN="172.16.60.0/24"
 
IP_LAN_VPN="172.16.60.0/24"
  
echo -e " "
+
echo " "
echo -e "------------------------"
+
echo "------------------------"
echo -e " VPN configuration"
+
echo " VPN configuration"
echo -e "------------------------"
+
echo "------------------------"
echo -e "    # VPN interface  : $INT_VPN"
+
echo "    # VPN interface  : $INT_VPN"
echo -e "    # VPN port      : $VPN_PORT"
+
echo "    # VPN port      : $VPN_PORT"
echo -e "    # VPN protocol  : $VPN_PROTOCOL"
+
echo "    # VPN protocol  : $VPN_PROTOCOL"
echo -e "    -------------------------------------- "
+
echo "    -------------------------------------- "
  
echo -e "      ... Allow VPN connections through $INT_VPN"
+
echo "      ... Allow VPN connections through $INT_VPN"
 
$IPTABLES -A INPUT -p $VPN_PROTOCOL --dport $VPN_PORT -j ACCEPT
 
$IPTABLES -A INPUT -p $VPN_PROTOCOL --dport $VPN_PORT -j ACCEPT
 
$IPTABLES -A OUTPUT -p $VPN_PROTOCOL --dport $VPN_PORT -j ACCEPT
 
$IPTABLES -A OUTPUT -p $VPN_PROTOCOL --dport $VPN_PORT -j ACCEPT
Line 38: Line 38:
 
$IPTABLES -A OUTPUT -p $VPN_PROTOCOL --sport $VPN_PORT -j ACCEPT
 
$IPTABLES -A OUTPUT -p $VPN_PROTOCOL --sport $VPN_PORT -j ACCEPT
 
 
echo -e "    ... Allow VPN packets type INPUT,OUTPUT,FORWARD"
+
echo "    ... Allow VPN packets type INPUT,OUTPUT,FORWARD"
 
$IPTABLES -A INPUT -i $INT_VPN -m state ! --state INVALID -j ACCEPT
 
$IPTABLES -A INPUT -i $INT_VPN -m state ! --state INVALID -j ACCEPT
 
$IPTABLES -A OUTPUT -o $INT_VPN -m state ! --state INVALID -j ACCEPT
 
$IPTABLES -A OUTPUT -o $INT_VPN -m state ! --state INVALID -j ACCEPT
Line 44: Line 44:
  
 
# Allow forwarding
 
# Allow forwarding
echo -e "      ... Allow packets to by forward from|to the VPN"
+
echo "      ... Allow packets to by forward from|to the VPN"
 
$IPTABLES -A FORWARD -i $INT_VPN -o $INT_ETH -j ACCEPT
 
$IPTABLES -A FORWARD -i $INT_VPN -o $INT_ETH -j ACCEPT
 
$IPTABLES -A FORWARD -i $INT_ETH -o $INT_VPN -j ACCEPT
 
$IPTABLES -A FORWARD -i $INT_ETH -o $INT_VPN -j ACCEPT
  
  
echo -e "    -------------------------------------- "
+
echo "    -------------------------------------- "
echo -e "      Open VPN LAN(s)
+
echo "      Open VPN LAN(s)"
echo -e "    -------------------------------------- "
+
echo "    -------------------------------------- "
echo -e "      # VPN network IP @  : $IP_LAN_VPN"
+
echo "      # VPN network IP @  : $IP_LAN_VPN"
  
 
# Allow packets to be send from|to the VPN network
 
# Allow packets to be send from|to the VPN network

Revision as of 10:59, 7 February 2015


What is a VPN?

See What is a VPN?


VPN firewall

Adjust the following to your own port, network ID and protocol:

IPTABLES=`which iptables`

INT_ETH=eth0
IP_LAN_ETH=`/sbin/ifconfig $INT_ETH | grep 'inet addr:' | cut -d: -f2 | awk '{ print $1}'`

INT_VPN=tun0
VPN_PORT="8080"
VPN_PROTOCOL="udp"
IP_LAN_VPN="172.16.60.0/24"

echo " "		
echo "------------------------"
echo " VPN configuration"
echo "------------------------"
echo "    # VPN interface  : $INT_VPN"
echo "    # VPN port       : $VPN_PORT"
echo "    # VPN protocol   : $VPN_PROTOCOL"
echo "    -------------------------------------- "

echo "      ... Allow VPN connections through $INT_VPN"
$IPTABLES -A INPUT -p $VPN_PROTOCOL --dport $VPN_PORT -j ACCEPT
$IPTABLES -A OUTPUT -p $VPN_PROTOCOL --dport $VPN_PORT -j ACCEPT
# Hint: if you do not accept all RELATED,ESTABLISHED connections then you must allow the source port
$IPTABLES -A OUTPUT -p $VPN_PROTOCOL --sport $VPN_PORT -j ACCEPT
		
echo "     ... Allow VPN packets type INPUT,OUTPUT,FORWARD"
$IPTABLES -A INPUT -i $INT_VPN -m state ! --state INVALID -j ACCEPT
$IPTABLES -A OUTPUT -o $INT_VPN -m state ! --state INVALID -j ACCEPT
$IPTABLES -A FORWARD -o $INT_VPN -m state ! --state INVALID -j ACCEPT

# Allow forwarding
echo "      ... Allow packets to by forward from|to the VPN"
$IPTABLES -A FORWARD -i $INT_VPN -o $INT_ETH -j ACCEPT
$IPTABLES -A FORWARD -i $INT_ETH -o $INT_VPN -j ACCEPT


echo "    -------------------------------------- "
echo "      Open VPN LAN(s)"
echo "    -------------------------------------- "
echo "      # VPN network IP @  : $IP_LAN_VPN"

# Allow packets to be send from|to the VPN network
$IPTABLES -A FORWARD -s $IP_LAN_VPN -j ACCEPT
$IPTABLES -t nat -A POSTROUTING -s $IP_LAN_VPN -o $INT_ETH -j MASQUERADE

# Allow VPN client <-> client communication
$IPTABLES -A INPUT -s $IP_LAN_VPN -d $IP_LAN_VPN -m state ! --state INVALID -j ACCEPT
$IPTABLES -A OUTPUT -s $IP_LAN_VPN -d $IP_LAN_VPN -m state ! --state INVALID -j ACCEPT


####### Add route(s) to remote network(s)
# You must add a new route for each network you'd like to access through the VPN server!
# The VPN server must be able to reach the remote network! (otherwise it cannot acts as a GW !)
# route add -net <network>/<mask> gw <VPN_SERVER_ETH_IP>
#
# !! This information should be pushed by the server !! 
# If not you can either add it manually over here (= in Iptables) or in the OpenVPN client conf.
#######
#echo "      ... add VPN route between VPN LAN and current location"
#route add -net 192.168.12.0/24 gw 192.168.1.45