LinuxQuestions.org
Help answer threads with 0 replies.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Security
User Name
Password
Linux - Security This forum is for all security related questions.
Questions, tips, system compromises, firewalls, etc. are all included here.

Notices


Reply
  Search this Thread
Old 05-10-2015, 12:45 AM   #1
JosephS
Member
 
Registered: Jun 2007
Distribution: Debian Jessie, Bunsenlabs
Posts: 586

Rep: Reputation: 38
Need help with a vpn firewall


I am using a firewall to keep my computer from connecting when a vpn goes down, to restrict it to go through the vpn service. I can get a connection to the vpn, but lose it after I start the firewall. Can someone tell what is wrong with it. This is a firewall I found in a post, except a couple lines. I start it after I start openvpn:
Code:
sudo openvpn --config /etc/openvpn/vpnbook-ca1-udp53.ovpn --script-securrity 2 --up /etc/openvpn/update-resolv-conf
This is the firewall:
Quote:
# re: how to block internet connection when vpn fails?
# forums.debian.net
# by M51 » 2013-11-02 12:43
#
# Here's my script, modified to allow all incoming traffic on eth0 from the local
# lan. It assumes you have no other iptables rules in place (that is the default
# with Debian, but may not be for other distros). If, after running it and
# connecting to your vpn you can no longer resolve hostnames, it's likely because
# your system isn't using the DNS servers provided by the vpn and is instead
# using your ISP or local router assigned servers (DNS leak! Bad!) To fix this,
# make sure the resolvconf package is installed and you run
# /etc/openvpn/update-resolv-conf on connecting/disconnecting from the vpn. The
# --up and --down command line parameters can be used for this like so: openvpn
# --script-security 2 --up /etc/openvpn/update-resolv-conf --down
# /etc/openvpn/update-resolv-conf


#!/bin/sh

# Delete old iptables rules
# and temporarily block all traffic.
iptables -P OUTPUT DROP
iptables -P INPUT DROP
iptables -P FORWARD DROP
iptables -F

/sbin/iptables -P INPUT DROP
/sbin/iptables -P FORWARD DROP
/sbin/iptables -A INPUT -i lo -j ACCEPT
/sbin/iptables -A INPUT -m state --state RELATED,ESTABLISHED -j ACCEPT
/sbin/iptables -A OUTPUT -p udp --sport 68 -j ACCEPT
/bin/grep -h '^remote ' /etc/openvpn/*.ovpn | /usr/bin/cut -d ' ' -f 2 | /usr/bin/sort -du | /usr/bin/xargs -I @ /sbin/iptables -A OUTPUT -d @ -j ACCEPT
/sbin/iptables -A OUTPUT -o eth0 -j REJECT

# What it does (line by line):
# 1) Set policy to reject all incoming traffic other than what we specifically allow.
# 2) Allow incoming loopback traffic.
# 3) Allow incoming traffic already associated with a connection.
# 4) Allow incoming traffic on eth0 from the local lan.
# 5) Allow outbound traffic on eth0 to the local lan if it is already associated with a connection.
# 6) Allow outbound traffic on udp port 68 to allow the machine to get an IP address via DHCP (you can remove this if you use manually assigned addresses).
# An even better version of the rule would be:
# /sbin/iptables -A OUTPUT -o eth0 -d 192.168.1.0/24 -p udp --sport 68 --dport 67 -j ACCEPT
# This is a little more restrictive than the one above, and matches what I have in use.
# 7) Parse the ovpn files found in /etc/openvpn and allow outbound traffic to any servers listed.
# 8) Reject all other outbound traffic on eth0. It is important to specify eth0 here, otherwise we'd block outbound traffic on the vpn itself.

# Note: This will block normal web browsing and other such activity even when the
# vpn is disconnected (I simply never do anything on the net from this machine
# without the vpn). To enable normal communications, just run iptables -F to
# flush the rules. You can even use the --up and --down parameters of openvpn to
# do this as well. EDIT: That last sentence should be ignored for a secure setup.
# While it might be convenient to automatically disable the rules, it defeats the
# original purpose of preventing communication when the vpn fails unexpectedly.
 
Old 05-14-2015, 03:28 AM   #2
translator1111
Member
 
Registered: Jun 2010
Location: Slovakia
Distribution: Debian 8, Ubuntu 10.04 and 12.04; SLAX 6.0; ConnochaetOS 0.9.; LFS; Natty chip: VT1708S
Posts: 108
Blog Entries: 2

Rep: Reputation: 7
Dear Josephs
is there a typo in the word security written "with 2 rs" ?
Quote:
sudo openvpn --config /etc/openvpn/vpnbook-ca1-udp53.ovpn --script-securrity 2 --up /etc/openvpn/update-resolv-conf
faithfully,
M.
 
Old 05-15-2015, 11:40 AM   #3
JosephS
Member
 
Registered: Jun 2007
Distribution: Debian Jessie, Bunsenlabs
Posts: 586

Original Poster
Rep: Reputation: 38
Quote:
Originally Posted by translator1111 View Post
Dear Josephs
is there a typo in the word security written "with 2 rs" ?

faithfully,
M.
Yes, but that is not what I typed when I used the command. I copied it wrong in the post.

Thanks
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
firewall for vpn pinguim007 Linux - Networking 1 06-17-2011 07:16 AM
VPN Firewall Solution Rycharde Linux - Security 1 03-24-2008 12:47 AM
Best suggestion for a VPN firewall. waelaltaqi Linux - Networking 8 10-22-2006 04:50 AM
Redhat Firewall VPN dwpondscum Red Hat 1 12-03-2004 04:31 PM
VPN through IPchains firewall snowdog12 Linux - Networking 1 04-26-2003 06:06 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Security

All times are GMT -5. The time now is 07:07 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration