LinuxQuestions.org
Latest LQ Deal: Latest LQ Deals
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 06-27-2011, 06:11 PM   #1
jaiya
LQ Newbie
 
Registered: May 2011
Location: UK
Distribution: Slackware 13.37
Posts: 6

Rep: Reputation: 0
iptables - only allow connections through vpn


Hi I use a PPTP VPN (See future post about how to make L2TP/ipsec work) and it doesn't stay connected very well (See future post for how to make VPN auto reconnect ). I'd like to make iptables drop all packets that are not coming through the VPN.

I tried -A OUTPUT -s 10.0.0.180 -j DROP .. but then i couldn't even 'dial' the VPN. Then I tried -A OUTPUT -j LOG and realized i know very little about how it actually works... Please help.
 
Old 06-27-2011, 08:30 PM   #2
Noway2
Senior Member
 
Registered: Jul 2007
Distribution: Gentoo
Posts: 2,125

Rep: Reputation: 781Reputation: 781Reputation: 781Reputation: 781Reputation: 781Reputation: 781Reputation: 781
You really need to understand both how Iptables and a VPN works. As far as iptables, I would highly recommend one of the many tutorial on it. Here is one that I know to be reputable: http://bodhizazen.net/Tutorials/iptables

In essence your -A OUTPUT -s 10.0.0.180 -j DROP rule is backwards of what you want. In effect you are saying to drop all traffic that is outbound from the interface that originated at 10.0.0.,180 and I doubt that this is what you want. Instead you want to configure a set of policy rules for your input and output tables based upon your design. With VPN this gets more complicated because you also need to involve the routing table. The routine table determines what interface traffic is handled by and this in turn will be filtered in Iptables. A problem you may face with this approach is that the VPN uses a virtual interface, either a TUN or TAP adapter that is a logical construct on your physical interface such as eth0. so in essence, you can't restrict the traffic from the physical interface and get it to flow via VPN.
 
Old 06-28-2011, 10:20 AM   #3
lazydog
Senior Member
 
Registered: Dec 2003
Location: The Key Stone State
Distribution: CentOS Sabayon and now Gentoo
Posts: 1,249
Blog Entries: 3

Rep: Reputation: 194Reputation: 194
You could try the following.

Lets say your VPN is using port 10000, the destination is 1.2.3.4 and the interface is tun0

Code:
iptbales -OUTPUT -i tun0 -j ACCEPT
iptables -OUTPUT -d 1.2.3.4 --dport 10000 -j ACCEPT
iptbales -OUTPUT -j DROP
This should allow you to bring up the VPN and then only allow traffic that is to pass over the VPN.
 
Old 06-29-2011, 04:22 PM   #4
jaiya
LQ Newbie
 
Registered: May 2011
Location: UK
Distribution: Slackware 13.37
Posts: 6

Original Poster
Rep: Reputation: 0
@Noway2 - thanks, I've started reading that.

@lazydog - thanks, but it says -i can't be used with OUTPUT

The interface it uses is ppp0... More info coming soon I'm still learning to read -j LOG
 
Old 06-30-2011, 06:55 AM   #5
Hangdog42
LQ Veteran
 
Registered: Feb 2003
Location: Maryland
Distribution: Slackware
Posts: 7,803
Blog Entries: 1

Rep: Reputation: 422Reputation: 422Reputation: 422Reputation: 422Reputation: 422
There is a typo in lazydog's rules (flagged -OUTPUT and should have replaced -i with -o) They should probably look something like:


Code:
iptbales -A OUTPUT -o tun0 -j ACCEPT
iptables -A OUTPUT -d 1.2.3.4 --dport 10000 -j ACCEPT
iptbales -A OUTPUT -j DROP

Though I'm not so sure the second rule is needed since the first rule will route any traffic on tun0, which presumably is your VPN interface.

Quote:
Originally Posted by jaiya
The interface it uses is ppp0... More info coming soon I'm still learning to read -j LOG
Your main interface may be ppp0, but the VPN interface is likely to be something else that is run through ppp0.

Last edited by Hangdog42; 06-30-2011 at 07:00 AM.
 
Old 06-30-2011, 07:29 AM   #6
jaiya
LQ Newbie
 
Registered: May 2011
Location: UK
Distribution: Slackware 13.37
Posts: 6

Original Poster
Rep: Reputation: 0
I thought my main interface was eth0, ppp0 onlY appears when I connect to the vpn.
 
Old 06-30-2011, 08:38 AM   #7
Noway2
Senior Member
 
Registered: Jul 2007
Distribution: Gentoo
Posts: 2,125

Rep: Reputation: 781Reputation: 781Reputation: 781Reputation: 781Reputation: 781Reputation: 781Reputation: 781
I am still thinking that the Iptables rules above will only ALLOW traffic to flow through the desired interface but that it won't CAUSE it to flow through the interface; the conditions of cause and permitting being separate concepts. I still think you will need either a modification to your routing table, as is typically employed by tools such as OpenVPN or a masquerade or other NAT statement(s) in iptables.
 
Old 07-02-2011, 01:13 AM   #8
lazydog
Senior Member
 
Registered: Dec 2003
Location: The Key Stone State
Distribution: CentOS Sabayon and now Gentoo
Posts: 1,249
Blog Entries: 3

Rep: Reputation: 194Reputation: 194
Quote:
Originally Posted by Hangdog42 View Post
There is a typo in lazydog's rules (flagged -OUTPUT and should have replaced -i with -o) They should probably look something like:
Yes, it was a typo, my mistake. Sorry.


Quote:
Code:
iptbales -A OUTPUT -o tun0 -j ACCEPT
iptables -A OUTPUT -d 1.2.3.4 --dport 10000 -j ACCEPT
iptbales -A OUTPUT -j DROP

Though I'm not so sure the second rule is needed since the first rule will route any traffic on tun0, which presumably is your VPN interface.
The second rule is to allow the bringing up of the VPN. OP was looking to drop everything outbound except the VPN connection. You will need to allow for the buildup of the VPN so that that connection is not dropped.
 
Old 07-02-2011, 01:17 AM   #9
lazydog
Senior Member
 
Registered: Dec 2003
Location: The Key Stone State
Distribution: CentOS Sabayon and now Gentoo
Posts: 1,249
Blog Entries: 3

Rep: Reputation: 194Reputation: 194
Quote:
Originally Posted by Noway2 View Post
I am still thinking that the Iptables rules above will only ALLOW traffic to flow through the desired interface but that it won't CAUSE it to flow through the interface; the conditions of cause and permitting being separate concepts. I still think you will need either a modification to your routing table, as is typically employed by tools such as OpenVPN or a masquerade or other NAT statement(s) in iptables.
Routing table will most likely still require the proper information to ensure the traffic is flowing through the proper interface. I would be intersted in knowing what the routing tables looks like before and after the VPn is brought up and also what the other sides ip address is on the inside. Only with this information would we be able to tell what is really needed. I assume the OP knows what he is doing just not how to go about it.
 
Old 07-02-2011, 07:09 AM   #10
Hangdog42
LQ Veteran
 
Registered: Feb 2003
Location: Maryland
Distribution: Slackware
Posts: 7,803
Blog Entries: 1

Rep: Reputation: 422Reputation: 422Reputation: 422Reputation: 422Reputation: 422
Quote:
Originally Posted by lazydog
The second rule is to allow the bringing up of the VPN. OP was looking to drop everything outbound except the VPN connection. You will need to allow for the buildup of the VPN so that that connection is not dropped.
Maybe I'm not thinking about this correctly, but if the VPN traffic is running exclusively over the tun device, the second rule will never get used because all the traffic will be handled by the preceding rule.

In other words, the request to establish a VPN connection initially comes in over something other than tun0, but the response should go out on tun0, in which case the first rule will handle it. However, I'm certainly not a VPN expert, so am I misunderstanding how this works?
 
Old 07-02-2011, 11:30 PM   #11
lazydog
Senior Member
 
Registered: Dec 2003
Location: The Key Stone State
Distribution: CentOS Sabayon and now Gentoo
Posts: 1,249
Blog Entries: 3

Rep: Reputation: 194Reputation: 194
Quote:
Originally Posted by Hangdog42 View Post
Maybe I'm not thinking about this correctly, but if the VPN traffic is running exclusively over the tun device, the second rule will never get used because all the traffic will be handled by the preceding rule.

In other words, the request to establish a VPN connection initially comes in over something other than tun0, but the response should go out on tun0, in which case the first rule will handle it. However, I'm certainly not a VPN expert, so am I misunderstanding how this works?
Connection is first established, then the tunnel is built. If the OP wanted to drop all traffic except the tunnel traffic the original connection to build the tunnel would not be created because all traffic other then the tunnel traffic is dropped. Thus you need that one rule to allow for the creation of the connection to build the tunnel.
 
1 members found this post helpful.
Old 07-03-2011, 08:00 AM   #12
Hangdog42
LQ Veteran
 
Registered: Feb 2003
Location: Maryland
Distribution: Slackware
Posts: 7,803
Blog Entries: 1

Rep: Reputation: 422Reputation: 422Reputation: 422Reputation: 422Reputation: 422
Thanks lazydog, I get it now.
 
  


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
Iptables, two internet connections, VPN + two local networks. dlublink Linux - Networking 1 12-31-2008 12:06 PM
Mandriva VPN Connections dudeman41465 Linux - Desktop 0 08-03-2008 01:57 AM
VPN connections? JET-33 Linux - Networking 3 07-17-2007 07:31 PM
iptables and VPN connections lucifercipher Linux - Networking 2 04-05-2005 09:43 AM
VPN Connections itguy Linux - Security 2 05-02-2002 03:10 PM

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

All times are GMT -5. The time now is 03:45 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