<?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; debian</title>
	<atom:link href="http://www.troublenow.org/category/linux/debian/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>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>Mobile internet using you mobile phone in Linux</title>
		<link>http://www.troublenow.org/22/mobile-internet-using-you-mobile-phone-in-linux/</link>
		<comments>http://www.troublenow.org/22/mobile-internet-using-you-mobile-phone-in-linux/#comments</comments>
		<pubDate>Sun, 24 Aug 2008 16:22:20 +0000</pubDate>
		<dc:creator>Arno Haverlach</dc:creator>
				<category><![CDATA[debian]]></category>
		<category><![CDATA[gentoo]]></category>
		<category><![CDATA[linux]]></category>
		<category><![CDATA[ubuntu]]></category>
		<category><![CDATA[Mobile]]></category>

		<guid isPermaLink="false">http://www.troublenow.org/?p=22</guid>
		<description><![CDATA[When I am on the road sometimes its very handy to have internet around. luckily this is very easy to accomplish in Linux. In this case I will be using a Samsung F700 Mobile phone connected to my Asus EEE 701 laptop running Ubuntu linux. A few things however to think of before you start: [...]]]></description>
			<content:encoded><![CDATA[<p>When I am on the road sometimes its very handy to have internet around.</p>
<p>luckily this is very easy to accomplish in Linux. In this case I will be using a Samsung F700 Mobile phone connected to my Asus EEE 701 laptop running Ubuntu linux.</p>
<p>A few things however to think of before you start:<br />
- Do you have a &#8216;unlimited&#8217; or limited (100MiB/1GiB etc..) contract (&#8216;unlimited&#8217; is recommended)<br />
- Does your provider allow dial up using your phone &amp; laptop (By Vodafone it is not allowed but if you use it for &#8216;normal&#8217; web browsing they don&#8217;t mind (if you start using it to download your latest TV episode&#8217;s or whatever you will be shutdown.)</p>
<p><strong>So lets start:</strong></p>
<p>First connect the phone to the laptop using the USB cable in my case the phone will ask me in what &#8216;mode&#8217; the phone should operate, I need to select &#8216;pc studio&#8217; to use the phone as a gateway to the internet.</p>
<p>Now when the phone is connected to the PC open a terminal and run wvdialconf to create a new config file:</p>

<div class="wp-terminal">trouble@sun:$ sudo wvdialconf /etc/wvdial.conf<br/><br/>Editing `/etc/wvdial.conf'.<br/><br/>Scanning your serial ports for a modem.<br/><br/>ttyS0&lt;*1&gt;: ATQ0 V1 E1 -- failed with 2400 baud, next try: 9600 baud<br/>ttyS0&lt;*1&gt;: ATQ0 V1 E1 -- failed with 9600 baud, next try: 115200 baud<br/>ttyS0&lt;*1&gt;: ATQ0 V1 E1 -- and failed too at 115200, giving up.<br/>Modem Port Scan&lt;*1&gt;: S1   S2   S3<br/>WvModem&lt;*1&gt;: Cannot get information for serial port.<br/>ttyACM0&lt;*1&gt;: ATQ0 V1 E1 -- OK<br/>ttyACM0&lt;*1&gt;: ATQ0 V1 E1 Z -- OK<br/>ttyACM0&lt;*1&gt;: ATQ0 V1 E1 S0=0 -- OK<br/>ttyACM0&lt;*1&gt;: ATQ0 V1 E1 S0=0 &amp;C1 -- OK<br/>ttyACM0&lt;*1&gt;: ATQ0 V1 E1 S0=0 &amp;C1 &amp;D2 -- OK<br/>ttyACM0&lt;*1&gt;: ATQ0 V1 E1 S0=0 &amp;C1 &amp;D2 +FCLASS=0 -- ERROR<br/>ttyACM0&lt;*1&gt;: Modem Identifier: ATI -- Manufacturer: SAMSUNG ELECTRONICS CORPORATION<br/>ttyACM0&lt;*1&gt;: Speed 4800: AT -- OK<br/>ttyACM0&lt;*1&gt;: Speed 9600: AT -- OK<br/>ttyACM0&lt;*1&gt;: Speed 19200: AT -- OK<br/>ttyACM0&lt;*1&gt;: Speed 38400: AT -- OK<br/>ttyACM0&lt;*1&gt;: Speed 57600: AT -- OK<br/>ttyACM0&lt;*1&gt;: Speed 115200: AT -- OK<br/>ttyACM0&lt;*1&gt;: Speed 230400: AT -- OK<br/>ttyACM0&lt;*1&gt;: Speed 460800: AT -- OK<br/>ttyACM0&lt;*1&gt;: Max speed is 460800; that should be safe.<br/>ttyACM0&lt;*1&gt;: ATQ0 V1 E1 S0=0 &amp;C1 &amp;D2 -- OK<br/><br/>Found an USB modem on /dev/ttyACM0.<br/>Modem configuration written to /etc/wvdial.conf.<br/>ttyACM0: Speed 460800; init "ATQ0 V1 E1 S0=0 &amp;C1 &amp;D2"<br/></div>

<p>As you can see it found my Samsung F700 phone and updated the wvdial.conf file.</p>
<p>Now we need to edit the wvdial.conf file to add a few paramaters (user/pass &amp; dial number)<br />
the default config file looks like this:</p>

<div class="wp-terminal">trouble@sun:$ $ cat /etc/wvdial.conf <br/><br/>[Dialer Defaults]<br/>Init1 = ATZ<br/>Init2 = ATQ0 V1 E1 S0=0 &amp;C1 &amp;D2<br/>Modem Type = USB Modem<br/>Baud = 460800<br/>New PPPD = yes<br/>Modem = /dev/ttyACM0<br/>ISDN = 0<br/>; Phone =<br/>; Password =<br/>; Username =<br/></div>

<p>Now you will need to know the &#8216;Target Phone Number&#8217; for vodafone in the Netherlands this is &#8216;*99#&#8217; but this might be different in your case so just &#8216;google&#8217; around if you have a other provider for the target phone number.</p>
<p>The username and password can be just random but I like to keep it simple and changed both to &#8216;vodafone&#8217;</p>
<p>Also you need to enable &#8216;stupid mode&#8217; in wvdial to work around some of the &#8216;intelligence&#8217; in wvdial to get it to work.</p>
<p>So vi the wvdial.conf file and it should look like this:</p>

<div class="wp-terminal">trouble@sun:$ $ sudo vi /etc/wvdial.conf<br/>[Dialer Defaults]<br/>Init1 = ATZ<br/>Init2 = ATQ0 V1 E1 S0=0 &amp;C1 &amp;D2<br/>Modem Type = USB Modem<br/>Baud = 460800<br/>New PPPD = yes<br/>Modem = /dev/ttyACM0<br/>ISDN = 0<br/>Phone = *99#<br/>Password = vodafone<br/>Username = vodafone<br/>Stupid Mode = 1<br/></div>

<p>Now you are ready to go, so start &#8216;wvdial&#8217; and you should be connected (I created a desktop terminal launcher with the command: &#8216;sudo wvdial&#8217; for this).</p>

<div class="wp-terminal">trouble@sun:$ $ sudo wvdial<br/>--&gt; WvDial: Internet dialer version 1.60<br/>--&gt; Cannot get information for serial port.<br/>--&gt; Initializing modem.<br/>--&gt; Sending: ATZ<br/>ATZ<br/>OK<br/>--&gt; Sending: ATQ0 V1 E1 S0=0 &amp;C1 &amp;D2<br/>ATQ0 V1 E1 S0=0 &amp;C1 &amp;D2<br/>OK<br/>--&gt; Modem initialized.<br/>--&gt; Sending: ATDT*99#<br/>--&gt; Waiting for carrier.<br/>ATDT*99#<br/>CONNECT<br/>--&gt; Carrier detected.  Starting PPP immediately.<br/>--&gt; Starting pppd at Sun Aug 24 18:14:11 2008<br/>--&gt; Pid of pppd: 23198<br/>--&gt; Using interface ppp0<br/>--&gt; pppd: ��[06][08]��[06][08]<br/>--&gt; pppd: ��[06][08]��[06][08]<br/>--&gt; pppd: ��[06][08]��[06][08]<br/>--&gt; pppd: ��[06][08]��[06][08]<br/>--&gt; pppd: ��[06][08]��[06][08]<br/>--&gt; pppd: ��[06][08]��[06][08]<br/>--&gt; pppd: ��[06][08]��[06][08]<br/>--&gt; local  IP address YOURIP<br/>--&gt; pppd: ��[06][08]��[06][08]<br/>--&gt; remote IP address GATEWAYIP<br/>--&gt; pppd: ��[06][08]��[06][08]<br/>--&gt; primary   DNS address DNSIP<br/>--&gt; pppd: ��[06][08]��[06][08]<br/>--&gt; secondary DNS address DNSIP<br/>--&gt; pppd: ��[06][08]��[06][08]<br/></div>

]]></content:encoded>
			<wfw:commentRss>http://www.troublenow.org/22/mobile-internet-using-you-mobile-phone-in-linux/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Burning a video DVD VIDEO_TS in Linux</title>
		<link>http://www.troublenow.org/20/burning-a-video-dvd-video_ts-in-linux/</link>
		<comments>http://www.troublenow.org/20/burning-a-video-dvd-video_ts-in-linux/#comments</comments>
		<pubDate>Tue, 15 Jan 2008 18:01:59 +0000</pubDate>
		<dc:creator>Arno Haverlach</dc:creator>
				<category><![CDATA[debian]]></category>
		<category><![CDATA[linux]]></category>
		<category><![CDATA[ubuntu]]></category>
		<category><![CDATA[DVD]]></category>

		<guid isPermaLink="false">http://www.troublenow.org/?p=20</guid>
		<description><![CDATA[You can rip dvd&#8217;s with multiple tools, and some of these rip the dvd to a &#8216;VIDEO_TS&#8217; and &#8216;AUDIO_TS&#8217; folder. You can burn them again with the tool mkisofs. Place your &#8216;VIDEO_TS&#8217; and &#8216;AUDIO_TS&#8217; in a folder (lets say /home/user1/mymovie/) Install mkisofs: trouble@sun:$ apt-get updatetrouble@sun:$ apt-get install mkisofs Then use mkisofs to create a ISO [...]]]></description>
			<content:encoded><![CDATA[<p>You can rip dvd&#8217;s with multiple tools, and some of these rip the dvd to a &#8216;VIDEO_TS&#8217; and &#8216;AUDIO_TS&#8217; folder. You can burn them again with the tool mkisofs.</p>
<p>Place your &#8216;VIDEO_TS&#8217; and &#8216;AUDIO_TS&#8217; in a folder (lets say /home/user1/mymovie/)</p>
<p>Install mkisofs:</p>

<div class="wp-terminal">trouble@sun:$ apt-get update<br/>trouble@sun:$ apt-get install mkisofs<br/></div>

<p>Then use mkisofs to create a ISO file from the folder:</p>

<div class="wp-terminal">trouble@sun:$ mkisofs -dvd-video -o /home/user1/mymovie.iso /home/user1/mymovie/<br/></div>

<p>Now in /home/user1 you have a iso file called &#8216;mymovie.iso&#8217;</p>
<p>now use brazero or any other burning tool to burn the .iso file to a DVD.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.troublenow.org/20/burning-a-video-dvd-video_ts-in-linux/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Firewall VMware Server 1.0.x guest with iptables on the host</title>
		<link>http://www.troublenow.org/19/firewall-vmware-server-10x-guest-with-iptables-on-the-host/</link>
		<comments>http://www.troublenow.org/19/firewall-vmware-server-10x-guest-with-iptables-on-the-host/#comments</comments>
		<pubDate>Thu, 06 Dec 2007 12:33:07 +0000</pubDate>
		<dc:creator>Arno Haverlach</dc:creator>
				<category><![CDATA[debian]]></category>
		<category><![CDATA[linux]]></category>
		<category><![CDATA[ubuntu]]></category>
		<category><![CDATA[firewall]]></category>
		<category><![CDATA[iptables]]></category>
		<category><![CDATA[vmware]]></category>

		<guid isPermaLink="false">http://www.troublenow.org/?p=19</guid>
		<description><![CDATA[Running a linux host with VMware 1.0.x Server you are not able to firewall the VMware guests on the host machine. Because vmware runs in the kernel the traffic to the guest is already handled by vmware before iptables will see the traffic. Now it is possible to firewall the client by setting up a [...]]]></description>
			<content:encoded><![CDATA[<p>Running a linux host with VMware 1.0.x Server you are not able to firewall the VMware guests on the host machine. Because vmware runs in the kernel the traffic to the guest is already handled by vmware before iptables will see the traffic.</p>
<p>Now it is possible to firewall the client by setting up a dummy network interface and bridge the physical interface to the dummy, this way you can let VMware setup his bridge to the dummy interface and you see the traffic passing by.</p>
<p><strong>The layout</strong></p>
<p>Lets say you have the following setup (click for larger):<br />
<a href="http://www.troublenow.org/crap/pics/vmware/networklayout.png"><img src="http://www.troublenow.org/crap/pics/vmware/networklayout.png" height="200" width="500" alt="network layout"/></a></p>
<p>host01 has a virtual host &#8216;guest01&#8242; and it is bridged to eth0 and eth1 so it has a connection to the internet and a connection to the backlan to reach the DB0x servers.</p>
<p>However host02 has the same setup, but I don&#8217;t want &#8216;guest02&#8242; to reach &#8216;guest01&#8242;, this could be aranged with a firewall on the guests but thats a bad solution if they are running windows (you don&#8217;t want to overload a already bloated windows with a extra firewall right?), so however there are multiple ways to fix this one solution is to setup a bridge on the host machine&#8217;s and firewall the traffic before it reaches the guest.</p>
<p>The following image should explain it a little more (click for larger):<br />
<a href="http://www.troublenow.org/crap/pics/vmware/logical-bridge.png"><img src="http://www.troublenow.org/crap/pics/vmware/logical-bridge.png" height="200" width="500" alt="logical bridge"/></a></p>
<p><strong>The configuration</strong></p>
<p>In this setup the &#8216;host&#8217; machine is running ubuntu 6.06.1 LTS, has 2 nic&#8217;s and we are using VMware Server 1.0.4. that should have a bridge to both nics.<br />
We will be creating 2 dummy network interfaces called &#8216;dummy0&#8242; and &#8216;dummy1&#8242; and 2 bridges called &#8216;br0&#8242; and &#8216;br1&#8242;.<br />
Then bind eth0 to dummy0 with br0 and eth1 to dummy1 with br1.</p>
<p>First install bridge utilities</p>

<div class="wp-terminal">trouble@sun:$ apt-get install bridge-utils<br/></div>

<p>Now connect to the console of the server as you can&#8217;t do this remote (well you can but then do 1 interface at a time)<br />
Shutdown vmware and shutdown the interfaces</p>

<div class="wp-terminal">trouble@sun:$ /etc/init.d/vmware stop<br/>trouble@sun:$ ifdown eth0<br/>trouble@sun:$ ifdown eth1<br/></div>

<p>Now be sure to comment out the settings in /etc/network/interfaces for eth0 and eth1 so these are not read anymore.</p>
<p>create the dummy interfaces</p>

<div class="wp-terminal">trouble@sun:$ modprobe dummy -o dummy0<br/>trouble@sun:$ modprobe dummy -o dummy1<br/></div>

<p>then create bridge 0 and bridge 1 and bind the interfaces to them, in my network I need to put stp &#8216;off&#8217; but check in your case.</p>
<p># br0, eth0 and dummy0</p>

<div class="wp-terminal">trouble@sun:$ brctl addbr br0<br/>trouble@sun:$ brctl addif br0 eth0<br/>trouble@sun:$ brctl addif br0 dummy0<br/>trouble@sun:$ brctl stp br0 off<br/></div>

<p># br1, eth1 and dummy1</p>

<div class="wp-terminal">trouble@sun:$ brctl addbr br1<br/>trouble@sun:$ brctl addif br1 eth1<br/>trouble@sun:$ brctl addif br1 dummy1<br/>trouble@sun:$ brctl stp br1 off<br/></div>

<p>Now with the command &#8216;brctl show&#8217; you should see the interfaces.</p>

<div class="wp-terminal">trouble@sun:$ brctl show<br/>bridge name     bridge id               STP enabled     interfaces<br/>br1             8000.00112f164152       no              eth1<br/>dummy1<br/>br0             8000.00112f164151       no              eth0<br/>dummy0<br/></div>

<p>Oke now the bridges are configured, time to add a ipaddress to br0 and br1 so we can also connect to the server for management. Currently I will do this with ifconfig instead of putting it in the network file (see below for the complete script)</p>

<div class="wp-terminal">trouble@sun:$ ifconfig eth0 0.0.0.0<br/>trouble@sun:$ ifconfig dummy0 0.0.0.0<br/>trouble@sun:$ ifconfig eth1 0.0.0.0<br/>trouble@sun:$ ifconfig dummy1 0.0.0.0<br/>trouble@sun:$ ifconfig br0 10.1.1.2 netmask 255.255.255.0<br/>trouble@sun:$ ifconfig br1 192.168.10.2 netmask 255.255.255.0<br/>trouble@sun:$ route add default gw 10.1.1.1<br/></div>

<p>Now the host should be reachable again on his network interfaces.</p>
<p>Now its time to reconfigure VMware with  vmware-config.pl, when it asks for the network settings change them in the &#8216;editor&#8217; mode and set bridging on &#8216;vmnet0&#8242; to &#8216;br0&#8242; and &#8216;vmnet2&#8242; to &#8216;br1&#8242;.<br />
Edit your virtual machine to use vmnet0 and vmnet2 and you should be ready to go with network on the virtual machines again.</p>
<p><strong>The Firewall Rules</strong></p>
<p>So the bridges are set, now its time to create some firewall rules, I won&#8217;t start explaining iptables here so here is an example configuration script that creates the bridged interfaces and configures the firewall.</p>
<p>To explain it a little:<br />
First I will create the bridges and add ipaddresses to them, and only do this if they are not already created.<br />
Then we move all traffic flowing through br0 in &#8216;Aforward&#8217; (traffic to dummy0), and all traffic flowing through br1 in &#8216;Bforward&#8217; (traffic to dummy1)(Just give it your own names if you wish this is logical for me <img src='http://www.troublenow.org/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
<p>Now make sure to put your firewall rules for the guests in the section marked as:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
</pre></td><td class="code"><pre class="bash" style="font-family:monospace;">   <span style="color: #666666; font-style: italic;">##### Firewall rules for br0 from here! ####  </span>
   <span style="color: #666666; font-style: italic;">##### Firewall rules for br0 until here! ####</span></pre></td></tr></table></div>

<p>And the same for br1, and configure your local firewall rules to the ipaddresses of the host in:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
</pre></td><td class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #666666; font-style: italic;">#-------- Local Firewall Rules to this host ----------#</span>
<span style="color: #666666; font-style: italic;">#-----------------------------------------------------#</span></pre></td></tr></table></div>

<p>And you should be ready to go firewalled all traffic flowing through the vmware guests. Be sure to understand that this will only firewall the traffic from the &#8216;outside&#8217; to your guest if you have multiple guests on your vmware host traffic is not firewalled between the 2 guests. This could be fixed by putting every guest in a seperate vmnet and use the host to NAT traffic to it but that won&#8217;t work in every setup.<br />
Currently in the setup I am using I only have 2 Windows servers on 2 different hosts so I bridged those, firewalled those on the hosts, and the linux guests on the same hosts have there own firewall rules so I don&#8217;t have this problem. (you do firewall all your nodes in a network right?)</p>
<p>And the complete script:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
</pre></td><td 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;">#   Arno Haverlach (arno (at) haverlach (dot) nl)</span>
<span style="color: #666666; font-style: italic;">#   Firewall/Bridge script for vmware</span>
<span style="color: #666666; font-style: italic;">#   ver 0.1 20071204</span>
<span style="color: #666666; font-style: italic;">#----------------------------------------------------#</span>
&nbsp;
<span style="color: #666666; font-style: italic;">#--------------IP Variables -------------------------#</span>
<span style="color: #007800;">DNS1</span>=10.1.1.1		        <span style="color: #666666; font-style: italic;"># dns server 1</span>
<span style="color: #007800;">DNS2</span>=10.1.1.2                   <span style="color: #666666; font-style: italic;"># dns server 2</span>
<span style="color: #007800;">MANAGEMENTHOST</span>=x.x.x.x          <span style="color: #666666; font-style: italic;"># Management host</span>
<span style="color: #666666; font-style: italic;">#-----------------------------------------------------#</span>
&nbsp;
<span style="color: #666666; font-style: italic;">#---------------- variables --------------------------#</span>
<span style="color: #666666; font-style: italic;"># Bridge 0 (WAN)</span>
<span style="color: #007800;">BR0IP</span>=<span style="color: #ff0000;">&quot;10.1.1.2&quot;</span>            <span style="color: #666666; font-style: italic;"># ip of the LAN interface</span>
<span style="color: #007800;">BR0MASK</span>=<span style="color: #ff0000;">&quot;255.255.255.0&quot;</span>       <span style="color: #666666; font-style: italic;"># subnetmask of the LAN</span>
<span style="color: #007800;">BR0IF1</span>=<span style="color: #ff0000;">&quot;eth0&quot;</span>                   <span style="color: #666666; font-style: italic;"># The physical LAN interface</span>
<span style="color: #007800;">BR0IF2</span>=<span style="color: #ff0000;">&quot;dummy0&quot;</span>                 <span style="color: #666666; font-style: italic;"># This should be the dummy</span>
<span style="color: #007800;">BR0GW</span>=<span style="color: #ff0000;">&quot;1&quot;</span>                       <span style="color: #666666; font-style: italic;"># 0 for no 1 for yes to enable the gateway</span>
<span style="color: #007800;">BR0GWIP</span>=<span style="color: #ff0000;">&quot;10.1.1.1&quot;</span>          <span style="color: #666666; font-style: italic;"># the ip of the gateway if BRI1GW=1</span>
&nbsp;
<span style="color: #666666; font-style: italic;"># Bridge 1 (LAN)</span>
<span style="color: #007800;">BR1IP</span>=<span style="color: #ff0000;">&quot;192.168.10.2&quot;</span>          <span style="color: #666666; font-style: italic;"># ip of the LAN interface</span>
<span style="color: #007800;">BR1MASK</span>=<span style="color: #ff0000;">&quot;255.255.255.0&quot;</span>         <span style="color: #666666; font-style: italic;"># subnetmask of the LAN</span>
<span style="color: #007800;">BR1IF1</span>=<span style="color: #ff0000;">&quot;eth1&quot;</span>                   <span style="color: #666666; font-style: italic;"># The physical LAN interface</span>
<span style="color: #007800;">BR1IF2</span>=<span style="color: #ff0000;">&quot;dummy1&quot;</span>                 <span style="color: #666666; font-style: italic;"># This should be the dummy</span>
<span style="color: #007800;">BR1GW</span>=<span style="color: #ff0000;">&quot;0&quot;</span>                       <span style="color: #666666; font-style: italic;"># 0 for no 1 for yes to enable the gateway</span>
<span style="color: #007800;">BR1GWIP</span>=<span style="color: #ff0000;">&quot;0.0.0.0&quot;</span>               <span style="color: #666666; font-style: italic;"># the ip of the gateway if BRI1GW=1</span>
&nbsp;
<span style="color: #666666; font-style: italic;"># A few paths</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>
<span style="color: #007800;">MODPROBE</span>=<span style="color: #ff0000;">&quot;/sbin/modprobe&quot;</span>       <span style="color: #666666; font-style: italic;"># path to modprobe</span>
<span style="color: #007800;">BRCTL</span>=<span style="color: #ff0000;">&quot;/usr/sbin/brctl&quot;</span>         <span style="color: #666666; font-style: italic;"># path to brctl</span>
<span style="color: #007800;">IFCONFIG</span>=<span style="color: #ff0000;">&quot;/sbin/ifconfig&quot;</span>       <span style="color: #666666; font-style: italic;"># path to ifconfig</span>
<span style="color: #007800;">ROUTE</span>=<span style="color: #ff0000;">&quot;/sbin/route&quot;</span>             <span style="color: #666666; font-style: italic;"># path to route</span>
&nbsp;
<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: #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>
&nbsp;
<span style="color: #666666; font-style: italic;">#-----------------------------------------------------#</span>
&nbsp;
<span style="color: #666666; font-style: italic;">#--------------- And now the fun stuff ---------------#</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;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>
&nbsp;
<span style="color: #666666; font-style: italic;">#---------------- Create br0 -------------------------#</span>
&nbsp;
<span style="color: #666666; font-style: italic;"># load the module if needed</span>
 <span style="color: #007800;">MDCHK1</span>=<span style="color: #ff0000;">&quot;<span style="color: #780078;">`lsmod | grep -i dummy0 | awk {' print $1 '}`</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;">$MDCHK1</span>&quot;</span> <span style="color: #000000; font-weight: bold;">!</span>= <span style="color: #ff0000;">&quot;dummy0&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: #007800;">$MODPROBE</span> dummy <span style="color: #660033;">-o</span> dummy0; <span style="color: #000000; font-weight: bold;">fi</span>
&nbsp;
<span style="color: #666666; font-style: italic;"># create the bridge if needed</span>
 <span style="color: #007800;">BRCHK1</span>=<span style="color: #ff0000;">&quot;<span style="color: #780078;">`brctl show | grep br0 | awk {' print $1 '}`</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;">$BRCHK1</span>&quot;</span> <span style="color: #000000; font-weight: bold;">!</span>= <span style="color: #ff0000;">&quot;br0&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: #007800;">$BRCTL</span> addbr br0
  <span style="color: #007800;">$BRCTL</span> addif br0 <span style="color: #007800;">$BR0IF1</span>
  <span style="color: #007800;">$BRCTL</span> addif br0 <span style="color: #007800;">$BR0IF2</span>
  <span style="color: #007800;">$BRCTL</span> stp br0 off
  <span style="color: #007800;">$IFCONFIG</span> <span style="color: #007800;">$BR0IF1</span> 0.0.0.0
  <span style="color: #007800;">$IFCONFIG</span> <span style="color: #007800;">$BR0IF2</span> 0.0.0.0
  <span style="color: #007800;">$IFCONFIG</span> br0 <span style="color: #007800;">$BR0IP</span> netmask <span style="color: #007800;">$BR0MASK</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;">$BR0GW</span>&quot;</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: #007800;">$ROUTE</span> add default gw <span style="color: #007800;">$BR0GWIP</span>
  <span style="color: #000000; font-weight: bold;">fi</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;">#---------------- Create br1 -------------------------#</span>
<span style="color: #666666; font-style: italic;"># load the module if needed</span>
 <span style="color: #007800;">MDCHK1</span>=<span style="color: #ff0000;">&quot;<span style="color: #780078;">`lsmod | grep -i dummy1 | awk {' print $1 '}`</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;">$MDCHK1</span>&quot;</span> <span style="color: #000000; font-weight: bold;">!</span>= <span style="color: #ff0000;">&quot;dummy1&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: #007800;">$MODPROBE</span> dummy <span style="color: #660033;">-o</span> dummy1; <span style="color: #000000; font-weight: bold;">fi</span>
&nbsp;
<span style="color: #666666; font-style: italic;"># create the bridge if needed</span>
 <span style="color: #007800;">BRCHK1</span>=<span style="color: #ff0000;">&quot;<span style="color: #780078;">`brctl show | grep br1 | awk {' print $1 '}`</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;">$BRCHK1</span>&quot;</span> <span style="color: #000000; font-weight: bold;">!</span>= <span style="color: #ff0000;">&quot;br1&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: #007800;">$BRCTL</span> addbr br1
  <span style="color: #007800;">$BRCTL</span> addif br1 <span style="color: #007800;">$BR1IF1</span>
  <span style="color: #007800;">$BRCTL</span> addif br1 <span style="color: #007800;">$BR1IF2</span>
  <span style="color: #007800;">$BRCTL</span> stp br1 off
  <span style="color: #007800;">$IFCONFIG</span> <span style="color: #007800;">$BR1IF1</span> 0.0.0.0
  <span style="color: #007800;">$IFCONFIG</span> <span style="color: #007800;">$BR1IF2</span> 0.0.0.0
  <span style="color: #007800;">$IFCONFIG</span> br1 <span style="color: #007800;">$BR1IP</span> netmask <span style="color: #007800;">$BR1MASK</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;">$BR1GW</span>&quot;</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: #007800;">$ROUTE</span> add default gw <span style="color: #007800;">$BR1GWIP</span>
  <span style="color: #000000; font-weight: bold;">fi</span>
 <span style="color: #000000; font-weight: bold;">fi</span>
&nbsp;
<span style="color: #666666; font-style: italic;">#-----------------------------------------------------#</span>
&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: #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;">-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
&nbsp;
<span style="color: #666666; font-style: italic;">#-----------------------------------------------------#</span>
&nbsp;
<span style="color: #666666; font-style: italic;">#-------------- We put br0 in Aforward ---------------#</span>
&nbsp;
 <span style="color: #666666; font-style: italic;"># Create Aforward</span>
 <span style="color: #007800;">$IPTABLES</span> <span style="color: #660033;">-N</span> Aforward
<span style="color: #007800;">$IPTABLES</span> <span style="color: #660033;">-A</span> FORWARD <span style="color: #660033;">-i</span> br0 <span style="color: #660033;">-j</span> Aforward
 <span style="color: #007800;">$IPTABLES</span> <span style="color: #660033;">-A</span> FORWARD <span style="color: #660033;">-o</span> br0 <span style="color: #660033;">-j</span> Aforward
&nbsp;
<span style="color: #666666; font-style: italic;"># Drop all crap on Aforward</span>
    <span style="color: #007800;">$IPTABLES</span> <span style="color: #660033;">-A</span> Aforward <span style="color: #660033;">-p</span> TCP <span style="color: #660033;">--tcp-flags</span> SYN,FIN SYN,FIN <span style="color: #660033;">-j</span> DROP
    <span style="color: #007800;">$IPTABLES</span> <span style="color: #660033;">-A</span> Aforward <span style="color: #660033;">-p</span> TCP <span style="color: #660033;">--tcp-flags</span> SYN,RST SYN,RST <span style="color: #660033;">-j</span> DROP
    <span style="color: #007800;">$IPTABLES</span> <span style="color: #660033;">-A</span> Aforward <span style="color: #660033;">-p</span> TCP <span style="color: #660033;">--tcp-flags</span> FIN,RST FIN,RST <span style="color: #660033;">-j</span> DROP
    <span style="color: #007800;">$IPTABLES</span> <span style="color: #660033;">-A</span> Aforward <span style="color: #660033;">-p</span> TCP <span style="color: #660033;">--tcp-flags</span> ACK,FIN FIN <span style="color: #660033;">-j</span> DROP
    <span style="color: #007800;">$IPTABLES</span> <span style="color: #660033;">-A</span> Aforward <span style="color: #660033;">-p</span> TCP <span style="color: #660033;">--tcp-flags</span> ACK,PSH PSH <span style="color: #660033;">-j</span> DROP
    <span style="color: #007800;">$IPTABLES</span> <span style="color: #660033;">-A</span> Aforward <span style="color: #660033;">-p</span> TCP <span style="color: #660033;">--tcp-flags</span> ACK,URG URG <span style="color: #660033;">-j</span> DROP
&nbsp;
<span style="color: #666666; font-style: italic;">##### Firewall rules for br0 from here! ####</span>
&nbsp;
<span style="color: #666666; font-style: italic;">##### Firewall rules for br0 until here! ####</span>
&nbsp;
<span style="color: #666666; font-style: italic;"># drop the rest on Aforward</span>
    <span style="color: #007800;">$IPTABLES</span> <span style="color: #660033;">-A</span> Aforward <span style="color: #660033;">-j</span> DROP
&nbsp;
<span style="color: #666666; font-style: italic;">#-----------------------------------------------------#</span>
&nbsp;
<span style="color: #666666; font-style: italic;">#-------------- We put br1 in Bforward ---------------#</span>
&nbsp;
 <span style="color: #666666; font-style: italic;"># Create Bforward</span>
 <span style="color: #007800;">$IPTABLES</span> <span style="color: #660033;">-N</span> Bforward
<span style="color: #007800;">$IPTABLES</span> <span style="color: #660033;">-A</span> FORWARD <span style="color: #660033;">-i</span> br1 <span style="color: #660033;">-j</span> Bforward
 <span style="color: #007800;">$IPTABLES</span> <span style="color: #660033;">-A</span> FORWARD <span style="color: #660033;">-o</span> br1 <span style="color: #660033;">-j</span> Bforward
&nbsp;
<span style="color: #666666; font-style: italic;"># Drop all crap on Bforward</span>
    <span style="color: #007800;">$IPTABLES</span> <span style="color: #660033;">-A</span> Bforward <span style="color: #660033;">-p</span> TCP <span style="color: #660033;">--tcp-flags</span> SYN,FIN SYN,FIN <span style="color: #660033;">-j</span> DROP
    <span style="color: #007800;">$IPTABLES</span> <span style="color: #660033;">-A</span> Bforward <span style="color: #660033;">-p</span> TCP <span style="color: #660033;">--tcp-flags</span> SYN,RST SYN,RST <span style="color: #660033;">-j</span> DROP
    <span style="color: #007800;">$IPTABLES</span> <span style="color: #660033;">-A</span> Bforward <span style="color: #660033;">-p</span> TCP <span style="color: #660033;">--tcp-flags</span> FIN,RST FIN,RST <span style="color: #660033;">-j</span> DROP
    <span style="color: #007800;">$IPTABLES</span> <span style="color: #660033;">-A</span> Bforward <span style="color: #660033;">-p</span> TCP <span style="color: #660033;">--tcp-flags</span> ACK,FIN FIN <span style="color: #660033;">-j</span> DROP
    <span style="color: #007800;">$IPTABLES</span> <span style="color: #660033;">-A</span> Bforward <span style="color: #660033;">-p</span> TCP <span style="color: #660033;">--tcp-flags</span> ACK,PSH PSH <span style="color: #660033;">-j</span> DROP
    <span style="color: #007800;">$IPTABLES</span> <span style="color: #660033;">-A</span> Bforward <span style="color: #660033;">-p</span> TCP <span style="color: #660033;">--tcp-flags</span> ACK,URG URG <span style="color: #660033;">-j</span> DROP
&nbsp;
<span style="color: #666666; font-style: italic;">##### Firewall rules for br1 from here! ####</span>
&nbsp;
<span style="color: #666666; font-style: italic;">##### Firewall rules for br1 until here! ####</span>
&nbsp;
<span style="color: #666666; font-style: italic;"># drop the rest on Bforward</span>
    <span style="color: #007800;">$IPTABLES</span> <span style="color: #660033;">-A</span> Bforward <span style="color: #660033;">-j</span> DROP
&nbsp;
<span style="color: #666666; font-style: italic;">#-----------------------------------------------------#</span>
&nbsp;
<span style="color: #666666; font-style: italic;">#--------------- Drop on FORWARD ---------------------#</span>
&nbsp;
 <span style="color: #007800;">$IPTABLES</span> <span style="color: #660033;">-A</span> FORWARD <span style="color: #660033;">-j</span> LOG <span style="color: #660033;">--log-prefix</span> <span style="color: #ff0000;">&quot;[DROP-FORWARD] &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;">#-----------------------------------------------------#</span>
&nbsp;
<span style="color: #666666; font-style: italic;">#-------- Local Firewall Rules to this host ----------#</span>
&nbsp;
<span style="color: #666666; font-style: italic;">## INPUT ##</span>
&nbsp;
<span style="color: #666666; font-style: italic;"># VMWARE Console management hosts</span>
&nbsp;
 <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;">$MANAGEMENTHOST</span> <span style="color: #660033;">--dport</span> <span style="color: #000000;">902</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;">$MANAGEMENTHOST</span> <span style="color: #660033;">--sport</span> <span style="color: #000000;">902</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> INPUT <span style="color: #660033;">-p</span> tcp <span style="color: #660033;">-s</span> <span style="color: #007800;">$MANAGEMENTHOST</span> <span style="color: #660033;">--dport</span> <span style="color: #000000;">8222</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;">$MANAGEMENTHOST</span> <span style="color: #660033;">--sport</span> <span style="color: #000000;">8222</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> INPUT <span style="color: #660033;">-p</span> tcp <span style="color: #660033;">-s</span> <span style="color: #007800;">$MANAGEMENTHOST</span> <span style="color: #660033;">--dport</span> <span style="color: #000000;">8333</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;">$MANAGEMENTHOST</span> <span style="color: #660033;">--sport</span> <span style="color: #000000;">8333</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;"># ssh in from everyone and all interfaces</span>
&nbsp;
 <span style="color: #007800;">$IPTABLES</span> <span style="color: #660033;">-A</span> INPUT <span style="color: #660033;">-p</span> tcp <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;">--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;">## OUTPUT ##</span>
&nbsp;
<span style="color: #666666; font-style: italic;"># port 80 to browse a bit for updates and stuff (you should limit this)</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;">--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;">--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;"># DNS lookups</span>
&nbsp;
 <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>
 <span style="color: #000000; font-weight: bold;">for</span> dnsip <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;">$dnsip</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;">$dnsip</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;">$dnsip</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;">$dnsip</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;">$dnsip</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;">$dnsip</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;">$dnsip</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: #000000; font-weight: bold;">done</span>
&nbsp;
<span style="color: #666666; font-style: italic;"># deny rest</span>
&nbsp;
 <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] &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] &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: #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;">#-----------------------------------------------------#</span>
&nbsp;
<span style="color: #666666; font-style: italic;">#---------------- End the if cmd=start ---------------#</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;">#------------- Set default policy to 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: #666666; font-style: italic;">#-----------------------------------------------------#</span>
<span style="color: #666666; font-style: italic;">#eof</span></pre></td></tr></table></div>

]]></content:encoded>
			<wfw:commentRss>http://www.troublenow.org/19/firewall-vmware-server-10x-guest-with-iptables-on-the-host/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
	</channel>
</rss>

