<?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>TroubleNow.org &#187; Arno Haverlach</title>
	<atom:link href="http://www.troublenow.org/author/admin/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.troublenow.org</link>
	<description>Just a reference base</description>
	<lastBuildDate>Fri, 06 Jan 2012 08:13:00 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
		<item>
		<title>Howto setup openvpn in bridge mode on debian</title>
		<link>http://www.troublenow.org/362/howto-setup-openvpn-in-bridge-mode-on-debian/</link>
		<comments>http://www.troublenow.org/362/howto-setup-openvpn-in-bridge-mode-on-debian/#comments</comments>
		<pubDate>Wed, 21 Dec 2011 13:29:23 +0000</pubDate>
		<dc:creator>Arno Haverlach</dc:creator>
				<category><![CDATA[debian]]></category>
		<category><![CDATA[OpenVPN]]></category>

		<guid isPermaLink="false">http://www.troublenow.org/?p=362</guid>
		<description><![CDATA[Below is my setup for a OpenVPN server in bridged mode with local firewall. In short we will create a VPN server with the following setup: Note, if you are using ESXi follow this post first: OpenVPN bridge and vmware esxi Installation First install the required packages: apt-get install openssl bridge-utils openvpn zip Copy over [...]]]></description>
			<content:encoded><![CDATA[<p>Below is my setup for a OpenVPN server in bridged mode with local firewall.<br />
In short we will create a VPN server with the following setup:</p>
<p><a href="http://www.troublenow.org/wp-content/uploads/2011/12/TN.org-openvpn-bridged.png" title="OpenVPN Bridge"><img src="http://www.troublenow.org/wp-content/uploads/2011/12/TN.org-openvpn-bridged-300x263.png" alt="" title="TN.org-openvpn-bridged" width="300" height="263" class="alignleft size-medium wp-image-413" /></a><br />
<ul class="list-black">
<ul>
<li>Debian 6 as VPN server.</li>
<li>VPN Server on TCP port 443</li>
<li>(SSL port so it works behind firewall&#8217;s)</li>
<li>2048bit key size.</li>
<li>Local subnet of 192.168.255.0/24</li>
<li>Max 10 VPN Clients</li>
<li>(Can be increased by changing dhcp pool size)</li>
<li>All config files will be kept in /etc/openvpn</li>
<li>Local firewall to control access for VPN users</li>
</ul>
</ul></p>
<p>Note, if you are using ESXi follow this post first: <a href="http://www.troublenow.org/344/openvpn_bridge_and_vmware_esxi/" title="OpenVPN bridge and vmware esxi">OpenVPN bridge and vmware esxi</a></p>
<h3>Installation</h3>
<p>First install the required packages:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #c20cb9; font-weight: bold;">apt-get</span> <span style="color: #c20cb9; font-weight: bold;">install</span> openssl bridge-utils openvpn <span style="color: #c20cb9; font-weight: bold;">zip</span></pre></div></div>

<p></p>
<p>Copy over the example easy-rsa 2.0 data to /etc/openvpn</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #c20cb9; font-weight: bold;">cp</span> <span style="color: #660033;">-a</span> <span style="color: #000000; font-weight: bold;">/</span>usr<span style="color: #000000; font-weight: bold;">/</span>share<span style="color: #000000; font-weight: bold;">/</span>doc<span style="color: #000000; font-weight: bold;">/</span>openvpn<span style="color: #000000; font-weight: bold;">/</span>examples<span style="color: #000000; font-weight: bold;">/</span>easy-rsa<span style="color: #000000; font-weight: bold;">/</span><span style="color: #000000;">2.0</span><span style="color: #000000; font-weight: bold;">/</span> <span style="color: #000000; font-weight: bold;">/</span>etc<span style="color: #000000; font-weight: bold;">/</span>openvpn<span style="color: #000000; font-weight: bold;">/</span>easy-rsa</pre></div></div>

<p></p>
<p>Now we need to edit the <strong>vars</strong> file in the easy-rsa folder to match your organization information, so change <strong>EXAMPLE</strong> to your own info.</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #7a0874; font-weight: bold;">cd</span> <span style="color: #000000; font-weight: bold;">/</span>etc<span style="color: #000000; font-weight: bold;">/</span>openvpn<span style="color: #000000; font-weight: bold;">/</span>easy-rsa
<span style="color: #c20cb9; font-weight: bold;">sed</span> <span style="color: #660033;">-i</span> <span style="color: #ff0000;">'/export EASY_RSA=/ c\export EASY_RSA=\&quot;/etc/openvpn/easy-rsa\&quot;'</span> vars
<span style="color: #c20cb9; font-weight: bold;">sed</span> <span style="color: #660033;">-i</span> <span style="color: #ff0000;">'/export KEY_SIZE=/ c\export KEY_SIZE=2048'</span> vars
<span style="color: #c20cb9; font-weight: bold;">sed</span> <span style="color: #660033;">-i</span> <span style="color: #ff0000;">'/export KEY_COUNTRY=/ c\export KEY_COUNTRY=\&quot;EXAMPLE\&quot;'</span> vars
<span style="color: #c20cb9; font-weight: bold;">sed</span> <span style="color: #660033;">-i</span> <span style="color: #ff0000;">'/export KEY_PROVINCE=/ c\export KEY_PROVINCE=\&quot;EXAMPLE\&quot;'</span> vars
<span style="color: #c20cb9; font-weight: bold;">sed</span> <span style="color: #660033;">-i</span> <span style="color: #ff0000;">'/export KEY_CITY=/ c\export KEY_CITY=\&quot;EXAMPLE\&quot;'</span> vars
<span style="color: #c20cb9; font-weight: bold;">sed</span> <span style="color: #660033;">-i</span> <span style="color: #ff0000;">'/export KEY_ORG=/ c\export KEY_ORG=\&quot;EXAMPLE\&quot;'</span> vars
<span style="color: #c20cb9; font-weight: bold;">sed</span> <span style="color: #660033;">-i</span> <span style="color: #ff0000;">'/export KEY_EMAIL=/ c\export KEY_EMAIL=\&quot;user\@example.com\&quot;'</span> vars</pre></div></div>

<p></p>
<p>Now build your CA and server key <em>(you already have provided all the right info in the <strong>vars</strong> file so press enter all the way through).</em></p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #7a0874; font-weight: bold;">source</span> .<span style="color: #000000; font-weight: bold;">/</span>vars
.<span style="color: #000000; font-weight: bold;">/</span>clean-all
.<span style="color: #000000; font-weight: bold;">/</span>build-ca
.<span style="color: #000000; font-weight: bold;">/</span>build-key-server server
.<span style="color: #000000; font-weight: bold;">/</span>build-dh<span style="color: #000000; font-weight: bold;">&lt;</span>;<span style="color: #000000; font-weight: bold;">/</span>pre<span style="color: #000000; font-weight: bold;">&gt;</span>
<span style="color: #000000; font-weight: bold;">&lt;</span>br<span style="color: #000000; font-weight: bold;">&gt;</span></pre></div></div>

<p>Now we need to create a server.conf file in /etc/openvpn</p>
<pre>cd /etc/openvpn &#038;&#038; vi server.conf</pre>
<p></p>
<p><strong>server.conf</strong><br />
<span class='hlight' >I will use TCP port 443 for the VPN server with a local subnet of 192.168.255.0/24<br />
IP&#8217;s 192.168.255.200~192.168.255.210 will be used for client DHCP (max 10 clients), and 192.168.255.3 is the OpenVPN server himself.</span><br />
<h4 class="toggle"><a href="#">Server.conf (Click to expand)</a></h4><div class="toggle_body"><div class="block"></p>
<pre>port 443
proto tcp
dev tap0
ca /etc/openvpn/easy-rsa/keys/ca.crt
cert /etc/openvpn/easy-rsa/keys/server.crt
key /etc/openvpn/easy-rsa/keys/server.key
dh /etc/openvpn/easy-rsa/keys/dh2048.pem
ifconfig-pool-persist ipp.txt
server-bridge 192.168.255.3 255.255.255.0 192.168.255.200 192.168.255.210
keepalive 10 120
comp-lzo
persist-key
persist-tun
log /var/log/openvpn.log
log-append /var/log/openvpn.log
status /var/log/openvpn-status.log
verb 3

#===================================================#
# Client Settings
#===================================================#
# If you need to push routes you can do so here for example:
#push "route 192.168.0.0 255.255.255.0 192.168.255.1"

push "ping 10"
push "ping-restart 60"

push "dhcp-option DOMAIN example.local"
push "dhcp-option DNS 192.168.255.1"
push "dhcp-option DNS 192.168.255.2"
push "dhcp-option WINS 192.168.255.1"
push "route-delay 5"

push "echo "
push "echo Welcome to the EXAMPLE Network!"
push "echo "
</pre>
<p></div></div></p>
<p>Now we need to bridge the OpenVPN tap0 interface with your network interface (eth0 in this example).<br />
<span class='hlight' >Make sure to change the settings for your network (IP, subnet, gateway etc) as this will replace your current interface configuration don&#8217;t do this remotely.</span><br />
</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #c20cb9; font-weight: bold;">vi</span> <span style="color: #000000; font-weight: bold;">/</span>etc<span style="color: #000000; font-weight: bold;">/</span>init.d<span style="color: #000000; font-weight: bold;">/</span>bridge</pre></div></div>

<h4 class="toggle"><a href="#">/etc/init.d/bridge (Click to expand)</a></h4><div class="toggle_body"><div class="block"></p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #666666; font-style: italic;">#!/bin/bash  </span>
&nbsp;
<span style="color: #666666; font-style: italic;">### BEGIN INIT INFO</span>
<span style="color: #666666; font-style: italic;"># Provides:             bridge</span>
<span style="color: #666666; font-style: italic;"># Required-Start:       $remote_fs $syslog</span>
<span style="color: #666666; font-style: italic;"># Required-Stop:        $remote_fs $syslog</span>
<span style="color: #666666; font-style: italic;"># Default-Start:        2 3 4 5</span>
<span style="color: #666666; font-style: italic;"># Default-Stop:</span>
<span style="color: #666666; font-style: italic;"># Short-Description:    Bridge for OpenVPN</span>
<span style="color: #666666; font-style: italic;">### END INIT INFO</span>
&nbsp;
<span style="color: #666666; font-style: italic;"># Define Bridge Interface </span>
<span style="color: #007800;">br</span>=<span style="color: #ff0000;">&quot;br0&quot;</span> 
<span style="color: #666666; font-style: italic;"># Define list of TAP interfaces to be bridged, </span>
<span style="color: #666666; font-style: italic;"># for example tap=&quot;tap0 tap1&quot;. </span>
<span style="color: #007800;">tap</span>=<span style="color: #ff0000;">&quot;tap0&quot;</span> 
<span style="color: #666666; font-style: italic;"># Define physical ethernet interface to be bridged </span>
<span style="color: #666666; font-style: italic;"># with TAP interface(s) above. </span>
<span style="color: #007800;">eth</span>=<span style="color: #ff0000;">&quot;eth0&quot;</span> 
<span style="color: #007800;">eth_ip</span>=<span style="color: #ff0000;">&quot;192.168.255.3&quot;</span> 
<span style="color: #007800;">eth_netmask</span>=<span style="color: #ff0000;">&quot;255.255.255.0&quot;</span> 
<span style="color: #007800;">eth_broadcast</span>=<span style="color: #ff0000;">&quot;192.168.255.255&quot;</span> 
<span style="color: #007800;">gw</span>=<span style="color: #ff0000;">&quot;192.168.255.254&quot;</span>   
&nbsp;
<span style="color: #666666; font-style: italic;">#################################   </span>
<span style="color: #666666; font-style: italic;"># Set up Ethernet bridge on Linux   </span>
<span style="color: #666666; font-style: italic;"># Requires: bridge-utils   </span>
<span style="color: #666666; font-style: italic;">#################################    </span>
start_bridge <span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #7a0874; font-weight: bold;">&#41;</span> <span style="color: #7a0874; font-weight: bold;">&#123;</span>   
        <span style="color: #000000; font-weight: bold;">for</span> t <span style="color: #000000; font-weight: bold;">in</span> <span style="color: #007800;">$tap</span>; <span style="color: #000000; font-weight: bold;">do</span>
                openvpn <span style="color: #660033;">--mktun</span> <span style="color: #660033;">--dev</span> <span style="color: #007800;">$t</span>   
        <span style="color: #000000; font-weight: bold;">done</span>   
&nbsp;
        brctl addbr <span style="color: #007800;">$br</span>
        brctl addif <span style="color: #007800;">$br</span> <span style="color: #007800;">$eth</span>
&nbsp;
        <span style="color: #000000; font-weight: bold;">for</span> t <span style="color: #000000; font-weight: bold;">in</span> <span style="color: #007800;">$tap</span>; <span style="color: #000000; font-weight: bold;">do</span>
                brctl addif <span style="color: #007800;">$br</span> <span style="color: #007800;">$t</span>
        <span style="color: #000000; font-weight: bold;">done</span>
&nbsp;
        <span style="color: #000000; font-weight: bold;">for</span> t <span style="color: #000000; font-weight: bold;">in</span> <span style="color: #007800;">$tap</span>; <span style="color: #000000; font-weight: bold;">do</span>
                <span style="color: #c20cb9; font-weight: bold;">ifconfig</span> <span style="color: #007800;">$t</span> 0.0.0.0 promisc up   
        <span style="color: #000000; font-weight: bold;">done</span>
        <span style="color: #c20cb9; font-weight: bold;">ifconfig</span> <span style="color: #007800;">$eth</span> 0.0.0.0 promisc up
        <span style="color: #c20cb9; font-weight: bold;">ifconfig</span> <span style="color: #007800;">$br</span> <span style="color: #007800;">$eth_ip</span> netmask <span style="color: #007800;">$eth_netmask</span> broadcast <span style="color: #007800;">$eth_broadcast</span> up   
        route add default gw <span style="color: #007800;">$gw</span> <span style="color: #007800;">$br</span>
<span style="color: #7a0874; font-weight: bold;">&#125;</span> 
&nbsp;
<span style="color: #666666; font-style: italic;">####################################   </span>
<span style="color: #666666; font-style: italic;"># Tear Down Ethernet bridge on Linux   </span>
<span style="color: #666666; font-style: italic;">####################################    </span>
stop_bridge <span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #7a0874; font-weight: bold;">&#41;</span> <span style="color: #7a0874; font-weight: bold;">&#123;</span>   
        <span style="color: #c20cb9; font-weight: bold;">ifconfig</span> <span style="color: #007800;">$br</span> down
        brctl delbr <span style="color: #007800;">$br</span>    
        <span style="color: #000000; font-weight: bold;">for</span> t <span style="color: #000000; font-weight: bold;">in</span> <span style="color: #007800;">$tap</span>; <span style="color: #000000; font-weight: bold;">do</span>
                openvpn <span style="color: #660033;">--rmtun</span> <span style="color: #660033;">--dev</span> <span style="color: #007800;">$t</span>   
        <span style="color: #000000; font-weight: bold;">done</span>   
        <span style="color: #c20cb9; font-weight: bold;">ifconfig</span> <span style="color: #007800;">$eth</span> <span style="color: #007800;">$eth_ip</span> netmask <span style="color: #007800;">$eth_netmask</span> broadcast <span style="color: #007800;">$eth_broadcast</span> up   
        route add default gw <span style="color: #007800;">$gw</span> <span style="color: #007800;">$eth</span>
<span style="color: #7a0874; font-weight: bold;">&#125;</span>  
&nbsp;
<span style="color: #666666; font-style: italic;">####################################</span>
<span style="color: #666666; font-style: italic;"># OPTIONS</span>
<span style="color: #666666; font-style: italic;">####################################</span>
<span style="color: #000000; font-weight: bold;">case</span> <span style="color: #ff0000;">&quot;$1&quot;</span> <span style="color: #000000; font-weight: bold;">in</span> 
        start<span style="color: #7a0874; font-weight: bold;">&#41;</span>   
          <span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #660033;">-n</span> <span style="color: #ff0000;">&quot;Starting Bridge&quot;</span>   
          start_bridge   
          <span style="color: #000000; font-weight: bold;">;;</span> 
        stop<span style="color: #7a0874; font-weight: bold;">&#41;</span>   
          <span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #660033;">-n</span> <span style="color: #ff0000;">&quot;Stopping Bridge&quot;</span>   
          stop_bridge   
          <span style="color: #000000; font-weight: bold;">;;</span> 
        restart<span style="color: #7a0874; font-weight: bold;">&#41;</span>   
          stop_bridge   
          <span style="color: #c20cb9; font-weight: bold;">sleep</span> <span style="color: #000000;">2</span>   
          start_bridge   
          <span style="color: #000000; font-weight: bold;">;;</span> 
        <span style="color: #000000; font-weight: bold;">*</span><span style="color: #7a0874; font-weight: bold;">&#41;</span>   
          <span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;Usage: $0 {start|stop|restart}&quot;</span> <span style="color: #000000; font-weight: bold;">&amp;</span>gt;<span style="color: #000000; font-weight: bold;">&amp;</span>amp;<span style="color: #000000;">2</span>   
          <span style="color: #7a0874; font-weight: bold;">exit</span> <span style="color: #000000;">1</span>   
          <span style="color: #000000; font-weight: bold;">;;</span> 
<span style="color: #000000; font-weight: bold;">esac</span></pre></div></div>

<p></div></div>
<p>Now make the script executable and set it as a default startup script:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #c20cb9; font-weight: bold;">chmod</span> <span style="color: #000000;">755</span> <span style="color: #000000; font-weight: bold;">/</span>etc<span style="color: #000000; font-weight: bold;">/</span>init.d<span style="color: #000000; font-weight: bold;">/</span>bridge
update-rc.d bridge defaults</pre></div></div>

<h3>User creation script</h3>
<p>For easy management I create a template config file and a script to create the certificate and zip the certificates and config file so you can send it to a user.</p>
<p>First we will create a template config file for openvpn, make sure to edit the VPNSERVERHOSTNAME to your hostname/ip for the VPN Server.<br />
Create a configs directory, here we will keep the user configuration zip files later on.</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #7a0874; font-weight: bold;">cd</span> <span style="color: #000000; font-weight: bold;">/</span>etc<span style="color: #000000; font-weight: bold;">/</span>openvpn
<span style="color: #c20cb9; font-weight: bold;">mkdir</span> configs
<span style="color: #7a0874; font-weight: bold;">cd</span> <span style="color: #000000; font-weight: bold;">/</span>etc<span style="color: #000000; font-weight: bold;">/</span>openvpn<span style="color: #000000; font-weight: bold;">/</span>configs
<span style="color: #c20cb9; font-weight: bold;">vi</span> template-config.ovpn</pre></div></div>

<pre>client
dev tap
proto tcp
remote VPNSERVERHOSTNAME 443
resolv-retry infinite
nobind
pkcs12 &lt;&gt;.p12
ns-cert-type server
comp-lzo
verb 3
#redirect-gateway</pre>
<p></p>
<p>Then create the <strong>new-user</strong> script.</p>
<pre>cd /etc/openvpn
vi new-user</pre>
<h4 class="toggle"><a href="#">newuser (Click to expand)</a></h4><div class="toggle_body"><div class="block"></p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #666666; font-style: italic;">#!/bin/bash</span>
<span style="color: #007800;">action</span>=<span style="color: #ff0000;">&quot;$1&quot;</span>
<span style="color: #007800;">option</span>=<span style="color: #ff0000;">&quot;$2&quot;</span>
<span style="color: #007800;">base</span>=<span style="color: #ff0000;">&quot;/etc/openvpn&quot;</span>
<span style="color: #666666; font-style: italic;">#</span>
<span style="color: #666666; font-style: italic;">#if [ -n $base/configs/$username ]</span>
&nbsp;
<span style="color: #666666; font-style: italic;">#----------------------------------------------------------------#</span>
<span style="color: #666666; font-style: italic;"># new user</span>
<span style="color: #666666; font-style: italic;">#----------------------------------------------------------------#</span>
<span style="color: #000000; font-weight: bold;">function</span> new_user<span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #7a0874; font-weight: bold;">&#41;</span>
<span style="color: #7a0874; font-weight: bold;">&#123;</span>
 <span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;Creating the new user <span style="color: #007800;">$username</span>&quot;</span>
&nbsp;
 <span style="color: #666666; font-style: italic;"># source the easy-rsa variables:</span>
 <span style="color: #7a0874; font-weight: bold;">source</span> <span style="color: #007800;">$base</span><span style="color: #000000; font-weight: bold;">/</span>easy-rsa<span style="color: #000000; font-weight: bold;">/</span>vars
&nbsp;
 <span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;Checking if user already exists&quot;</span>
 <span style="color: #000000; font-weight: bold;">if</span> <span style="color: #7a0874; font-weight: bold;">&#91;</span> <span style="color: #660033;">-x</span> <span style="color: #007800;">$base</span><span style="color: #000000; font-weight: bold;">/</span>configs<span style="color: #000000; font-weight: bold;">/</span><span style="color: #007800;">$username</span> <span style="color: #7a0874; font-weight: bold;">&#93;</span>
  <span style="color: #000000; font-weight: bold;">then</span>
   <span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;ERROR: user already exists&quot;</span>
   <span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;&quot;</span>
   <span style="color: #7a0874; font-weight: bold;">exit</span> <span style="color: #000000;">0</span>
 <span style="color: #000000; font-weight: bold;">else</span>
  <span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;Please check the already filled in answers and press&quot;</span>
  <span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;enter for all the options finaly press 'Y' twice.&quot;</span>
  <span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;&quot;</span>
  <span style="color: #c20cb9; font-weight: bold;">sleep</span> <span style="color: #000000;">5</span>
  <span style="color: #007800;">$base</span><span style="color: #000000; font-weight: bold;">/</span>easy-rsa<span style="color: #000000; font-weight: bold;">/</span>build-key-pkcs12 <span style="color: #007800;">$username</span>
&nbsp;
  <span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;Creating the config directory&quot;</span>
  <span style="color: #007800;">userdir</span>=<span style="color: #007800;">$base</span><span style="color: #000000; font-weight: bold;">/</span>configs<span style="color: #000000; font-weight: bold;">/</span><span style="color: #007800;">$username</span>
  <span style="color: #c20cb9; font-weight: bold;">mkdir</span> <span style="color: #007800;">$userdir</span>
  <span style="color: #c20cb9; font-weight: bold;">cp</span> <span style="color: #007800;">$base</span><span style="color: #000000; font-weight: bold;">/</span>easy-rsa<span style="color: #000000; font-weight: bold;">/</span>keys<span style="color: #000000; font-weight: bold;">/</span><span style="color: #007800;">$username</span>.p12 <span style="color: #007800;">$userdir</span>
  <span style="color: #c20cb9; font-weight: bold;">cp</span> <span style="color: #007800;">$base</span><span style="color: #000000; font-weight: bold;">/</span>configs<span style="color: #000000; font-weight: bold;">/</span>template-config.ovpn <span style="color: #007800;">$userdir</span><span style="color: #000000; font-weight: bold;">/</span><span style="color: #007800;">$username</span>.ovpn
  <span style="color: #c20cb9; font-weight: bold;">sed</span> <span style="color: #660033;">-i</span> <span style="color: #ff0000;">&quot;s/&amp;lt;&amp;gt;/<span style="color: #007800;">$username</span>/g&quot;</span> <span style="color: #007800;">$userdir</span><span style="color: #000000; font-weight: bold;">/</span><span style="color: #007800;">$username</span>.ovpn
  <span style="color: #7a0874; font-weight: bold;">cd</span> <span style="color: #007800;">$userdir</span>
  <span style="color: #000000; font-weight: bold;">/</span>usr<span style="color: #000000; font-weight: bold;">/</span>bin<span style="color: #000000; font-weight: bold;">/</span><span style="color: #c20cb9; font-weight: bold;">zip</span> <span style="color: #007800;">$userdir</span><span style="color: #000000; font-weight: bold;">/</span><span style="color: #007800;">$username</span>.zip <span style="color: #007800;">$username</span>.<span style="color: #000000; font-weight: bold;">*</span>
&nbsp;
  <span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;&quot;</span>
  <span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;User created&quot;</span>
  <span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;&quot;</span>
 <span style="color: #000000; font-weight: bold;">fi</span>
<span style="color: #7a0874; font-weight: bold;">&#125;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">#----------------------------------------------------------------#</span>
<span style="color: #666666; font-style: italic;"># show the usage</span>
<span style="color: #666666; font-style: italic;">#----------------------------------------------------------------#</span>
<span style="color: #000000; font-weight: bold;">function</span> show_usage<span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #7a0874; font-weight: bold;">&#41;</span>
<span style="color: #7a0874; font-weight: bold;">&#123;</span>
  <span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;&quot;</span>
  <span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;Usage: $0 [option] [arg]&quot;</span>
  <span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;Where [option] is:&quot;</span>
  <span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;&quot;</span>
  <span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;-new&quot;</span>
  <span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;   Create a new user&quot;</span>
  <span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;   [arg] = &quot;</span>
  <span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;&quot;</span>
  <span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;&quot;</span>
<span style="color: #7a0874; font-weight: bold;">&#125;</span>
<span style="color: #666666; font-style: italic;">#----------------------------------------------------------------#</span>
&nbsp;
<span style="color: #666666; font-style: italic;">#----------------------------------------------------------------#</span>
<span style="color: #666666; font-style: italic;"># Parse action</span>
<span style="color: #666666; font-style: italic;">#----------------------------------------------------------------#</span>
<span style="color: #000000; font-weight: bold;">function</span> parse_action<span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #7a0874; font-weight: bold;">&#41;</span>
<span style="color: #7a0874; font-weight: bold;">&#123;</span>
   <span style="color: #000000; font-weight: bold;">case</span> <span style="color: #007800;">$action</span> <span style="color: #000000; font-weight: bold;">in</span>
      -new<span style="color: #7a0874; font-weight: bold;">&#41;</span>
        <span style="color: #007800;">username</span>=<span style="color: #ff0000;">&quot;<span style="color: #007800;">$option</span>&quot;</span>
        new_user
        <span style="color: #000000; font-weight: bold;">;;</span>
      <span style="color: #000000; font-weight: bold;">*</span><span style="color: #7a0874; font-weight: bold;">&#41;</span>
        show_usage
        <span style="color: #000000; font-weight: bold;">;;</span>
   <span style="color: #000000; font-weight: bold;">esac</span>
<span style="color: #7a0874; font-weight: bold;">exit</span> <span style="color: #000000;">0</span>
<span style="color: #7a0874; font-weight: bold;">&#125;</span>
<span style="color: #666666; font-style: italic;">#----------------------------------------------------------------#</span>
&nbsp;
<span style="color: #666666; font-style: italic;">#----------------------------------------------------------------#</span>
<span style="color: #666666; font-style: italic;"># Main function</span>
<span style="color: #666666; font-style: italic;">#----------------------------------------------------------------#</span>
<span style="color: #000000; font-weight: bold;">function</span> main<span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #7a0874; font-weight: bold;">&#41;</span>
<span style="color: #7a0874; font-weight: bold;">&#123;</span>
  <span style="color: #000000; font-weight: bold;">if</span> <span style="color: #7a0874; font-weight: bold;">&#91;</span> <span style="color: #ff0000;">&quot;X<span style="color: #007800;">${action}</span>&quot;</span> == <span style="color: #ff0000;">&quot;X&quot;</span> <span style="color: #7a0874; font-weight: bold;">&#93;</span>
   <span style="color: #000000; font-weight: bold;">then</span>
    show_usage
    <span style="color: #7a0874; font-weight: bold;">exit</span> <span style="color: #000000;">0</span>
   <span style="color: #000000; font-weight: bold;">else</span>
    parse_action
  <span style="color: #000000; font-weight: bold;">fi</span>
&nbsp;
<span style="color: #7a0874; font-weight: bold;">&#125;</span>
<span style="color: #666666; font-style: italic;">#----------------------------------------------------------------#</span>
&nbsp;
<span style="color: #666666; font-style: italic;">#----------------------------------------------------------------#</span>
<span style="color: #666666; font-style: italic;"># run the Main script</span>
<span style="color: #666666; font-style: italic;">#----------------------------------------------------------------#</span>
main
<span style="color: #666666; font-style: italic;">#----------------------------------------------------------------#</span></pre></div></div>

<p></div></div>
<p>Now make the script executable and run it with &#8220;-new johndoe&#8221; to create a new vpn certificate for user John Doe.</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #7a0874; font-weight: bold;">cd</span> <span style="color: #000000; font-weight: bold;">/</span>etc<span style="color: #000000; font-weight: bold;">/</span>openvpn
<span style="color: #c20cb9; font-weight: bold;">chmod</span> <span style="color: #000000;">700</span> new-user
.<span style="color: #000000; font-weight: bold;">/</span>new-user <span style="color: #660033;">-new</span> johndoe</pre></div></div>

<p></p>
<p>And finally we start the openvpn service:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">/</span>etc<span style="color: #000000; font-weight: bold;">/</span>init.d<span style="color: #000000; font-weight: bold;">/</span>openvpn start</pre></div></div>

<h3>Firewall</h3>
<p>Now we add a IPtables firewall script to protect the network from the VPN clients.</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #c20cb9; font-weight: bold;">mkdir</span> <span style="color: #000000; font-weight: bold;">/</span>opt<span style="color: #000000; font-weight: bold;">/</span>firewall
<span style="color: #c20cb9; font-weight: bold;">vi</span> <span style="color: #000000; font-weight: bold;">/</span>opt<span style="color: #000000; font-weight: bold;">/</span>firewall<span style="color: #000000; font-weight: bold;">/</span>localfw</pre></div></div>

<h4 class="toggle"><a href="#">localfw (Click to expand)</a></h4><div class="toggle_body"><div class="block"></p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #666666; font-style: italic;">#!/bin/bash</span>
<span style="color: #666666; font-style: italic;">#----------------------------------------------------#</span>
<span style="color: #666666; font-style: italic;">#   Firewall for bridged openvpn</span>
<span style="color: #666666; font-style: italic;">#   ver 0.1 20111021</span>
<span style="color: #666666; font-style: italic;">#----------------------------------------------------#</span>
&nbsp;
<span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;--------------------------------&quot;</span>
<span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;IPTABLES FIREWALL SCRIPT LOADING&quot;</span>
<span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;--------------------------------&quot;</span>
&nbsp;
modprobe ip_tables
&nbsp;
<span style="color: #666666; font-style: italic;">#--------------IP Variables -------------------------#</span>
<span style="color: #007800;">DNS1</span>=192.168.255.1                      <span style="color: #666666; font-style: italic;"># dns server 1</span>
<span style="color: #007800;">DNS2</span>=192.168.255.2                      <span style="color: #666666; font-style: italic;"># dns server 2</span>
<span style="color: #007800;">DNSSERVERS</span>=<span style="color: #ff0000;">&quot;<span style="color: #007800;">$DNS1</span> <span style="color: #007800;">$DNS2</span>&quot;</span>
&nbsp;
<span style="color: #007800;">WAN_IF</span>=<span style="color: #ff0000;">&quot;br0&quot;</span>                            <span style="color: #666666; font-style: italic;"># WAN Interface</span>
<span style="color: #007800;">WAN_IP</span>=<span style="color: #ff0000;">&quot;192.168.255.3&quot;</span>                  <span style="color: #666666; font-style: italic;"># WAN IP</span>
&nbsp;
<span style="color: #007800;">LANRANGE</span>=<span style="color: #ff0000;">&quot;192.168.255.0/24&quot;</span>               <span style="color: #666666; font-style: italic;"># LAN Range</span>
<span style="color: #666666; font-style: italic;">#-----------------------------------------------------#</span>
<span style="color: #007800;">IPTABLES</span>=<span style="color: #ff0000;">&quot;/sbin/iptables&quot;</span>       <span style="color: #666666; font-style: italic;"># path to iptables</span>
&nbsp;
<span style="color: #666666; font-style: italic;">#-----------------------------------------------------#</span>
<span style="color: #666666; font-style: italic;"># Check how we are started</span>
<span style="color: #007800;">CMD</span>=<span style="color: #007800;">$1</span>
<span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;Checking how we are started&quot;</span>
<span style="color: #000000; font-weight: bold;">if</span> <span style="color: #7a0874; font-weight: bold;">&#40;</span> <span style="color: #7a0874; font-weight: bold;">&#91;</span> <span style="color: #660033;">-z</span> <span style="color: #007800;">$CMD</span> <span style="color: #7a0874; font-weight: bold;">&#93;</span> <span style="color: #7a0874; font-weight: bold;">&#41;</span>; <span style="color: #000000; font-weight: bold;">then</span> <span style="color: #007800;">CMD</span>=<span style="color: #ff0000;">&quot;start&quot;</span>; <span style="color: #000000; font-weight: bold;">fi</span>
<span style="color: #666666; font-style: italic;">#-----------------------------------------------------#</span>
&nbsp;
<span style="color: #666666; font-style: italic;">#-----------------------------------------------------#</span>
<span style="color: #000000; font-weight: bold;">if</span> <span style="color: #7a0874; font-weight: bold;">&#40;</span> <span style="color: #7a0874; font-weight: bold;">&#91;</span> <span style="color: #007800;">$CMD</span> = <span style="color: #ff0000;">&quot;start&quot;</span> <span style="color: #7a0874; font-weight: bold;">&#93;</span> <span style="color: #7a0874; font-weight: bold;">&#41;</span>; <span style="color: #000000; font-weight: bold;">then</span>
<span style="color: #666666; font-style: italic;">#-----------------------------------------------------#</span>
&nbsp;
 <span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;checking if we need to enable IP forwarding&quot;</span>
 <span style="color: #007800;">IPFWDCHK</span>=<span style="color: #ff0000;">&quot;<span style="color: #780078;">`cat /proc/sys/net/ipv4/ip_forward`</span>&quot;</span>
 <span style="color: #000000; font-weight: bold;">if</span> <span style="color: #7a0874; font-weight: bold;">&#40;</span> <span style="color: #7a0874; font-weight: bold;">&#91;</span> <span style="color: #ff0000;">&quot;<span style="color: #007800;">$IPFWDCHK</span>&quot;</span> <span style="color: #000000; font-weight: bold;">!</span>= <span style="color: #ff0000;">&quot;1&quot;</span> <span style="color: #7a0874; font-weight: bold;">&#93;</span> <span style="color: #7a0874; font-weight: bold;">&#41;</span>; <span style="color: #000000; font-weight: bold;">then</span> 
   <span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;IP forwarding not enabled yet enabling forwarding now&quot;</span>
   <span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #000000;">1</span> <span style="color: #000000; font-weight: bold;">&gt;</span> <span style="color: #000000; font-weight: bold;">/</span>proc<span style="color: #000000; font-weight: bold;">/</span>sys<span style="color: #000000; font-weight: bold;">/</span>net<span style="color: #000000; font-weight: bold;">/</span>ipv4<span style="color: #000000; font-weight: bold;">/</span>ip_forward
 <span style="color: #000000; font-weight: bold;">fi</span>
&nbsp;
&nbsp;
<span style="color: #666666; font-style: italic;">#--------------- Firewall default --------------------#</span>
&nbsp;
 <span style="color: #666666; font-style: italic;"># Default policy: ACCEPT</span>
 <span style="color: #007800;">$IPTABLES</span> <span style="color: #660033;">-P</span> FORWARD ACCEPT
 <span style="color: #007800;">$IPTABLES</span> <span style="color: #660033;">-P</span> INPUT ACCEPT
 <span style="color: #007800;">$IPTABLES</span> <span style="color: #660033;">-P</span> OUTPUT ACCEPT
&nbsp;
 <span style="color: #666666; font-style: italic;"># Flush</span>
 <span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;Flushing all rules&quot;</span>
 <span style="color: #007800;">$IPTABLES</span> <span style="color: #660033;">-F</span>
 <span style="color: #007800;">$IPTABLES</span> <span style="color: #660033;">-t</span> mangle <span style="color: #660033;">-F</span>
 <span style="color: #007800;">$IPTABLES</span> <span style="color: #660033;">-t</span> nat <span style="color: #660033;">-F</span>
 <span style="color: #007800;">$IPTABLES</span> <span style="color: #660033;">-F</span> FORWARD
 <span style="color: #007800;">$IPTABLES</span> <span style="color: #660033;">-F</span> INPUT
 <span style="color: #007800;">$IPTABLES</span> <span style="color: #660033;">-F</span> OUTPUT
&nbsp;
 <span style="color: #666666; font-style: italic;"># Default policy: ACCEPT</span>
 <span style="color: #007800;">$IPTABLES</span> <span style="color: #660033;">-P</span> FORWARD ACCEPT
 <span style="color: #007800;">$IPTABLES</span> <span style="color: #660033;">-P</span> INPUT ACCEPT
 <span style="color: #007800;">$IPTABLES</span> <span style="color: #660033;">-P</span> OUTPUT ACCEPT
<span style="color: #666666; font-style: italic;">#-----------------------------------------------------#</span>
&nbsp;
 <span style="color: #666666; font-style: italic;"># high-volumes</span>
 <span style="color: #007800;">$IPTABLES</span> <span style="color: #660033;">-N</span> Aforward
&nbsp;
 <span style="color: #666666; font-style: italic;">#allow fragmentation-needed</span>
 <span style="color: #007800;">$IPTABLES</span> <span style="color: #660033;">-A</span> Aforward <span style="color: #660033;">-p</span> icmp <span style="color: #660033;">--icmp-type</span> fragmentation-needed <span style="color: #660033;">-j</span> ACCEPT
&nbsp;
<span style="color: #000000; font-weight: bold;">fi</span>
&nbsp;
<span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;Start setting VPN Client rules&quot;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">#-----------------------------------------------------#</span>
<span style="color: #666666; font-style: italic;">#       VPN CLIENT RULES FROM HERE                    #</span>
<span style="color: #666666; font-style: italic;">#-----------------------------------------------------#</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">if</span> <span style="color: #7a0874; font-weight: bold;">&#40;</span> <span style="color: #7a0874; font-weight: bold;">&#91;</span> <span style="color: #007800;">$CMD</span> = <span style="color: #ff0000;">&quot;VPN&quot;</span> <span style="color: #660033;">-o</span> <span style="color: #007800;">$CMD</span> = <span style="color: #ff0000;">&quot;start&quot;</span> <span style="color: #7a0874; font-weight: bold;">&#93;</span> <span style="color: #7a0874; font-weight: bold;">&#41;</span>; <span style="color: #000000; font-weight: bold;">then</span>
        <span style="color: #666666; font-style: italic;">####################################################</span>
        <span style="color: #666666; font-style: italic;"># VPN Clients</span>
        <span style="color: #666666; font-style: italic;">#########################</span>
        <span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot; - Setting rules for VPN Clients&quot;</span>
        <span style="color: #007800;">$IPTABLES</span> <span style="color: #660033;">-F</span> vpn-clients
        <span style="color: #007800;">$IPTABLES</span> <span style="color: #660033;">-X</span> vpn-clients
        <span style="color: #007800;">$IPTABLES</span> <span style="color: #660033;">-N</span> vpn-clients
        <span style="color: #000000; font-weight: bold;">if</span> <span style="color: #7a0874; font-weight: bold;">&#40;</span> <span style="color: #7a0874; font-weight: bold;">&#91;</span> <span style="color: #007800;">$CMD</span> = <span style="color: #ff0000;">&quot;start&quot;</span> <span style="color: #7a0874; font-weight: bold;">&#93;</span> <span style="color: #7a0874; font-weight: bold;">&#41;</span>; <span style="color: #000000; font-weight: bold;">then</span>
                <span style="color: #000000; font-weight: bold;">for</span> ip <span style="color: #000000; font-weight: bold;">in</span> 192.168.255.200 192.168.255.201 192.168.255.202 192.168.255.203 192.168.255.204 192.168.255.205 192.168.255.206 192.168.255.207 192.168.255.208 192.168.255.209 192.168.255.210
                    <span style="color: #000000; font-weight: bold;">do</span>
                        <span style="color: #007800;">$IPTABLES</span> <span style="color: #660033;">-A</span> FORWARD <span style="color: #660033;">-s</span> <span style="color: #007800;">$ip</span> <span style="color: #660033;">-j</span> vpn-clients
                        <span style="color: #007800;">$IPTABLES</span> <span style="color: #660033;">-A</span> FORWARD <span style="color: #660033;">-d</span> <span style="color: #007800;">$ip</span> <span style="color: #660033;">-j</span> vpn-clients
                <span style="color: #000000; font-weight: bold;">done</span>
        <span style="color: #000000; font-weight: bold;">fi</span>
&nbsp;
        <span style="color: #666666; font-style: italic;"># YOUR RULES GO HERE</span>
&nbsp;
        <span style="color: #666666; font-style: italic;"># HTTP to a local webserver (for example)</span>
        <span style="color: #007800;">$IPTABLES</span> <span style="color: #660033;">-A</span> vpn-clients <span style="color: #660033;">-p</span> tcp <span style="color: #660033;">-d</span> 192.168.255.10 <span style="color: #660033;">--dport</span> <span style="color: #000000;">80</span> <span style="color: #660033;">-j</span> ACCEPT
        <span style="color: #007800;">$IPTABLES</span> <span style="color: #660033;">-A</span> vpn-clients <span style="color: #660033;">-p</span> tcp <span style="color: #660033;">-s</span> 192.168.255.10 <span style="color: #660033;">--sport</span> <span style="color: #000000;">80</span> <span style="color: #000000; font-weight: bold;">!</span> <span style="color: #660033;">--syn</span> <span style="color: #660033;">-j</span> ACCEPT
&nbsp;
        <span style="color: #666666; font-style: italic;"># ALLOW Ping</span>
        <span style="color: #007800;">$IPTABLES</span> <span style="color: #660033;">-A</span> vpn-clients <span style="color: #660033;">-p</span> icmp <span style="color: #660033;">-j</span> ACCEPT
&nbsp;
        <span style="color: #666666; font-style: italic;"># DROP ALL Other</span>
        <span style="color: #007800;">$IPTABLES</span> <span style="color: #660033;">-A</span> vpn-clients <span style="color: #660033;">-j</span> LOG <span style="color: #660033;">--log-prefix</span> <span style="color: #ff0000;">&quot;[DROP-vpn-clients ]&quot;</span>
        <span style="color: #007800;">$IPTABLES</span> <span style="color: #660033;">-A</span> vpn-clients <span style="color: #660033;">-j</span> DROP
        <span style="color: #666666; font-style: italic;">#########################</span>
        <span style="color: #666666; font-style: italic;"># VPN range</span>
        <span style="color: #666666; font-style: italic;">####################################################</span>
<span style="color: #000000; font-weight: bold;">fi</span>
&nbsp;
<span style="color: #666666; font-style: italic;">#-----------------------------------------------------#</span>
<span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;Done setting VPN Client Rules&quot;</span>
<span style="color: #666666; font-style: italic;">#-----------------------------------------------------#</span>
<span style="color: #666666; font-style: italic;">#       VPN CLIENT RULES UNTIL HERE                   #</span>
<span style="color: #666666; font-style: italic;">#-----------------------------------------------------#</span>
&nbsp;
&nbsp;
<span style="color: #666666; font-style: italic;">#-----------------------------------------------------#</span>
<span style="color: #000000; font-weight: bold;">if</span> <span style="color: #7a0874; font-weight: bold;">&#40;</span> <span style="color: #7a0874; font-weight: bold;">&#91;</span> <span style="color: #007800;">$CMD</span> = <span style="color: #ff0000;">&quot;start&quot;</span> <span style="color: #7a0874; font-weight: bold;">&#93;</span> <span style="color: #7a0874; font-weight: bold;">&#41;</span>; <span style="color: #000000; font-weight: bold;">then</span>
        <span style="color: #666666; font-style: italic;">#********************************************************</span>
        <span style="color: #666666; font-style: italic;"># VPNServer local rules</span>
        <span style="color: #666666; font-style: italic;">#********************</span>
        <span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;Setting local rules&quot;</span>
        <span style="color: #666666; font-style: italic;"># ssh in</span>
        <span style="color: #007800;">$IPTABLES</span> <span style="color: #660033;">-A</span> INPUT <span style="color: #660033;">-p</span> tcp <span style="color: #660033;">-d</span> <span style="color: #007800;">$WAN_IP</span> <span style="color: #660033;">--dport</span> <span style="color: #000000;">22</span> <span style="color: #660033;">-j</span> ACCEPT
        <span style="color: #007800;">$IPTABLES</span> <span style="color: #660033;">-A</span> OUTPUT <span style="color: #660033;">-p</span> tcp <span style="color: #660033;">-s</span> <span style="color: #007800;">$WAN_IP</span> <span style="color: #660033;">--sport</span> <span style="color: #000000;">22</span> <span style="color: #000000; font-weight: bold;">!</span> <span style="color: #660033;">--syn</span> <span style="color: #660033;">-j</span> ACCEPT
&nbsp;
        <span style="color: #666666; font-style: italic;"># VPN in</span>
        <span style="color: #007800;">$IPTABLES</span> <span style="color: #660033;">-A</span> INPUT <span style="color: #660033;">-p</span> tcp <span style="color: #660033;">-d</span> <span style="color: #007800;">$WAN_IP</span> <span style="color: #660033;">--dport</span> <span style="color: #000000;">443</span> <span style="color: #660033;">-j</span> ACCEPT
        <span style="color: #007800;">$IPTABLES</span> <span style="color: #660033;">-A</span> OUTPUT <span style="color: #660033;">-p</span> tcp <span style="color: #660033;">-s</span> <span style="color: #007800;">$WAN_IP</span> <span style="color: #660033;">--sport</span> <span style="color: #000000;">443</span> <span style="color: #660033;">-j</span> ACCEPT
&nbsp;
        <span style="color: #666666; font-style: italic;"># DNS lookups naar DNS</span>
        <span style="color: #000000; font-weight: bold;">for</span> i <span style="color: #000000; font-weight: bold;">in</span> <span style="color: #007800;">$DNSSERVERS</span>
        <span style="color: #000000; font-weight: bold;">do</span>
          <span style="color: #007800;">$IPTABLES</span> <span style="color: #660033;">-A</span> OUTPUT <span style="color: #660033;">-p</span> udp <span style="color: #660033;">--sport</span> <span style="color: #000000;">53</span> <span style="color: #660033;">-d</span> <span style="color: #007800;">$i</span> <span style="color: #660033;">-j</span> ACCEPT
          <span style="color: #007800;">$IPTABLES</span> <span style="color: #660033;">-A</span> INPUT  <span style="color: #660033;">-p</span> udp <span style="color: #660033;">-s</span> <span style="color: #007800;">$i</span> <span style="color: #660033;">--sport</span> <span style="color: #000000;">53</span> <span style="color: #660033;">-j</span> ACCEPT
          <span style="color: #007800;">$IPTABLES</span> <span style="color: #660033;">-A</span> OUTPUT <span style="color: #660033;">-p</span> udp <span style="color: #660033;">-d</span> <span style="color: #007800;">$i</span> <span style="color: #660033;">--dport</span> <span style="color: #000000;">53</span> <span style="color: #660033;">-j</span> ACCEPT
          <span style="color: #007800;">$IPTABLES</span> <span style="color: #660033;">-A</span> INPUT  <span style="color: #660033;">-p</span> udp <span style="color: #660033;">-s</span> <span style="color: #007800;">$i</span> <span style="color: #660033;">--dport</span> <span style="color: #000000;">53</span> <span style="color: #660033;">-j</span> ACCEPT
          <span style="color: #007800;">$IPTABLES</span> <span style="color: #660033;">-A</span> OUTPUT <span style="color: #660033;">-p</span> tcp <span style="color: #660033;">-d</span> <span style="color: #007800;">$i</span> <span style="color: #660033;">--dport</span> <span style="color: #000000;">53</span> <span style="color: #660033;">-j</span> ACCEPT
          <span style="color: #007800;">$IPTABLES</span> <span style="color: #660033;">-A</span> INPUT  <span style="color: #660033;">-p</span> tcp <span style="color: #660033;">-s</span> <span style="color: #007800;">$i</span> <span style="color: #660033;">--dport</span> <span style="color: #000000;">53</span> <span style="color: #660033;">-j</span> ACCEPT
          <span style="color: #007800;">$IPTABLES</span> <span style="color: #660033;">-A</span> OUTPUT <span style="color: #660033;">-p</span> tcp <span style="color: #660033;">--sport</span> <span style="color: #000000;">53</span> <span style="color: #660033;">-d</span> <span style="color: #007800;">$i</span> <span style="color: #000000; font-weight: bold;">!</span> <span style="color: #660033;">--syn</span> <span style="color: #660033;">-j</span> ACCEPT
          <span style="color: #007800;">$IPTABLES</span> <span style="color: #660033;">-A</span> OUTPUT <span style="color: #660033;">-p</span> udp <span style="color: #660033;">--dport</span> <span style="color: #000000;">123</span> <span style="color: #660033;">-j</span> ACCEPT
          <span style="color: #007800;">$IPTABLES</span> <span style="color: #660033;">-A</span> INPUT <span style="color: #660033;">-p</span> udp <span style="color: #660033;">--sport</span> <span style="color: #000000;">123</span> <span style="color: #660033;">-j</span> ACCEPT
        <span style="color: #000000; font-weight: bold;">done</span>
&nbsp;
        <span style="color: #666666; font-style: italic;"># local everything</span>
        <span style="color: #007800;">$IPTABLES</span> <span style="color: #660033;">-A</span> OUTPUT <span style="color: #660033;">-p</span> tcp <span style="color: #660033;">-d</span> 127.0.0.1 <span style="color: #660033;">-s</span> 127.0.0.1 <span style="color: #660033;">-j</span> ACCEPT
        <span style="color: #007800;">$IPTABLES</span> <span style="color: #660033;">-A</span> INPUT <span style="color: #660033;">-p</span> tcp <span style="color: #660033;">-s</span> 127.0.0.1 <span style="color: #660033;">-d</span> 127.0.0.1 <span style="color: #660033;">-j</span> ACCEPT
        <span style="color: #007800;">$IPTABLES</span> <span style="color: #660033;">-A</span> INPUT <span style="color: #660033;">-p</span> tcp <span style="color: #660033;">-d</span> 127.0.0.1 <span style="color: #660033;">-s</span> 127.0.0.1 <span style="color: #660033;">-j</span> ACCEPT
        <span style="color: #007800;">$IPTABLES</span> <span style="color: #660033;">-A</span> OUTPUT <span style="color: #660033;">-p</span> tcp <span style="color: #660033;">-s</span> 127.0.0.1 <span style="color: #660033;">-d</span> 127.0.0.1 <span style="color: #660033;">-j</span> ACCEPT
&nbsp;
        <span style="color: #007800;">$IPTABLES</span> <span style="color: #660033;">-A</span> OUTPUT <span style="color: #660033;">-p</span> udp <span style="color: #660033;">-d</span> 127.0.0.1 <span style="color: #660033;">-s</span> 127.0.0.1 <span style="color: #660033;">-j</span> ACCEPT
        <span style="color: #007800;">$IPTABLES</span> <span style="color: #660033;">-A</span> INPUT <span style="color: #660033;">-p</span> udp <span style="color: #660033;">-s</span> 127.0.0.1 <span style="color: #660033;">-d</span> 127.0.0.1 <span style="color: #660033;">-j</span> ACCEPT
        <span style="color: #007800;">$IPTABLES</span> <span style="color: #660033;">-A</span> INPUT <span style="color: #660033;">-p</span> udp <span style="color: #660033;">-d</span> 127.0.0.1 <span style="color: #660033;">-s</span> 127.0.0.1 <span style="color: #660033;">-j</span> ACCEPT
        <span style="color: #007800;">$IPTABLES</span> <span style="color: #660033;">-A</span> OUTPUT <span style="color: #660033;">-p</span> udp <span style="color: #660033;">-s</span> 127.0.0.1 <span style="color: #660033;">-d</span> 127.0.0.1 <span style="color: #660033;">-j</span> ACCEPT
&nbsp;
        <span style="color: #007800;">$IPTABLES</span> <span style="color: #660033;">-A</span> OUTPUT <span style="color: #660033;">-p</span> icmp <span style="color: #660033;">-d</span> 127.0.0.1 <span style="color: #660033;">-s</span> 127.0.0.1 <span style="color: #660033;">-j</span> ACCEPT
        <span style="color: #007800;">$IPTABLES</span> <span style="color: #660033;">-A</span> INPUT <span style="color: #660033;">-p</span> icmp <span style="color: #660033;">-s</span> 127.0.0.1 <span style="color: #660033;">-d</span> 127.0.0.1 <span style="color: #660033;">-j</span> ACCEPT
        <span style="color: #007800;">$IPTABLES</span> <span style="color: #660033;">-A</span> INPUT <span style="color: #660033;">-p</span> icmp <span style="color: #660033;">-d</span> 127.0.0.1 <span style="color: #660033;">-s</span> 127.0.0.1 <span style="color: #660033;">-j</span> ACCEPT
        <span style="color: #007800;">$IPTABLES</span> <span style="color: #660033;">-A</span> OUTPUT <span style="color: #660033;">-p</span> icmp <span style="color: #660033;">-s</span> 127.0.0.1 <span style="color: #660033;">-d</span> 127.0.0.1 <span style="color: #660033;">-j</span> ACCEPT
&nbsp;
        <span style="color: #666666; font-style: italic;"># browse (apt, etc..)</span>
        <span style="color: #007800;">$IPTABLES</span> <span style="color: #660033;">-A</span> OUTPUT <span style="color: #660033;">-p</span> tcp <span style="color: #660033;">-s</span> <span style="color: #007800;">$WAN_IP</span> <span style="color: #660033;">--dport</span> <span style="color: #000000;">80</span> <span style="color: #660033;">-j</span> ACCEPT
        <span style="color: #007800;">$IPTABLES</span> <span style="color: #660033;">-A</span> INPUT <span style="color: #660033;">-p</span> tcp <span style="color: #660033;">-d</span> <span style="color: #007800;">$WAN_IP</span> <span style="color: #660033;">--sport</span> <span style="color: #000000;">80</span> <span style="color: #000000; font-weight: bold;">!</span> <span style="color: #660033;">--syn</span> <span style="color: #660033;">-j</span> ACCEPT
        <span style="color: #007800;">$IPTABLES</span> <span style="color: #660033;">-A</span> OUTPUT <span style="color: #660033;">-p</span> tcp <span style="color: #660033;">-s</span> <span style="color: #007800;">$WAN_IP</span> <span style="color: #660033;">--dport</span> <span style="color: #000000;">443</span> <span style="color: #660033;">-j</span> ACCEPT
        <span style="color: #007800;">$IPTABLES</span> <span style="color: #660033;">-A</span> INPUT <span style="color: #660033;">-p</span> tcp <span style="color: #660033;">-d</span> <span style="color: #007800;">$WAN_IP</span> <span style="color: #660033;">--sport</span> <span style="color: #000000;">443</span> <span style="color: #000000; font-weight: bold;">!</span> <span style="color: #660033;">--syn</span> <span style="color: #660033;">-j</span> ACCEPT
&nbsp;
        <span style="color: #666666; font-style: italic;"># ALLOW ICMP</span>
        <span style="color: #007800;">$IPTABLES</span> <span style="color: #660033;">-A</span> INPUT <span style="color: #660033;">-p</span> icmp <span style="color: #660033;">-j</span> ACCEPT
        <span style="color: #007800;">$IPTABLES</span> <span style="color: #660033;">-A</span> OUTPUT <span style="color: #660033;">-p</span> icmp <span style="color: #660033;">-j</span> ACCEPT
&nbsp;
        <span style="color: #666666; font-style: italic;"># deny rest</span>
        <span style="color: #007800;">$IPTABLES</span> <span style="color: #660033;">-A</span> INPUT <span style="color: #660033;">-j</span> LOG <span style="color: #660033;">--log-prefix</span> <span style="color: #ff0000;">&quot;[DROP-INPUT-WAN] &quot;</span>
        <span style="color: #007800;">$IPTABLES</span> <span style="color: #660033;">-A</span> INPUT <span style="color: #660033;">-j</span> DROP
        <span style="color: #007800;">$IPTABLES</span> <span style="color: #660033;">-A</span> OUTPUT <span style="color: #660033;">-j</span> LOG <span style="color: #660033;">--log-prefix</span> <span style="color: #ff0000;">&quot;[DROP-OUTPUT-WAN] &quot;</span>
        <span style="color: #007800;">$IPTABLES</span> <span style="color: #660033;">-A</span> OUTPUT <span style="color: #660033;">-j</span> DROP
        <span style="color: #666666; font-style: italic;">#$IPTABLES -A FORWARD -j LOG --log-prefix &quot;[DROP-FORWARD-WAN] &quot;</span>
        <span style="color: #007800;">$IPTABLES</span> <span style="color: #660033;">-A</span> FORWARD <span style="color: #660033;">-j</span> DROP
&nbsp;
        <span style="color: #666666; font-style: italic;"># Reset default policy: DROP</span>
        <span style="color: #007800;">$IPTABLES</span> <span style="color: #660033;">-P</span> FORWARD DROP
        <span style="color: #007800;">$IPTABLES</span> <span style="color: #660033;">-P</span> INPUT DROP
        <span style="color: #007800;">$IPTABLES</span> <span style="color: #660033;">-P</span> OUTPUT DROP
<span style="color: #000000; font-weight: bold;">fi</span>
<span style="color: #666666; font-style: italic;">#-----------------------------------------------------#</span>
&nbsp;
<span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;--------------------------------&quot;</span>
<span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;IPTABLES FIREWALL SCRIPT LOADED &quot;</span>
<span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;--------------------------------&quot;</span>
<span style="color: #666666; font-style: italic;">#-----------------------------------------------------#</span>
<span style="color: #666666; font-style: italic;">#eof</span>
<span style="color: #666666; font-style: italic;">#-----------------------------------------------------#</span></pre></div></div>

<p></div></div>
<p>Then make the script executable and add the firewall to run at startup</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #c20cb9; font-weight: bold;">chmod</span> <span style="color: #000000;">700</span> <span style="color: #000000; font-weight: bold;">/</span>opt<span style="color: #000000; font-weight: bold;">/</span>firwall<span style="color: #000000; font-weight: bold;">/</span>localfw
<span style="color: #c20cb9; font-weight: bold;">vi</span> <span style="color: #000000; font-weight: bold;">/</span>etc<span style="color: #000000; font-weight: bold;">/</span>rc.local <span style="color: #7a0874; font-weight: bold;">&#40;</span>add <span style="color: #000000; font-weight: bold;">&lt;</span>strong<span style="color: #000000; font-weight: bold;">&gt;/</span>opt<span style="color: #000000; font-weight: bold;">/</span>firewall<span style="color: #000000; font-weight: bold;">/</span>localfw<span style="color: #000000; font-weight: bold;">&lt;/</span>strong<span style="color: #000000; font-weight: bold;">&gt;</span> just before <span style="color: #7a0874; font-weight: bold;">exit</span> <span style="color: #000000;">0</span><span style="color: #7a0874; font-weight: bold;">&#41;</span></pre></div></div>

<h3>VPN status</h3>
<p>This script will show you some statistics on the VPN server.</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #c20cb9; font-weight: bold;">vi</span> <span style="color: #000000; font-weight: bold;">/</span>usr<span style="color: #000000; font-weight: bold;">/</span>local<span style="color: #000000; font-weight: bold;">/</span>bin<span style="color: #000000; font-weight: bold;">/</span>openvpn-status</pre></div></div>

<h4 class="toggle"><a href="#">openvpn-status (Click to expand)</a></h4><div class="toggle_body"><div class="block"></p>

<div class="wp_syntax"><div class="code"><pre class="python" style="font-family:monospace;"><span style="color: #808080; font-style: italic;">#!/usr/bin/env python</span>
<span style="color: #808080; font-style: italic;"># -*- coding: utf-8 -*-</span>
&nbsp;
STATUS = <span style="color: #483d8b;">&quot;/var/log/openvpn-status.log&quot;</span>
&nbsp;
status_file = <span style="color: #008000;">open</span><span style="color: black;">&#40;</span>STATUS, <span style="color: #483d8b;">'r'</span><span style="color: black;">&#41;</span>
stats = status_file.<span style="color: black;">readlines</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span>
status_file.<span style="color: black;">close</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span>
&nbsp;
hosts = <span style="color: black;">&#91;</span><span style="color: black;">&#93;</span>
&nbsp;
headers = <span style="color: black;">&#123;</span>
    <span style="color: #483d8b;">'cn'</span>:    <span style="color: #483d8b;">'Common Name'</span>,
    <span style="color: #483d8b;">'virt'</span>:  <span style="color: #483d8b;">'Virtual Address'</span>,
    <span style="color: #483d8b;">'real'</span>:  <span style="color: #483d8b;">'Real Address'</span>,
    <span style="color: #483d8b;">'sent'</span>:  <span style="color: #483d8b;">'Sent'</span>,
    <span style="color: #483d8b;">'recv'</span>:  <span style="color: #483d8b;">'Received'</span>,
    <span style="color: #483d8b;">'since'</span>: <span style="color: #483d8b;">'Connected Since'</span>
<span style="color: black;">&#125;</span>
&nbsp;
sizes = <span style="color: black;">&#91;</span>
    <span style="color: black;">&#40;</span><span style="color: #ff4500;">1</span><span style="color: #66cc66;">&lt;&lt;</span>50L, <span style="color: #483d8b;">'PB'</span><span style="color: black;">&#41;</span>,
    <span style="color: black;">&#40;</span><span style="color: #ff4500;">1</span><span style="color: #66cc66;">&lt;&lt;</span>40L, <span style="color: #483d8b;">'TB'</span><span style="color: black;">&#41;</span>,
    <span style="color: black;">&#40;</span><span style="color: #ff4500;">1</span><span style="color: #66cc66;">&lt;&lt;</span>30L, <span style="color: #483d8b;">'GB'</span><span style="color: black;">&#41;</span>,
    <span style="color: black;">&#40;</span><span style="color: #ff4500;">1</span><span style="color: #66cc66;">&lt;&lt;</span>20L, <span style="color: #483d8b;">'MB'</span><span style="color: black;">&#41;</span>,
    <span style="color: black;">&#40;</span><span style="color: #ff4500;">1</span><span style="color: #66cc66;">&lt;&lt;</span>10L, <span style="color: #483d8b;">'KB'</span><span style="color: black;">&#41;</span>,
    <span style="color: black;">&#40;</span><span style="color: #ff4500;">1</span>,       <span style="color: #483d8b;">'B'</span><span style="color: black;">&#41;</span>
<span style="color: black;">&#93;</span>
&nbsp;
<span style="color: #ff7700;font-weight:bold;">def</span> byte2str<span style="color: black;">&#40;</span>size<span style="color: black;">&#41;</span>:
    <span style="color: #ff7700;font-weight:bold;">for</span> f, suf <span style="color: #ff7700;font-weight:bold;">in</span> sizes:
        <span style="color: #ff7700;font-weight:bold;">if</span> size <span style="color: #66cc66;">&gt;</span>= f:
            <span style="color: #ff7700;font-weight:bold;">break</span>
&nbsp;
    <span style="color: #ff7700;font-weight:bold;">return</span> <span style="color: #483d8b;">&quot;%.2f %s&quot;</span> <span style="color: #66cc66;">%</span> <span style="color: black;">&#40;</span>size / <span style="color: #008000;">float</span><span style="color: black;">&#40;</span>f<span style="color: black;">&#41;</span>, suf<span style="color: black;">&#41;</span>
&nbsp;
<span style="color: #ff7700;font-weight:bold;">for</span> line <span style="color: #ff7700;font-weight:bold;">in</span> stats:
    cols = line.<span style="color: black;">split</span><span style="color: black;">&#40;</span><span style="color: #483d8b;">','</span><span style="color: black;">&#41;</span>
&nbsp;
    <span style="color: #ff7700;font-weight:bold;">if</span> <span style="color: #008000;">len</span><span style="color: black;">&#40;</span>cols<span style="color: black;">&#41;</span> == <span style="color: #ff4500;">5</span> <span style="color: #ff7700;font-weight:bold;">and</span> <span style="color: #ff7700;font-weight:bold;">not</span> line.<span style="color: black;">startswith</span><span style="color: black;">&#40;</span><span style="color: #483d8b;">'Common Name'</span><span style="color: black;">&#41;</span>:
        host  = <span style="color: black;">&#123;</span><span style="color: black;">&#125;</span>
        host<span style="color: black;">&#91;</span><span style="color: #483d8b;">'cn'</span><span style="color: black;">&#93;</span>    = cols<span style="color: black;">&#91;</span><span style="color: #ff4500;">0</span><span style="color: black;">&#93;</span>
        host<span style="color: black;">&#91;</span><span style="color: #483d8b;">'real'</span><span style="color: black;">&#93;</span>  = cols<span style="color: black;">&#91;</span><span style="color: #ff4500;">1</span><span style="color: black;">&#93;</span>.<span style="color: black;">split</span><span style="color: black;">&#40;</span><span style="color: #483d8b;">':'</span><span style="color: black;">&#41;</span><span style="color: black;">&#91;</span><span style="color: #ff4500;">0</span><span style="color: black;">&#93;</span>
        host<span style="color: black;">&#91;</span><span style="color: #483d8b;">'recv'</span><span style="color: black;">&#93;</span>  = byte2str<span style="color: black;">&#40;</span><span style="color: #008000;">int</span><span style="color: black;">&#40;</span>cols<span style="color: black;">&#91;</span><span style="color: #ff4500;">2</span><span style="color: black;">&#93;</span><span style="color: black;">&#41;</span><span style="color: black;">&#41;</span>
        host<span style="color: black;">&#91;</span><span style="color: #483d8b;">'sent'</span><span style="color: black;">&#93;</span>  = byte2str<span style="color: black;">&#40;</span><span style="color: #008000;">int</span><span style="color: black;">&#40;</span>cols<span style="color: black;">&#91;</span><span style="color: #ff4500;">3</span><span style="color: black;">&#93;</span><span style="color: black;">&#41;</span><span style="color: black;">&#41;</span>
        host<span style="color: black;">&#91;</span><span style="color: #483d8b;">'since'</span><span style="color: black;">&#93;</span> = cols<span style="color: black;">&#91;</span><span style="color: #ff4500;">4</span><span style="color: black;">&#93;</span>.<span style="color: black;">strip</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span>
        hosts.<span style="color: black;">append</span><span style="color: black;">&#40;</span>host<span style="color: black;">&#41;</span>
&nbsp;
    <span style="color: #ff7700;font-weight:bold;">if</span> <span style="color: #008000;">len</span><span style="color: black;">&#40;</span>cols<span style="color: black;">&#41;</span> == <span style="color: #ff4500;">4</span> <span style="color: #ff7700;font-weight:bold;">and</span> <span style="color: #ff7700;font-weight:bold;">not</span> line.<span style="color: black;">startswith</span><span style="color: black;">&#40;</span><span style="color: #483d8b;">'Virtual Address'</span><span style="color: black;">&#41;</span>:
        <span style="color: #ff7700;font-weight:bold;">for</span> h <span style="color: #ff7700;font-weight:bold;">in</span> hosts:
            <span style="color: #ff7700;font-weight:bold;">if</span> h<span style="color: black;">&#91;</span><span style="color: #483d8b;">'cn'</span><span style="color: black;">&#93;</span> == cols<span style="color: black;">&#91;</span><span style="color: #ff4500;">1</span><span style="color: black;">&#93;</span>:
                h<span style="color: black;">&#91;</span><span style="color: #483d8b;">'virt'</span><span style="color: black;">&#93;</span> = cols<span style="color: black;">&#91;</span><span style="color: #ff4500;">0</span><span style="color: black;">&#93;</span>
&nbsp;
fmt = <span style="color: #483d8b;">&quot;%(cn)-25s %(virt)-18s %(real)-15s %(sent)13s %(recv)13s %(since)25s&quot;</span>
<span style="color: #ff7700;font-weight:bold;">print</span> fmt <span style="color: #66cc66;">%</span> headers
<span style="color: #ff7700;font-weight:bold;">print</span> <span style="color: #483d8b;">&quot;<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span>.<span style="color: black;">join</span><span style="color: black;">&#40;</span><span style="color: black;">&#91;</span>fmt <span style="color: #66cc66;">%</span> h <span style="color: #ff7700;font-weight:bold;">for</span> h <span style="color: #ff7700;font-weight:bold;">in</span> hosts<span style="color: black;">&#93;</span><span style="color: black;">&#41;</span></pre></div></div>

<p></div></div>
<p>Now make the script executable.</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #c20cb9; font-weight: bold;">chmod</span> <span style="color: #000000;">700</span> <span style="color: #000000; font-weight: bold;">/</span>usr<span style="color: #000000; font-weight: bold;">/</span>local<span style="color: #000000; font-weight: bold;">/</span>bin<span style="color: #000000; font-weight: bold;">/</span>openvpn-status</pre></div></div>

<p>If you run it and a client is connected you will see something like this:</p>
<pre># /usr/local/bin/openvpn-status
Common Name               Virtual Address    Real Address             Sent      Received           Connected Since
johndoe                   00:00:00:00:00:00  1.2.3.4          1.11 MB     489.49 KB  Wed Dec 11 13:26:42 2011
</pre>
<h3>References</h3>
<ul class="list-black">
<ul>
<li><a href="http://www.openvpn.net/index.php/open-source/documentation.html" title="OpenVPN.net">OpenVPN.net</a></li>
<li><a href="http://code.geek.sh/2009/07/simple-openvpn-server-statistics/" title="Code.geek.sh">code.geek.sh</a></li>
</ul>
</ul>
]]></content:encoded>
			<wfw:commentRss>http://www.troublenow.org/362/howto-setup-openvpn-in-bridge-mode-on-debian/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>OpenVPN bridge and VMware ESXi</title>
		<link>http://www.troublenow.org/344/openvpn_bridge_and_vmware_esxi/</link>
		<comments>http://www.troublenow.org/344/openvpn_bridge_and_vmware_esxi/#comments</comments>
		<pubDate>Thu, 20 Oct 2011 16:37:35 +0000</pubDate>
		<dc:creator>Arno Haverlach</dc:creator>
				<category><![CDATA[linux]]></category>
		<category><![CDATA[OpenVPN]]></category>
		<category><![CDATA[VMware]]></category>
		<category><![CDATA[vmware]]></category>

		<guid isPermaLink="false">http://www.troublenow.org/?p=344</guid>
		<description><![CDATA[When you configure a bridged OpenVPN setup on a VMware ESXi (vSphere Hypervisor) you will notice that you can&#8217;t reach anything over the VPN except the OpenVPN host. This is because VMware by default prevents the NIC to go into promiscuous mode so the bridge won&#8217;t work. To fix this you need to change the VMware security [...]]]></description>
			<content:encoded><![CDATA[<p>When you configure a bridged OpenVPN setup on a VMware ESXi (vSphere Hypervisor) you will notice that you can&#8217;t reach anything over the VPN except the OpenVPN host.</p>
<p>This is because VMware by default prevents the NIC to go into promiscuous mode so the bridge won&#8217;t work.<br />
To fix this you need to change the VMware security policy to accept promiscuous mode.</p>
<ol>
<li>Go to &#8216;Configuration&#8217; in the vSphere client.</li>
<li>Select &#8216;Networking&#8217; on the left.</li>
<li>Click &#8216;Properties&#8217;<br />
<img class="alignnone size-large wp-image-345" title="esxi-promiscous01" src="http://www.troublenow.org/wp-content/uploads/2011/10/esxi-promiscous01-600x162.png" alt="" width="420" height="113" /></li>
<li>Select &#8216;VM Network&#8217; on the &#8216;Ports&#8217; tab.</li>
<li>Click &#8216;Edit&#8217;<br />
<img class="alignnone size-large wp-image-346" title="esxi-promiscous02" src="http://www.troublenow.org/wp-content/uploads/2011/10/esxi-promiscous02-600x539.png" alt="" width="420" height="377" /></li>
<li>Go to the &#8216;Security&#8217; tab.</li>
<li>Select the check box for &#8216;Promiscuous Mode&#8217; and select &#8216;Accept&#8217;.<br />
<img class="alignnone size-full wp-image-347" title="esxi-promiscous03" src="http://www.troublenow.org/wp-content/uploads/2011/10/esxi-promiscous03.png" alt="" width="434" height="205" /></li>
</ol>
]]></content:encoded>
			<wfw:commentRss>http://www.troublenow.org/344/openvpn_bridge_and_vmware_esxi/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Installing VMware server 2.0.2 on debian 6.0.1 X64</title>
		<link>http://www.troublenow.org/316/installing-vmware-server-2-0-2-on-debian-6-0-1-x64/</link>
		<comments>http://www.troublenow.org/316/installing-vmware-server-2-0-2-on-debian-6-0-1-x64/#comments</comments>
		<pubDate>Sat, 14 May 2011 15:06:23 +0000</pubDate>
		<dc:creator>Arno Haverlach</dc:creator>
				<category><![CDATA[debian]]></category>
		<category><![CDATA[linux]]></category>
		<category><![CDATA[Debian]]></category>
		<category><![CDATA[vmware]]></category>

		<guid isPermaLink="false">http://www.troublenow.org/?p=316</guid>
		<description><![CDATA[Download VMware-server-2.0.2-203138.x86_64.tar.gz from the vmware website and place it in /usr/src (you need to register on the VMware website before you can download) Download my install file below and unpack it to /usr/src: cd /usr/src wget http://www.troublenow.org/files/vmware/vmware2.0.2-on-debian6.0.1.tar.gz tar xvzf vmware2.0.2-on-debian6.0.1.tar.gz cd /usr/src/vmware2 sh install-vmware-2.0.2.sh This wil unpack the files, patch them for debian 6.0.1 and [...]]]></description>
			<content:encoded><![CDATA[<p><img class="alignleft size-thumbnail wp-image-323" title="Vmware" src="http://www.troublenow.org/wp-content/uploads/2011/05/vmware-boxes-58x58.png" alt="" width="58" height="58" /><br />
Download VMware-server-2.0.2-203138.x86_64.tar.gz from the vmware website and place it in /usr/src (you need to register on the VMware website before you can download)</p>
<p>Download my install file below and unpack it to /usr/src:</p>
<pre>cd /usr/src
wget http://www.troublenow.org/files/vmware/vmware2.0.2-on-debian6.0.1.tar.gz
tar xvzf vmware2.0.2-on-debian6.0.1.tar.gz
cd /usr/src/vmware2
sh install-vmware-2.0.2.sh</pre>
<p>This wil unpack the files, patch them for debian 6.0.1 and start the vmware installation.<br />
Answer all the questions during the vmware install and the installation should complete.</p>
<p>Now reboot the server and you should be ready to go.</p>
<p>The above vmware2.0.2-on-debian6.0.1.tar.gz file has the following content:</p>
<pre>00-vmware-2.6.32_functional.diff
01-vmware-2.6.32_cosmetic.diff
02-vmnet-include.diff
install-vmware-2.0.2.sh
patch-vmware_2.6.3x.sh
vmware-config.pl.diff</pre>
<p>All files except install-vmware-2.0.2.sh are from <a title="nerdbynature.de" href="http://nerdbynature.de/bits/2.6.32-22/" target="_blank">NerdbyNature.de</a> with some small modifications.<br />
install-vmware-2.0.2.sh is a simple setup script I created for easy install.</p>
<p>References:</p>
<ul>
<li><a title="communities.vmware.com" href="http://communities.vmware.com/index.jspa" target="_blank">communities.vmware.com</a></li>
<li><a title="nerdbynature.de" href="http://nerdbynature.de/bits/2.6.32-22/" target="_blank">NerdbyNature.de</a></li>
</ul>
]]></content:encoded>
			<wfw:commentRss>http://www.troublenow.org/316/installing-vmware-server-2-0-2-on-debian-6-0-1-x64/feed/</wfw:commentRss>
		<slash:comments>33</slash:comments>
		</item>
		<item>
		<title>IPv6 Subnets</title>
		<link>http://www.troublenow.org/299/ipv6-subnets/</link>
		<comments>http://www.troublenow.org/299/ipv6-subnets/#comments</comments>
		<pubDate>Sun, 24 Apr 2011 22:32:16 +0000</pubDate>
		<dc:creator>Arno Haverlach</dc:creator>
				<category><![CDATA[Networking]]></category>
		<category><![CDATA[Ipv6 subnet]]></category>

		<guid isPermaLink="false">http://www.troublenow.org/?p=299</guid>
		<description><![CDATA[Just a quick ipv6 subnet cheatsheet. XXXX:XXXX:XXXX:XXXX:XXXX:XXXX:XXXX:XXXX &#124;&#124;&#124; &#124;&#124;&#124;&#124; &#124;&#124;&#124;&#124; &#124;&#124;&#124;&#124; &#124;&#124;&#124;&#124; &#124;&#124;&#124;&#124; &#124;&#124;&#124;&#124; &#124;&#124;&#124; &#124;&#124;&#124;&#124; &#124;&#124;&#124;&#124; &#124;&#124;&#124;&#124; &#124;&#124;&#124;&#124; &#124;&#124;&#124;&#124; &#124;&#124;&#124;128--1 &#124;&#124;&#124; &#124;&#124;&#124;&#124; &#124;&#124;&#124;&#124; &#124;&#124;&#124;&#124; &#124;&#124;&#124;&#124; &#124;&#124;&#124;&#124; &#124;&#124;124---16 &#124;&#124;&#124; &#124;&#124;&#124;&#124; &#124;&#124;&#124;&#124; &#124;&#124;&#124;&#124; &#124;&#124;&#124;&#124; &#124;&#124;&#124;&#124; &#124;120----256 &#124;&#124;&#124; &#124;&#124;&#124;&#124; &#124;&#124;&#124;&#124; &#124;&#124;&#124;&#124; &#124;&#124;&#124;&#124; &#124;&#124;&#124;&#124; 116-----4,096 &#124;&#124;&#124; &#124;&#124;&#124;&#124; &#124;&#124;&#124;&#124; &#124;&#124;&#124;&#124; &#124;&#124;&#124;&#124; &#124;&#124;&#124;112-------65,536 &#124;&#124;&#124; &#124;&#124;&#124;&#124; &#124;&#124;&#124;&#124; &#124;&#124;&#124;&#124; &#124;&#124;&#124;&#124; &#124;&#124;108--------1,048,576 &#124;&#124;&#124; [...]]]></description>
			<content:encoded><![CDATA[<p>Just a quick ipv6 subnet cheatsheet.</p>

<div class="wp_syntax"><div class="code"><pre class="perl" style="font-family:monospace;">XXXX<span style="color: #339933;">:</span>XXXX<span style="color: #339933;">:</span>XXXX<span style="color: #339933;">:</span>XXXX<span style="color: #339933;">:</span>XXXX<span style="color: #339933;">:</span>XXXX<span style="color: #339933;">:</span>XXXX<span style="color: #339933;">:</span>XXXX
      <span style="color: #339933;">|||</span> <span style="color: #339933;">||||</span> <span style="color: #339933;">||||</span> <span style="color: #339933;">||||</span> <span style="color: #339933;">||||</span> <span style="color: #339933;">||||</span> <span style="color: #339933;">||||</span>
      <span style="color: #339933;">|||</span> <span style="color: #339933;">||||</span> <span style="color: #339933;">||||</span> <span style="color: #339933;">||||</span> <span style="color: #339933;">||||</span> <span style="color: #339933;">||||</span> <span style="color: #339933;">|||</span><span style="color: #cc66cc;">128</span><span style="color: #339933;">--</span><span style="color: #cc66cc;">1</span>
      <span style="color: #339933;">|||</span> <span style="color: #339933;">||||</span> <span style="color: #339933;">||||</span> <span style="color: #339933;">||||</span> <span style="color: #339933;">||||</span> <span style="color: #339933;">||||</span> <span style="color: #339933;">||</span><span style="color: #cc66cc;">124</span><span style="color: #339933;">---</span><span style="color: #cc66cc;">16</span>
      <span style="color: #339933;">|||</span> <span style="color: #339933;">||||</span> <span style="color: #339933;">||||</span> <span style="color: #339933;">||||</span> <span style="color: #339933;">||||</span> <span style="color: #339933;">||||</span> <span style="color: #339933;">|</span><span style="color: #cc66cc;">120</span><span style="color: #339933;">----</span><span style="color: #cc66cc;">256</span>
      <span style="color: #339933;">|||</span> <span style="color: #339933;">||||</span> <span style="color: #339933;">||||</span> <span style="color: #339933;">||||</span> <span style="color: #339933;">||||</span> <span style="color: #339933;">||||</span> <span style="color: #cc66cc;">116</span><span style="color: #339933;">-----</span><span style="color: #cc66cc;">4</span><span style="color: #339933;">,</span>096
      <span style="color: #339933;">|||</span> <span style="color: #339933;">||||</span> <span style="color: #339933;">||||</span> <span style="color: #339933;">||||</span> <span style="color: #339933;">||||</span> <span style="color: #339933;">|||</span><span style="color: #cc66cc;">112</span><span style="color: #339933;">-------</span><span style="color: #cc66cc;">65</span><span style="color: #339933;">,</span><span style="color: #cc66cc;">536</span>
      <span style="color: #339933;">|||</span> <span style="color: #339933;">||||</span> <span style="color: #339933;">||||</span> <span style="color: #339933;">||||</span> <span style="color: #339933;">||||</span> <span style="color: #339933;">||</span><span style="color: #cc66cc;">108</span><span style="color: #339933;">--------</span><span style="color: #cc66cc;">1</span><span style="color: #339933;">,</span>048<span style="color: #339933;">,</span><span style="color: #cc66cc;">576</span>
      <span style="color: #339933;">|||</span> <span style="color: #339933;">||||</span> <span style="color: #339933;">||||</span> <span style="color: #339933;">||||</span> <span style="color: #339933;">||||</span> <span style="color: #339933;">|</span><span style="color: #cc66cc;">104</span><span style="color: #339933;">---------</span><span style="color: #cc66cc;">16</span><span style="color: #339933;">,</span><span style="color: #cc66cc;">777</span><span style="color: #339933;">,</span><span style="color: #cc66cc;">216</span>
      <span style="color: #339933;">|||</span> <span style="color: #339933;">||||</span> <span style="color: #339933;">||||</span> <span style="color: #339933;">||||</span> <span style="color: #339933;">||||</span> <span style="color: #cc66cc;">100</span><span style="color: #339933;">----------</span><span style="color: #cc66cc;">268</span><span style="color: #339933;">,</span><span style="color: #cc66cc;">435</span><span style="color: #339933;">,</span><span style="color: #cc66cc;">456</span>
      <span style="color: #339933;">|||</span> <span style="color: #339933;">||||</span> <span style="color: #339933;">||||</span> <span style="color: #339933;">||||</span> <span style="color: #339933;">|||</span><span style="color: #cc66cc;">96</span><span style="color: #339933;">-------------</span><span style="color: #cc66cc;">4</span><span style="color: #339933;">,</span><span style="color: #cc66cc;">294</span><span style="color: #339933;">,</span><span style="color: #cc66cc;">967</span><span style="color: #339933;">,</span><span style="color: #cc66cc;">296</span>
      <span style="color: #339933;">|||</span> <span style="color: #339933;">||||</span> <span style="color: #339933;">||||</span> <span style="color: #339933;">||||</span> <span style="color: #339933;">||</span><span style="color: #cc66cc;">92</span><span style="color: #339933;">--------------</span><span style="color: #cc66cc;">68</span><span style="color: #339933;">,</span><span style="color: #cc66cc;">719</span><span style="color: #339933;">,</span><span style="color: #cc66cc;">476</span><span style="color: #339933;">,</span><span style="color: #cc66cc;">736</span>
      <span style="color: #339933;">|||</span> <span style="color: #339933;">||||</span> <span style="color: #339933;">||||</span> <span style="color: #339933;">||||</span> <span style="color: #339933;">|</span><span style="color: #cc66cc;">88</span><span style="color: #339933;">---------------</span><span style="color: #cc66cc;">1</span><span style="color: #339933;">,</span>099<span style="color: #339933;">,</span><span style="color: #cc66cc;">511</span><span style="color: #339933;">,</span><span style="color: #cc66cc;">627</span><span style="color: #339933;">,</span><span style="color: #cc66cc;">776</span>
      <span style="color: #339933;">|||</span> <span style="color: #339933;">||||</span> <span style="color: #339933;">||||</span> <span style="color: #339933;">||||</span> <span style="color: #cc66cc;">84</span><span style="color: #339933;">----------------</span><span style="color: #cc66cc;">17</span><span style="color: #339933;">,</span><span style="color: #cc66cc;">592</span><span style="color: #339933;">,</span><span style="color: #cc66cc;">186</span><span style="color: #339933;">,</span>044<span style="color: #339933;">,</span><span style="color: #cc66cc;">416</span>
      <span style="color: #339933;">|||</span> <span style="color: #339933;">||||</span> <span style="color: #339933;">||||</span> <span style="color: #339933;">|||</span><span style="color: #cc66cc;">80</span><span style="color: #339933;">------------------</span><span style="color: #cc66cc;">281</span><span style="color: #339933;">,</span><span style="color: #cc66cc;">474</span><span style="color: #339933;">,</span><span style="color: #cc66cc;">976</span><span style="color: #339933;">,</span><span style="color: #cc66cc;">710</span><span style="color: #339933;">,</span><span style="color: #cc66cc;">656</span>
      <span style="color: #339933;">|||</span> <span style="color: #339933;">||||</span> <span style="color: #339933;">||||</span> <span style="color: #339933;">||</span><span style="color: #cc66cc;">76</span><span style="color: #339933;">-------------------</span><span style="color: #cc66cc;">4</span><span style="color: #339933;">,</span><span style="color: #cc66cc;">503</span><span style="color: #339933;">,</span><span style="color: #cc66cc;">599</span><span style="color: #339933;">,</span><span style="color: #cc66cc;">627</span><span style="color: #339933;">,</span><span style="color: #cc66cc;">370</span><span style="color: #339933;">,</span><span style="color: #cc66cc;">496</span>
      <span style="color: #339933;">|||</span> <span style="color: #339933;">||||</span> <span style="color: #339933;">||||</span> <span style="color: #339933;">|</span><span style="color: #cc66cc;">72</span><span style="color: #339933;">--------------------</span><span style="color: #cc66cc;">72</span><span style="color: #339933;">,</span>057<span style="color: #339933;">,</span><span style="color: #cc66cc;">594</span><span style="color: #339933;">,</span>037<span style="color: #339933;">,</span><span style="color: #cc66cc;">927</span><span style="color: #339933;">,</span><span style="color: #cc66cc;">936</span>
      <span style="color: #339933;">|||</span> <span style="color: #339933;">||||</span> <span style="color: #339933;">||||</span> <span style="color: #cc66cc;">68</span><span style="color: #339933;">---------------------</span><span style="color: #cc66cc;">1</span><span style="color: #339933;">,</span><span style="color: #cc66cc;">152</span><span style="color: #339933;">,</span><span style="color: #cc66cc;">921</span><span style="color: #339933;">,</span><span style="color: #cc66cc;">504</span><span style="color: #339933;">,</span><span style="color: #cc66cc;">606</span><span style="color: #339933;">,</span><span style="color: #cc66cc;">846</span><span style="color: #339933;">,</span><span style="color: #cc66cc;">976</span>
      <span style="color: #339933;">|||</span> <span style="color: #339933;">||||</span> <span style="color: #339933;">|||</span><span style="color: #cc66cc;">64</span><span style="color: #339933;">-----------------------</span><span style="color: #cc66cc;">18</span><span style="color: #339933;">,</span><span style="color: #cc66cc;">446</span><span style="color: #339933;">,</span><span style="color: #cc66cc;">744</span><span style="color: #339933;">,</span>073<span style="color: #339933;">,</span><span style="color: #cc66cc;">709</span><span style="color: #339933;">,</span><span style="color: #cc66cc;">551</span><span style="color: #339933;">,</span><span style="color: #cc66cc;">616</span>
      <span style="color: #339933;">|||</span> <span style="color: #339933;">||||</span> <span style="color: #339933;">||</span><span style="color: #cc66cc;">60</span><span style="color: #339933;">------------------------</span><span style="color: #cc66cc;">295</span><span style="color: #339933;">,</span><span style="color: #cc66cc;">147</span><span style="color: #339933;">,</span><span style="color: #cc66cc;">905</span><span style="color: #339933;">,</span><span style="color: #cc66cc;">179</span><span style="color: #339933;">,</span><span style="color: #cc66cc;">352</span><span style="color: #339933;">,</span><span style="color: #cc66cc;">825</span><span style="color: #339933;">,</span><span style="color: #cc66cc;">856</span>
      <span style="color: #339933;">|||</span> <span style="color: #339933;">||||</span> <span style="color: #339933;">|</span><span style="color: #cc66cc;">56</span><span style="color: #339933;">-------------------------</span><span style="color: #cc66cc;">4</span><span style="color: #339933;">,</span><span style="color: #cc66cc;">722</span><span style="color: #339933;">,</span><span style="color: #cc66cc;">366</span><span style="color: #339933;">,</span><span style="color: #cc66cc;">482</span><span style="color: #339933;">,</span><span style="color: #cc66cc;">869</span><span style="color: #339933;">,</span><span style="color: #cc66cc;">645</span><span style="color: #339933;">,</span><span style="color: #cc66cc;">213</span><span style="color: #339933;">,</span><span style="color: #cc66cc;">696</span>
      <span style="color: #339933;">|||</span> <span style="color: #339933;">||||</span> <span style="color: #cc66cc;">52</span><span style="color: #339933;">--------------------------</span><span style="color: #cc66cc;">75</span><span style="color: #339933;">,</span><span style="color: #cc66cc;">557</span><span style="color: #339933;">,</span><span style="color: #cc66cc;">863</span><span style="color: #339933;">,</span><span style="color: #cc66cc;">725</span><span style="color: #339933;">,</span><span style="color: #cc66cc;">914</span><span style="color: #339933;">,</span><span style="color: #cc66cc;">323</span><span style="color: #339933;">,</span><span style="color: #cc66cc;">419</span><span style="color: #339933;">,</span><span style="color: #cc66cc;">136</span>
      <span style="color: #339933;">|||</span> <span style="color: #339933;">|||</span><span style="color: #cc66cc;">48</span><span style="color: #339933;">----------------------------</span><span style="color: #cc66cc;">1</span><span style="color: #339933;">,</span><span style="color: #cc66cc;">208</span><span style="color: #339933;">,</span><span style="color: #cc66cc;">925</span><span style="color: #339933;">,</span><span style="color: #cc66cc;">819</span><span style="color: #339933;">,</span><span style="color: #cc66cc;">614</span><span style="color: #339933;">,</span><span style="color: #cc66cc;">629</span><span style="color: #339933;">,</span><span style="color: #cc66cc;">174</span><span style="color: #339933;">,</span><span style="color: #cc66cc;">706</span><span style="color: #339933;">,</span><span style="color: #cc66cc;">176</span>
      <span style="color: #339933;">|||</span> <span style="color: #339933;">||</span><span style="color: #cc66cc;">44</span><span style="color: #339933;">-----------------------------</span><span style="color: #cc66cc;">19</span><span style="color: #339933;">,</span><span style="color: #cc66cc;">342</span><span style="color: #339933;">,</span><span style="color: #cc66cc;">813</span><span style="color: #339933;">,</span><span style="color: #cc66cc;">113</span><span style="color: #339933;">,</span><span style="color: #cc66cc;">834</span><span style="color: #339933;">,</span>066<span style="color: #339933;">,</span><span style="color: #cc66cc;">795</span><span style="color: #339933;">,</span><span style="color: #cc66cc;">298</span><span style="color: #339933;">,</span><span style="color: #cc66cc;">816</span>
      <span style="color: #339933;">|||</span> <span style="color: #339933;">|</span><span style="color: #cc66cc;">40</span><span style="color: #339933;">------------------------------</span><span style="color: #cc66cc;">309</span><span style="color: #339933;">,</span><span style="color: #cc66cc;">485</span><span style="color: #339933;">,</span>009<span style="color: #339933;">,</span><span style="color: #cc66cc;">821</span><span style="color: #339933;">,</span><span style="color: #cc66cc;">345</span><span style="color: #339933;">,</span>068<span style="color: #339933;">,</span><span style="color: #cc66cc;">724</span><span style="color: #339933;">,</span><span style="color: #cc66cc;">781</span><span style="color: #339933;">,</span>056
      <span style="color: #339933;">|||</span> <span style="color: #cc66cc;">36</span><span style="color: #339933;">-------------------------------</span><span style="color: #cc66cc;">4</span><span style="color: #339933;">,</span><span style="color: #cc66cc;">951</span><span style="color: #339933;">,</span><span style="color: #cc66cc;">760</span><span style="color: #339933;">,</span><span style="color: #cc66cc;">157</span><span style="color: #339933;">,</span><span style="color: #cc66cc;">141</span><span style="color: #339933;">,</span><span style="color: #cc66cc;">521</span><span style="color: #339933;">,</span>099<span style="color: #339933;">,</span><span style="color: #cc66cc;">596</span><span style="color: #339933;">,</span><span style="color: #cc66cc;">496</span><span style="color: #339933;">,</span><span style="color: #cc66cc;">896</span>
      <span style="color: #339933;">||</span><span style="color: #cc66cc;">32</span><span style="color: #339933;">---------------------------------</span><span style="color: #cc66cc;">79</span><span style="color: #339933;">,</span><span style="color: #cc66cc;">228</span><span style="color: #339933;">,</span><span style="color: #cc66cc;">162</span><span style="color: #339933;">,</span><span style="color: #cc66cc;">514</span><span style="color: #339933;">,</span><span style="color: #cc66cc;">264</span><span style="color: #339933;">,</span><span style="color: #cc66cc;">337</span><span style="color: #339933;">,</span><span style="color: #cc66cc;">593</span><span style="color: #339933;">,</span><span style="color: #cc66cc;">543</span><span style="color: #339933;">,</span><span style="color: #cc66cc;">950</span><span style="color: #339933;">,</span><span style="color: #cc66cc;">336</span>
      <span style="color: #339933;">|</span><span style="color: #cc66cc;">28</span><span style="color: #339933;">----------------------------------</span><span style="color: #cc66cc;">1</span><span style="color: #339933;">,</span><span style="color: #cc66cc;">267</span><span style="color: #339933;">,</span><span style="color: #cc66cc;">650</span><span style="color: #339933;">,</span><span style="color: #cc66cc;">600</span><span style="color: #339933;">,</span><span style="color: #cc66cc;">228</span><span style="color: #339933;">,</span><span style="color: #cc66cc;">229</span><span style="color: #339933;">,</span><span style="color: #cc66cc;">401</span><span style="color: #339933;">,</span><span style="color: #cc66cc;">496</span><span style="color: #339933;">,</span><span style="color: #cc66cc;">703</span><span style="color: #339933;">,</span><span style="color: #cc66cc;">205</span><span style="color: #339933;">,</span><span style="color: #cc66cc;">376</span>
      <span style="color: #cc66cc;">24</span><span style="color: #339933;">-----------------------------------</span><span style="color: #cc66cc;">20</span><span style="color: #339933;">,</span><span style="color: #cc66cc;">282</span><span style="color: #339933;">,</span><span style="color: #cc66cc;">409</span><span style="color: #339933;">,</span><span style="color: #cc66cc;">603</span><span style="color: #339933;">,</span><span style="color: #cc66cc;">651</span><span style="color: #339933;">,</span><span style="color: #cc66cc;">670</span><span style="color: #339933;">,</span><span style="color: #cc66cc;">423</span><span style="color: #339933;">,</span><span style="color: #cc66cc;">947</span><span style="color: #339933;">,</span><span style="color: #cc66cc;">251</span><span style="color: #339933;">,</span><span style="color: #cc66cc;">286</span><span style="color: #339933;">,</span>016</pre></div></div>

]]></content:encoded>
			<wfw:commentRss>http://www.troublenow.org/299/ipv6-subnets/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Xymon Microsoft SQL data query</title>
		<link>http://www.troublenow.org/192/xymon-microsoft-sql-data-query/</link>
		<comments>http://www.troublenow.org/192/xymon-microsoft-sql-data-query/#comments</comments>
		<pubDate>Fri, 17 Dec 2010 10:38:26 +0000</pubDate>
		<dc:creator>Arno Haverlach</dc:creator>
				<category><![CDATA[Xymon/Hobbit/BB]]></category>
		<category><![CDATA[bigbrother]]></category>
		<category><![CDATA[datasource]]></category>
		<category><![CDATA[DBI]]></category>
		<category><![CDATA[FreeTDS]]></category>
		<category><![CDATA[hobbit]]></category>
		<category><![CDATA[microsoft]]></category>
		<category><![CDATA[odbc]]></category>
		<category><![CDATA[perl]]></category>
		<category><![CDATA[sql]]></category>
		<category><![CDATA[xymon]]></category>

		<guid isPermaLink="false">http://www.troublenow.org/?p=192</guid>
		<description><![CDATA[Using FreeTDS it is possible to connect from A Linux server to Microsoft SQL Server (in this case I use SQL Server 2005), I use this to run a query on a Microsoft SQL Server from Xymon. First we need to install the required packages, in this case I use a Debian system: sudo apt-get [...]]]></description>
			<content:encoded><![CDATA[<p>Using FreeTDS it is possible to connect from A Linux server to Microsoft SQL Server (in this case I use SQL Server 2005), I use this to run a query on a Microsoft SQL Server from Xymon.</p>
<p>First we need to install the required packages, in this case I use a Debian system:</p>

<div class="wp_syntax"><div class="code"><pre class="perl" style="font-family:monospace;">sudo apt<span style="color: #339933;">-</span>get install libdbd<span style="color: #339933;">-</span>odbc<span style="color: #339933;">-</span>perl libdbi<span style="color: #339933;">-</span>perl tdsodbc freetds<span style="color: #339933;">-</span>common</pre></div></div>

<p>Now configure a datasouce in the <strong>/etc/odbci.ini</strong>:</p>

<div class="wp_syntax"><div class="code"><pre class="perl" style="font-family:monospace;"><span style="color: #009900;">&#91;</span>DB01<span style="color: #339933;">-</span>DATASOURCE<span style="color: #009900;">&#93;</span>
Driver          <span style="color: #339933;">=</span> <span style="color: #339933;">/</span>usr<span style="color: #339933;">/</span>lib<span style="color: #339933;">/</span>odbc<span style="color: #339933;">/</span>libtdsodbc<span style="color: #339933;">.</span>so
Description     <span style="color: #339933;">=</span> DB Server
Trace           <span style="color: #339933;">=</span> No
Server          <span style="color: #339933;">=</span> 192<span style="color: #339933;">.</span>168<span style="color: #339933;">.</span>0<span style="color: #339933;">.</span>1
Database        <span style="color: #339933;">=</span> testdb
<span style="color: #339933;">;</span>Port            <span style="color: #339933;">=</span> <span style="color: #cc66cc;">4444</span>
TDS_Version     <span style="color: #339933;">=</span> <span style="color: #cc66cc;">8.0</span></pre></div></div>

<p>And add the server (DB01) to the freetds config <strong>/etc/freetds/freetds.conf</strong>:</p>

<div class="wp_syntax"><div class="code"><pre class="perl" style="font-family:monospace;"><span style="color: #009900;">&#91;</span>DB01<span style="color: #009900;">&#93;</span>
        host <span style="color: #339933;">=</span> 192<span style="color: #339933;">.</span>168<span style="color: #339933;">.</span>0<span style="color: #339933;">.</span>1
        port <span style="color: #339933;">=</span> <span style="color: #cc66cc;">1433</span>
        tds version <span style="color: #339933;">=</span> <span style="color: #cc66cc;">8.0</span></pre></div></div>

<p><strong>Xymon setup:</strong></p>
<p>Now create a xymon /ext/xymon-DB01query.pl script to grab the data from the SQL Server.</p>
<p>Below is a basic version only usable on a single host in xymon and without any red/green/orange checking it wil create a test name &#8216;DB01query&#8217; inside xymon.</p>
<p>Also I presume getting 2 valuables back from the SQL server that are put in @DATA.</p>

<div class="wp_syntax"><div class="code"><pre class="perl" style="font-family:monospace;"><span style="color: #666666; font-style: italic;">#!/usr/bin/perl -w</span>
<span style="color: #666666; font-style: italic;">#############################################################################</span>
<span style="color: #666666; font-style: italic;"># $Id: $</span>
<span style="color: #666666; font-style: italic;">#############################################################################</span>
<span style="color: #000000; font-weight: bold;">use</span> strict<span style="color: #339933;">;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">## BB and related test constants</span>
<span style="color: #666666; font-style: italic;">#############################################################################</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">use</span> constant GREEN <span style="color: #339933;">=&gt;</span> <span style="color: #ff0000;">'green'</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">use</span> constant YELLOW <span style="color: #339933;">=&gt;</span> <span style="color: #ff0000;">'yellow'</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">use</span> constant RED <span style="color: #339933;">=&gt;</span> <span style="color: #ff0000;">'red'</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #666666; font-style: italic;"># BB Global variables</span>
<span style="color: #666666; font-style: italic;">#############################################################################</span>
&nbsp;
<span style="color: #b1b100;">my</span> <span style="color: #0000ff;">$bbtest</span> <span style="color: #339933;">=</span> <span style="color: #ff0000;">'DB01query'</span><span style="color: #339933;">;</span>
<span style="color: #b1b100;">my</span> <span style="color: #0000ff;">$color</span> <span style="color: #339933;">=</span> GREEN<span style="color: #339933;">;</span>
<span style="color: #b1b100;">my</span> <span style="color: #0000ff;">$status</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">$bbtest</span> <span style="color: #339933;">.</span> <span style="color: #ff0000;">&quot; OK&quot;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">## Main Program</span>
<span style="color: #666666; font-style: italic;">#############################################################################</span>
<span style="color: #009900;">&#123;</span>
<span style="color: #b1b100;">my</span> <span style="color: #0000ff;">$dbuser</span> <span style="color: #339933;">=</span> <span style="color: #ff0000;">'CHANGETHIS'</span><span style="color: #339933;">;</span>
<span style="color: #b1b100;">my</span> <span style="color: #0000ff;">$dbpass</span> <span style="color: #339933;">=</span> <span style="color: #ff0000;">'CHANGETHIS'</span><span style="color: #339933;">;</span>
<span style="color: #b1b100;">my</span> <span style="color: #0000ff;">$dbds</span> <span style="color: #339933;">=</span> <span style="color: #ff0000;">'DB01-DATASOURCE'</span><span style="color: #339933;">;</span>
<span style="color: #b1b100;">my</span> <span style="color: #0000ff;">$machine</span> <span style="color: #339933;">=</span> <span style="color: #ff0000;">'DB01'</span><span style="color: #339933;">;</span>
<span style="color: #b1b100;">my</span> <span style="color: #0000ff;">$perf</span> <span style="color: #339933;">=</span> <span style="color: #ff0000;">&quot;&quot;</span><span style="color: #339933;">;</span>
<span style="color: #b1b100;">my</span> <span style="color: #0000ff;">@DATA</span> <span style="color: #339933;">=</span> <span style="color: #ff0000;">&quot;&quot;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">use</span> DBI<span style="color: #339933;">;</span>
&nbsp;
<span style="color: #b1b100;">my</span> <span style="color: #0000ff;">$dbh</span> <span style="color: #339933;">=</span> DBI<span style="color: #339933;">-&gt;</span><span style="color: #006600;">connect</span><span style="color: #009900;">&#40;</span><span style="color: #ff0000;">&quot;dbi:ODBC:$dbds&quot;</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">$dbuser</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">$dbpass</span><span style="color: #339933;">,</span>
<span style="color: #009900;">&#123;</span>PrintError <span style="color: #339933;">=&gt;</span> <span style="color: #cc66cc;">1</span><span style="color: #339933;">,</span> RaiseError <span style="color: #339933;">=&gt;</span> <span style="color: #cc66cc;">1</span><span style="color: #339933;">,</span> LongTruncOk<span style="color: #339933;">=&gt;</span><span style="color: #cc66cc;">1</span><span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000066;">die</span> <span style="color: #ff0000;">&quot;Unable for connect to server $DBI::errstr&quot;</span>
    <span style="color: #b1b100;">unless</span> <span style="color: #0000ff;">$dbh</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #b1b100;">my</span> <span style="color: #0000ff;">$sql</span> <span style="color: #339933;">=</span> <span style="color: #ff0000;">&quot;select * from database01&quot;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #b1b100;">my</span> <span style="color: #0000ff;">$sth</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">$dbh</span><span style="color: #339933;">-&gt;</span><span style="color: #006600;">prepare</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">$sql</span><span style="color: #009900;">&#41;</span>
 <span style="color: #b1b100;">or</span> <span style="color: #000066;">die</span> <span style="color: #ff0000;">&quot;Can't prepare statement: $DBI::errstr&quot;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #0000ff;">$sth</span><span style="color: #339933;">-&gt;</span><span style="color: #006600;">execute</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #b1b100;">while</span> <span style="color: #009900;">&#40;</span> <span style="color: #b1b100;">my</span> <span style="color: #0000ff;">@row</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">$sth</span><span style="color: #339933;">-&gt;</span><span style="color: #006600;">fetchrow_array</span> <span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
 <span style="color: #0000ff;">$perf</span> <span style="color: #339933;">=</span> <span style="color: #ff0000;">&quot;@row<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #0000ff;">@DATA</span> <span style="color: #339933;">=</span> <span style="color: #000066;">split</span><span style="color: #009900;">&#40;</span><span style="color: #009966; font-style: italic;">/ /</span><span style="color: #339933;">,</span><span style="color: #0000ff;">$perf</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #0000ff;">$dbh</span><span style="color: #339933;">-&gt;</span><span style="color: #006600;">disconnect</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">## Send to Hobbit</span>
<span style="color: #666666; font-style: italic;">#############################################################################</span>
<span style="color: #b1b100;">my</span> <span style="color: #0000ff;">$report_date</span> <span style="color: #339933;">=</span> <span style="color: #ff0000;">`/bin/date`</span><span style="color: #339933;">;</span>
<span style="color: #000066;">chomp</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">$report_date</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000066;">system</span><span style="color: #009900;">&#40;</span><span style="color: #ff0000;">&quot;$ENV{BB} $ENV{BBDISP} 'status $machine.$bbtest $color $report_date <span style="color: #000099; font-weight: bold;">\n</span><span style="color: #000099; font-weight: bold;">\n</span>
&nbsp;
RESULT1 : $DATA[0]
RESULT2: $DATA[1]
'<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #009900;">&#125;</span></pre></div></div>

<p>I also want graphs from this so add a new section to the <strong>hobbitgraph.cfg</strong>:</p>

<div class="wp_syntax"><div class="code"><pre class="perl" style="font-family:monospace;"><span style="color: #009900;">&#91;</span>DB01query<span style="color: #009900;">&#93;</span>
                TITLE DB01query
                YAXIS <span style="color: #666666; font-style: italic;">#</span>
                DEF<span style="color: #339933;">:</span>RESULT1<span style="color: #339933;">=</span>DB01query<span style="color: #339933;">.</span>rrd<span style="color: #339933;">:</span>RESULT1<span style="color: #339933;">:</span>AVERAGE
                DEF<span style="color: #339933;">:</span>RESULT2<span style="color: #339933;">=</span>DB01query<span style="color: #339933;">.</span>rrd<span style="color: #339933;">:</span>RESULT1<span style="color: #339933;">:</span>AVERAGE
                LINE1<span style="color: #339933;">:</span>RESULT1<span style="color: #666666; font-style: italic;">#0000CC:RESULT1</span>
                LINE1<span style="color: #339933;">:</span>RESULT2<span style="color: #666666; font-style: italic;">#FFFF00:RESULT2</span>
                COMMENT<span style="color: #339933;">:</span><span style="color: #0000ff;">\n</span>
                GPRINT<span style="color: #339933;">:</span>RESULT1<span style="color: #339933;">:</span>LAST<span style="color: #339933;">:</span>RESULT1\<span style="color: #339933;">:</span> <span style="color: #339933;">%</span>5<span style="color: #339933;">.</span>0lf <span style="color: #009900;">&#40;</span>cur<span style="color: #009900;">&#41;</span>
                GPRINT<span style="color: #339933;">:</span>RESULT1<span style="color: #339933;">:</span>MAX<span style="color: #339933;">:</span> \<span style="color: #339933;">:</span> <span style="color: #339933;">%</span>5<span style="color: #339933;">.</span>0lf <span style="color: #009900;">&#40;</span>max<span style="color: #009900;">&#41;</span>
                GPRINT<span style="color: #339933;">:</span>RESULT1<span style="color: #339933;">:</span>MIN<span style="color: #339933;">:</span> \<span style="color: #339933;">:</span> <span style="color: #339933;">%</span>5<span style="color: #339933;">.</span>0lf <span style="color: #009900;">&#40;</span>min<span style="color: #009900;">&#41;</span>
                GPRINT<span style="color: #339933;">:</span>RESULT1<span style="color: #339933;">:</span>AVERAGE<span style="color: #339933;">:</span> \<span style="color: #339933;">:</span> <span style="color: #339933;">%</span>5<span style="color: #339933;">.</span>0lf <span style="color: #009900;">&#40;</span>avg<span style="color: #009900;">&#41;</span><span style="color: #0000ff;">\n</span>
                GPRINT<span style="color: #339933;">:</span>RESULT2<span style="color: #339933;">:</span>LAST<span style="color: #339933;">:</span>RESULT2\<span style="color: #339933;">:</span> <span style="color: #339933;">%</span>5<span style="color: #339933;">.</span>0lf <span style="color: #009900;">&#40;</span>cur<span style="color: #009900;">&#41;</span>
                GPRINT<span style="color: #339933;">:</span>RESULT2<span style="color: #339933;">:</span>MAX<span style="color: #339933;">:</span> \<span style="color: #339933;">:</span> <span style="color: #339933;">%</span>5<span style="color: #339933;">.</span>0lf <span style="color: #009900;">&#40;</span>max<span style="color: #009900;">&#41;</span>
                GPRINT<span style="color: #339933;">:</span>RESULT2<span style="color: #339933;">:</span>MIN<span style="color: #339933;">:</span> \<span style="color: #339933;">:</span> <span style="color: #339933;">%</span>5<span style="color: #339933;">.</span>0lf <span style="color: #009900;">&#40;</span>min<span style="color: #009900;">&#41;</span>
                GPRINT<span style="color: #339933;">:</span>RESULT2<span style="color: #339933;">:</span>AVERAGE<span style="color: #339933;">:</span> \<span style="color: #339933;">:</span> <span style="color: #339933;">%</span>5<span style="color: #339933;">.</span>0lf <span style="color: #009900;">&#40;</span>avg<span style="color: #009900;">&#41;</span><span style="color: #0000ff;">\n</span></pre></div></div>

<p>Edit the <strong>hobbitserver.cfg</strong> to include the DB01query in the TEST2RRD as &#8216;DB01query=ncv&#8217; and change the default mode to GAUGE:</p>

<div class="wp_syntax"><div class="code"><pre class="perl" style="font-family:monospace;">TEST2RRD<span style="color: #339933;">=</span><span style="color: #ff0000;">&quot;cpu=la,disk,inode,qtree,memory,$PINGCOLUMN=tcp,http=tcp,dns=tcp,dig=tcp,time=ntpstat,vmstat,iostat,netstat,temperature,apache,bind,sendmail,mailq,nmailq=mailq,socks,bea,iishealth,citrix,bbgen,bbtest,bbproxy,hobbitd,files,procs=processes,ports,clock,lines,ops,stats,cifs,JVM,JMS,HitCache,Session,JDBCConn,ExecQueue,JTA,TblSpace,RollBack,MemReq,InvObj,snapmirr,snaplist,snapshot,if_load=devmon,temp=devmon,DB01query=ncv&quot;</span>
&nbsp;
NCV_DB01query<span style="color: #339933;">=</span><span style="color: #ff0000;">&quot;RESULT1:GAUGE,RESULT1:GAUGE&quot;</span></pre></div></div>

<p>Now add this new test to the hobbitlaunch.cfg in xymon:</p>

<div class="wp_syntax"><div class="code"><pre class="perl" style="font-family:monospace;"><span style="color: #339933;">&gt;</span>
<span style="color: #009900;">&#91;</span>DB01query<span style="color: #009900;">&#93;</span>
        ENVFILE <span style="color: #339933;">/</span>vol<span style="color: #339933;">/</span>01<span style="color: #339933;">/</span>xymon<span style="color: #339933;">/</span>server<span style="color: #339933;">/</span>etc<span style="color: #339933;">/</span>hobbitserver<span style="color: #339933;">.</span>cfg
        NEEDS hobbitd
        CMD <span style="color: #0000ff;">$BBHOME</span><span style="color: #339933;">/</span>ext<span style="color: #339933;">/</span>xymon<span style="color: #339933;">-</span>DB01query<span style="color: #339933;">.</span>pl
        LOGFILE <span style="color: #0000ff;">$BBSERVERLOGS</span><span style="color: #339933;">/</span>DB01query<span style="color: #339933;">.</span><span style="color: #000066;">log</span>
        INTERVAL 5m</pre></div></div>

<p>Just wait a while and the test should show up in xymon.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.troublenow.org/192/xymon-microsoft-sql-data-query/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

