<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>KennyNet &#187; vpn</title>
	<atom:link href="http://www.kennynet.co.uk/tag/vpn/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.kennynet.co.uk</link>
	<description>Ramblings of a PHP developer</description>
	<lastBuildDate>Fri, 02 Dec 2011 14:05:13 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.2.1</generator>
		<item>
		<title>Filtering traffic through a VPN</title>
		<link>http://www.kennynet.co.uk/2010/04/14/filtering-traffic-through-vpn/</link>
		<comments>http://www.kennynet.co.uk/2010/04/14/filtering-traffic-through-vpn/#comments</comments>
		<pubDate>Wed, 14 Apr 2010 13:01:07 +0000</pubDate>
		<dc:creator>Kenny Millington</dc:creator>
				<category><![CDATA[Linux]]></category>
		<category><![CDATA[ipredator]]></category>
		<category><![CDATA[proxy]]></category>
		<category><![CDATA[ubuntu]]></category>
		<category><![CDATA[vpn]]></category>

		<guid isPermaLink="false">http://www.kennynet.co.uk/?p=113</guid>
		<description><![CDATA[Having recently purchased a subscription to iPredator I wanted to filter only certain traffic over the VPN and the rest, by default, over my normal ADSL account. My solution was to setup a SOCKS5 and HTTP proxy that went out over the VPN leaving the rest of the traffic to follow the default route as [...]]]></description>
			<content:encoded><![CDATA[<p>Having recently purchased a subscription to<a title="iPredator" href="https://www.ipredator.se/"> iPredator</a> I wanted to filter only certain traffic over the VPN and the rest, by default, over my normal ADSL account. My solution was to setup a SOCKS5 and HTTP proxy that went out over the VPN leaving the rest of the traffic to follow the default route as normal.</p>
<p>Please note this guide works for me on Ubuntu 9.10 (Karmic), your mileage may vary!</p>
<p><strong>Step 1: Setting up the PPTP connection to iPredator</strong></p>
<p>Firstly install the required packages:-</p>
<pre>$ sudo apt-get install pptp-linux ppp</pre>
<p>Obviously the first step is to actually get the VPN setup, so I created the peers file: /etc/ppp/peers/ipredator</p>
<pre>pty "pptp vpn.ipredator.se --nolaunchpppd --nobuffer --loglevel 0"
name YOUR-USERNAME-HERE
remotename ipredator
file /etc/ppp/options.pptp
ipparam ipredator
nodefaultroute
persist</pre>
<p>Next you have to populate your chap-secrets file with your password: /etc/ppp/chap-secrets:-</p>
<pre>YOUR-USERNAME-HERE    ipredator   YOUR-PASSWORD-HERE        *</pre>
<p>Finally edit the /etc/ppp/options.pptp file and uncomment the require-mppe-128 line. Now if you run &#8220;pon ipredator&#8221; and tail the syslog you should find that the VPN comes up although at the moment no traffic will route over it so go ahead and and run &#8220;poff ipredator&#8221;.</p>
<p><strong>Step two: Setup the SOCKS5 server</strong></p>
<p>Now we need to setup the SOCKS5 server, danted. First go ahead and install it:-</p>
<pre>$ sudo apt-get install dante-server</pre>
<p>Next edit the config file /etc/danted.conf and make it look something like this, changing 192.168.1.0/24 to your local subnet:-</p>
<pre>logoutput: syslog

internal: eth0 port = 1080
external: ppp0

method: none
clientmethod: none

user.privileged: proxy
user.notprivileged: proxy
user.libwrap: proxy

client pass {
    from: 192.168.1.0/24 port 1-65535 to: 0.0.0.0/0
}

client pass {
    from: 127.0.0.1/32 port 1-65535 to: 0.0.0.0/0
}

client block {
	from: 0.0.0.0/0 to: 0.0.0.0/0
log: connect error
}

block {
	from: 0.0.0.0/0 to: 127.0.0.0/8
	log: connect error
}

pass {
       from: 192.168.1.0/24 to: 0.0.0.0/0
       protocol: tcp udp
}

pass {
	from: 127.0.0.1/32 to: 0.0.0.0/0
        protocol: tcp udp
}

block {
	from: 0.0.0.0/0 to: 0.0.0.0/0
        log: connect error
}</pre>
<p>Finally since we will be controlling when this process starts we need to prevent it from starting at boot by running the following:-</p>
<pre>$ sudo update-rc.d -f danted remove
$ sudo service danted stop</pre>
<p><strong>Step three: Setting up the HTTP Proxy</strong></p>
<p>Firstly install the HTTP proxy (polipo):-</p>
<pre>$ sudo apt-get install polipo</pre>
<p>Now make your config file /etc/polipo/config look something like this, changing as appropriate:-</p>
<pre>proxyAddress = "192.168.1.1"    # IPv4 only
proxyPort = 3128
allowedClients = 192.168.1.0/24
allowedPorts = 1-65535

socksParentProxy = "192.168.1.1:1080"
socksProxyType = socks5
chunkHighMark = 50331648
diskCacheRoot = ""
disableIndexing = true
disableServersList = true
dnsUseGethostbyname = yes
disableVia=true
censoredHeaders = from,accept-language,x-pad,link
censorReferer = maybe
maxConnectionAge = 5m
maxConnectionRequests = 120
serverMaxSlots = 8
serverSlots = 2
tunnelAllowedPorts = 1-65535</pre>
<p>Finally since we&#8217;ll be controlling when this service starts, prevent it from starting on boot:-</p>
<pre>$ sudo update-rc.d -f polipo remove
$ sudo service polipo stop
</pre>
<p><strong>Step four: Setting up the VPN routes</strong></p>
<p>Now that our services are configured we need to add the magic glue that makes their requests route out via the VPN &#8211; this will be done using an ip-up.d script and an ip-down.d script.</p>
<p><em>NB: Both these scripts assume that your proxy user has user id 13, please change accordingly if this is not the case.</em></p>
<p>Create the /etc/ppp/ip.up.d/ipredator script as follows (changing 192.168.1.0/24 as appropriate):-</p>
<pre>#!/bin/bash

# Check for the iPredator VPN.
[ "$6" == "ipredator" ] || exit 0

# Setup the extra routing table for iPredator.
ip route add table 200 via $5
ip route add 192.168.1.0/24 dev eth0 table 200
ip rule add fwmark 0x50 table 200

# Mark all packets owned by the proxy user to go through iPredator.
iptables -t mangle -A OUTPUT --match owner --uid-owner 13 -j MARK --set-mark 80

# Start the daemons we use for this VPN.
service danted start
service polipo start</pre>
<p>Next create the /etc/ppp/ip-down.d/ipredator similarly:-</p>
<pre>#!/bin/bash

# Check for the iPredator VPN.
[ "$6" == "ipredator" ] || exit 0

# Stop the daemons we use for this VPN.
service danted stop
service polipo stop

# Remove the packet mangling rule.
iptables -t mangle -D OUTPUT --match owner --uid-owner 13 -j MARK --set-mark 80

# Remove the extra routing table for iPredator.
ip rule del fwmark 0x50 table 200
ip route del 192.168.1.0/24 dev eth0 table 200
ip route del table 200 via $5</pre>
<p>Ensure both scripts are executable.</p>
<p><strong>Step five: Testing the services.</strong><br />
To test firstly bring up the VPN by running &#8220;pon ipredator&#8221;, you should see the VPN come up and both polipo and danted should be started.</p>
<p>Check, by default, you get your ADSL IP:-</p>
<pre>$ wget -q -O - http://www.whatismyip.com/automation/n09230945.asp</pre>
<p>Next check that when routing via the proxy you get a different (VPN) IP:-</p>
<pre>$ export http_proxy=192.168.1.1:3128
$ wget -q -O - http://www.whatismyip.com/automation/n09230945.asp</pre>
<p>If it all works congratulations, you now have a http and socks5 proxy routing traffic over your VPN while all other traffic routes out via your normal connection.</p>
<p>IF it fails, I&#8217;m afraid you&#8217;re stuck going through the logs etc&#8230; Sorry!</p>
]]></content:encoded>
			<wfw:commentRss>http://www.kennynet.co.uk/2010/04/14/filtering-traffic-through-vpn/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
	</channel>
</rss>

