    <rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:sy="http://purl.org/rss/1.0/modules/syndication/" xmlns:admin="http://webns.net/mvcb/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:content="http://purl.org/rss/1.0/modules/content/">
     <channel>
        <title>Linux.com :: $300 for solution - fwmark, iptables</title>
        <link>http://www.linux.com/archive/forums/topic/1335</link>
        <description>Everything Linux and Open Source</description>
        <dc:language>en-us</dc:language> 
        <dc:creator>Linux.com Admin</dc:creator> 
        <admin:generatorAgent rdf:resource="http://www.linux.com" /> 
        <admin:errorReportsTo rdf:resource="mailto:noreply@linux.com" />
       <sy:updatePeriod>hourly</sy:updatePeriod>
       <sy:updateFrequency>1</sy:updateFrequency>
       <docs>http://backend.userland.com/rss</docs>



<div class="xarbb-noteswrapper">
</div>

   <div class="xarbb-noteswrapper">
       <div class="xar-sub rightnote">
           <div>
                    <a href="http://www.linux.com/archive/forums/topic/717">
Previous Topic</a>
|
                    <a href="http://www.linux.com/archive/forums/topic/1350">
Next Topic</a>
</div>

           <div>
                    <a href="http://www.linux.com/archive/forums/printtopic/1335?theme=print">
Print this topic</a> |
You are not subscribed            </div>
        </div>
        <div style="clear: both;"></div>
    </div>

    <h1>
        <a class="xar-title" href="http://www.linux.com/archive/forums/topic/1335">$300 for solution - fwmark, iptables</a>
   </h1>


   <div class="xarbb-topiccontrols">
<form action="http://www.linux.com/archive/forums?func=jump" method="post">
   <label for="xarbb_jump_menu">Forum Jump</label>
    <select name="f" id="xarbb_jump_menu" onchange="this.form.submit();">
        <optgroup label="Options">
            <option value="6" selected="selected">
Please select forum            </option>
            <option value="6">--------------------</option>
        </optgroup>
        <optgroup label="Forums">
                <option value="1">New to Linux</option>
                <option value="2">Hardware</option>
                <option value="3">Linux Distributions</option>
                <option value="4">Applications</option>
                <option value="5">Programming and Development</option>
                <option value="6">Miscellaneous Discussion</option>
                <option value="7">Linux.com Writers Forum</option>
                <option value="8">Jobs</option>
        </optgroup>
    </select>
    <input type="submit" class="button" value="Jump" />
</form>
<div style="clear: both;"></div>
   </div>

   <div class="xarbb-topiccontrols">

<span class="xar-sub">
    <a href="http://www.linux.com/archive/forums">
Forum Index    </a>
    <span style="font-size: larger;">&#187;</span>
    <a href="http://www.linux.com/archive/forums/category/4181">
        Forums 
    </a>
    <span style="font-size: larger;">&#187;</span>
    <a href="http://www.linux.com/archive/forums/forum/6">
        Miscellaneous Discussion   </a>
</span>
<div style="clear: both;"></div>
   </div>

<div class="xarbb-tablewrapper">



   <table>
       <tr>
           <th scope="col">
Author</th>
           <th scope="col">
Message</th>
       </tr>



            <tr>
                <td class="xar-norm author">
                    <div>
                        <a href="http://www.linux.com/archive/roles/400020">vincentdipiazza</a>
                   </div>
                   <div class="xar-sub">
Joined: Mar 19, 2008<br/>Posts: 3                        <br />
                        <a href="http://www.linux.com/archive/forums?by=400020&amp;func=searchtopics">
Other Topics</a>
                   </div>
               </td>

               <td class="xar-norm message">
                   <div class="xarbb-messagecontrols">
                       <div class="leftnote">
                           <span class="xar-sub">
Posted Mar 19, 2008 at 5:43:31 PM</span>
                       </div>



<div style="float: left;">
                           <strong class="xar-sub">
Subject: $300 for solution - fwmark, iptables                            </strong>
                        </div>
                        <div style="clear: both;"></div>
                    </div>

                    <div>
                        Please take the time to figure this out, I will pay you $300 if you could get this working.

I am using linux kernel 2.4.35 

I need to ask you for some expertise regarding iptables, fwmark, and ip rule.
 
I am currently redirecting all traffic through the VPN.  This works great.  However, I don't want http traffic to go through the VPN I want all other traffic to go through but not http.
 
So i did alot of research and I found that I would be able to create another routing table besides main.  And then route any specific traffic through that route.
 
First I create another table like this:
#ip route show table main | grep -Ev tun | grep -Ev ^default | while read ROUTE ; do
ip route add table 7 $ROUTE
done
#ip route add table 7 default via 192.168.66.1 
*** 192.168.66.1 is my IP recieved from my ISP's modem ***
 
I know table 7 works perfect because if I change the default ip rule to direct all traffic to table 7 I am no longer using the VPN for all traffic.  This is how I did the test:
DEFAULT IP RULE (ALL TRAFFIC GOES THROUGH VPN AT FIRST):
# ip rule
0:         from all lookup local
32766:  from all lookup main
32767:  from all lookup default
 
CHANGED IP RULE (ALL TRAFFIC GOES THROUGH ISP AFTER THESE COMMANDS):
# ip rule add from 0/0 table 7 pref 100
# ip rule
0:         from all lookup local
100:      from all lookup 7
32766:  from all lookup main
32767:  from all lookup default
 
But this is not what I want I only want to web traffic to go through the ISP and everything else to go through the VPN.  Therefore http should go through table 7 and all other traffic should go through table main.  So I did some research and found I need to mark the packets using IP tables.  And then i have to use fwmark to inside ip rule to move these packets to table 7.  So this is what I did:
FIRST I WANT TO REMOVE THE IP RULE TABLE 7 (ALL TRAFFIC NOW IS GOING BACK THROUGH THE VPN AFTER THESE COMMANDS):
# ip rule del from 0/0 table 7 pref 100
# ip rule
0:         from all lookup local
32766:  from all lookup main
32767:  from all lookup default
 
THEN I WANT TO ADD A FWMARK TO THE IP RULE (ALL TRAFFIC STILL GOES THROUGH VPN AFTER THESE COMMANDS):
# ip rule add fwmark 7 table 7 pref 100
# ip rule
0:         from all lookup local
100:     from all fwmark 0x7 lookup 7
32766:  from all lookup main
32767:  from all lookup default
 
The reason why traffic is still going through the VPN is because there are no marked packets with 7.
 
THEN I MARK ALL HTTP PACKETS WITH 7:
#iptables -t mangle -I PREROUTING -m layer7 --l7proto http -j MARK --set-mark 7
 
Now as soon as I issue this command http traffic doesn't work at all.  All other traffic works perfect, if I try to access a server using ssh it works, but if i try to access the web nothing happens.  This means that the command to mark http packets is working.  But for some reason fwmark doesn't effectively use table 7.  We know that table 7 is working perfect because we tested it by sending all traffic to it.  So the error or limitation is fwmark.  Why can't fwmark correctly use table 7?  I have read that I may need to add an SNAT or DNAT rule.  I also read that maybe the kernel has to include this fwmark in order for it to work.  I am stuck.  This is very important.  I will pay you $300 if you can figure this out for me.
 
P.S. AS SOON AS I REMOVE THE IPTABLES MARK 7 EVERYTHING IS GOING THROUGH THE VPN AGAIN AFTER THIS COMMAND.
#iptables -t mangle -D PREROUTING -m layer7 --l7proto http -j MARK --set-mark 7
 
1.) Table 7 works - this is not the issue.
2.) marking http packets works - this is not the issue
3.) ip rule add fwmark is not working for some reason.
a.) it could be that the kernel cannot handle this.  Please check it. But this does not seem likely since it allowed the command.
b.) it could be that when packets are going out they are going out with the wrong source IP, which is why I may need to use SNAT and DNAT iptables rules.
c.) I could be missing another step that is required when using fwmark inside the ip rule.
 
P.P.S Yes I have also tried marked all tcp port 80 without using the layer7 filter and I still get the exact same result.  PLEASE HELP!!!
 
Thanks,
Vince
 </div>

                </td>
            </tr>

            <tr>
                <td class="xar-norm author">
                    <a href="http://www.linux.com/archive/forums/topic/1335#top">
Back to top</a>
</td>
               <td class="xar-alt">

                        <a href="http://www.linux.com/archive/roles/400020">
                            <img src="modules/xarbb/xarimages/new/icon_profile.gif" alt="Profile" />
                        </a>
                        <a href="http://www.linux.com/archive/?module=roles&amp;func=email&amp;uid=400020">
                            <img src="modules/xarbb/xarimages/new/icon_email.gif" alt="Email" />
                       </a>
                            <a href="http://">
                                <img src="modules/xarbb/xarimages/new/icon_www.gif" alt="Website" />
                           </a>
</td>
           </tr>





           <tr>
               <td class="xar-norm author">
                   <strong>

                            <a href="http://www.linux.com/archive/roles/399680">
                                                           </a>
</strong>

                   <span class="xar-sub">
<br />
Joined Nov 26, 2009<br/>Posts: 241<br />
                        <br />
                        <a href="http://www.linux.com/archive/forums?by=399680&amp;func=searchtopics">
Other Topics                        </a>
                    </span>
                </td>

                <td class="xar-accent message">
                   <div class="xarbb-messagecontrols">
                       <div class="leftnote">
                           <span class="xar-sub">
Posted:
                                Mar 19, 2008 7:27:43 PM                           </span>
                       </div>
                       <div class="rightnote">
</div>
                       <div style="float:left;">
                           <strong class="xar-sub">
Subject:
                                <a name="1185489" href="http://www.linux.com/archive/forums/topic/1335#1185489">
                                    $300 for solution - fwmark, iptables                                </a>
                            </strong>
                        </div>
                        <div style="clear: both;"></div>
                    </div>

                    <div style="clear: left;">
                        This might not be what you want, but why don't you just use iptables?

make a chain called VPN allow what you want in there and drop ALL port 80, 8080 requests. (in and outbound)
make another chain called http and block everything accept ports 80 and 8080?

Or create those two chains and just forward all packets other then 80, 8080 to the VPN chain and forward 80, 8080 to the http chain?
                    </div>
                </td>
            </tr>

            <tr>
                <td class="xar-norm author">
                    <a href="http://www.linux.com/archive/forums/topic/1335#top">
Back to top</a>
</td>

               <td class="xar-alt">

                            <a href="http://www.linux.com/archive/roles/399680">
                                <img src="modules/xarbb/xarimages/new/icon_profile.gif" alt="Profile" />
                            </a>
                            <a href="http://www.linux.com/archive/?module=roles&amp;func=email&amp;uid=399680">
                                <img src="modules/xarbb/xarimages/new/icon_email.gif" alt="Email" />
                           </a>
</td>
           </tr>

           <tr>
               <td class="xar-norm author">
                   <strong>

                            <a href="http://www.linux.com/archive/roles/400326">
                                Gargravarr                           </a>
</strong>

                   <span class="xar-sub">
<br />
Joined Mar 25, 2008<br/>Posts: 1<br />
                        <br />
                        <a href="http://www.linux.com/archive/forums?by=400326&amp;func=searchtopics">
Other Topics                        </a>
                    </span>
                </td>

                <td class="xar-norm message">
                   <div class="xarbb-messagecontrols">
                       <div class="leftnote">
                           <span class="xar-sub">
Posted:
                                Mar 25, 2008 1:00:08 AM                           </span>
                       </div>
                       <div class="rightnote">
</div>
                       <div style="float:left;">
                           <strong class="xar-sub">
Subject:
                                <a name="1186043" href="http://www.linux.com/archive/forums/topic/1335#1186043">
                                    Re:  Re:  $300 for solution - fwmark, iptables                                </a>
                            </strong>
                        </div>
                        <div style="clear: both;"></div>
                    </div>

                    <div style="clear: left;">
                        It sounds like you might need to disable rp_filter for the ISP interface.

Something like...

echo 0 &gt; /proc/sys/net/ipv4/conf/eth0/rp_filter

should do it. Replacing eth0 with your ISP interface.
[Modified by: Gargravarr on March 25, 2008 01:03 AM]
                    </div>
                </td>
            </tr>

            <tr>
                <td class="xar-norm author">
                    <a href="http://www.linux.com/archive/forums/topic/1335#top">
Back to top</a>
</td>

               <td class="xar-alt">

                            <a href="http://www.linux.com/archive/roles/400326">
                                <img src="modules/xarbb/xarimages/new/icon_profile.gif" alt="Profile" />
                            </a>
                            <a href="http://www.linux.com/archive/?module=roles&amp;func=email&amp;uid=400326">
                                <img src="modules/xarbb/xarimages/new/icon_email.gif" alt="Email" />
                           </a>
                                <a href="http://">
                                    <img src="modules/xarbb/xarimages/new/icon_www.gif" alt="Website" />
                               </a>
</td>
           </tr>
</table>
</div>

<div class="xarbb-topiccontrols">

<span class="xar-sub">
    <a href="http://www.linux.com/archive/forums">
Forum Index    </a>
    <span style="font-size: larger;">&#187;</span>
    <a href="http://www.linux.com/archive/forums/category/4181">
        Forums 
    </a>
    <span style="font-size: larger;">&#187;</span>
    <a href="http://www.linux.com/archive/forums/forum/6">
        Miscellaneous Discussion   </a>
</span>

</div>



            </channel>
</rss>
