<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<meta content="text/html;charset=ISO-8859-1" http-equiv="Content-Type">
<title></title>
</head>
<body bgcolor="#ffffff" text="#000066">
<small>I use an own-written init script to enable iptables at start-up:
/etc/init.d/iptables_tc:</small><br>
<br>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<meta name="Generator" content="Kate, the KDE Advanced Text Editor">
<pre><span style="color: rgb(128, 128, 128);"><i>#!/bin/sh</i></span>
<span style="color: rgb(128, 128, 128);"><i>#</i></span>
<span style="color: rgb(128, 128, 128);"><i># iptables_tc - ipables/tc init script</i></span>
<span style="color: rgb(128, 128, 128);"><i>#</i></span>
<span style="color: rgb(128, 128, 128);"><i># wRitten by Jordi Ferrando</i></span>
<span style="color: rgb(128, 128, 128);"><i># Debian.etch</i></span>
<span style="color: rgb(128, 128, 128);"><i># <a class="moz-txt-link-abbreviated" href="mailto:jferrando@netplc.com">jferrando@netplc.com</a></i></span>
<span style="color: rgb(0, 128, 0);">TC=</span><span
style="color: rgb(221, 0, 0);">"/sbin/tc"</span>
<span style="color: rgb(0, 128, 0);">IPTABLES=</span><span
style="color: rgb(221, 0, 0);">"/sbin/iptables"</span>
<span style="color: rgb(255, 0, 255);"><b>start()</b></span> <b>{</b>
<span
style="color: rgb(136, 0, 136);"><b>echo</b></span> <span
style="color: rgb(221, 0, 0);">"Starting outbound shaping..."</span>
<span
style="color: rgb(128, 128, 128);"><i># Reset everything to a known state (cleared)</i></span>
<span
style="color: rgb(128, 128, 128);"><i>#flush de reglas</i></span>
<span
style="color: rgb(0, 128, 0);">$IPTABLES</span> -F
<span
style="color: rgb(0, 128, 0);">$IPTABLES</span> -X
<span
style="color: rgb(0, 128, 0);">$IPTABLES</span> -Z
<span
style="color: rgb(0, 128, 0);">$IPTABLES</span> -t nat -F
<span
style="color: rgb(128, 128, 128);"><i>#Borrar clase entera</i></span>
<span
style="color: rgb(0, 128, 0);">$TC</span> qdisc del dev eth0 root
<span
style="color: rgb(128, 128, 128);"><i>#Router linux con firewall y traffic shaping</i></span>
<span
style="color: rgb(128, 128, 128);"><i>#(c)NETPLC, J.Ferrando, Ene-2005/1-Dic-2005</i></span>
<span
style="color: rgb(128, 128, 128);"><i>#Interfaz eth0 192.168.7.5/255.255.255.248 (192.168.7.1 .. 192.168.7.6, broadcast 192.168.7.7, 192.168.7.0/29)</i></span>
<span
style="color: rgb(128, 128, 128);"><i># eth1 192.168.8.5/255.255.255.0 (192.168.8.0/24, LAN)</i></span>
<span
style="color: rgb(128, 128, 128);"><i>#Default gateway 192.168.7.1</i></span>
<span
style="color: rgb(128, 128, 128);"><i>#DNAT tables</i></span>
<span
style="color: rgb(128, 128, 128);"><i>#HTTP tcp/80</i></span>
iptables --table nat --append PREROUTING -i eth0 -d 192.168.7.5 -p tcp --dport 80 -j DNAT --to 192.168.8.5
(...)
<span style="color: rgb(128, 128, 128);"><i>#ROUTER SNAT para la LAN</i></span>
iptables --table nat --append POSTROUTING --out-interface eth0 -j MASQUERADE
<span
style="color: rgb(128, 128, 128);"><i>#Firewall red 192.168.8.0/24</i></span>
iptables -A FORWARD -s 192.168.8.5 -j ACCEPT
iptables -A INPUT -s 192.168.8.5 -j ACCEPT
<span
style="color: rgb(128, 128, 128);"><i>#servicios a la red local surera</i></span>
<span
style="color: rgb(128, 128, 128);"><i>#DNS</i></span>
iptables -A INPUT -s 192.168.8.0/24 -i eth1 -p tcp --sport 53 -j ACCEPT
iptables -A INPUT -s 192.168.8.0/24 -i eth1 -p tcp --dport 53 -j ACCEPT
iptables -A INPUT -s 192.168.8.0/24 -i eth1 -p udp --sport 53 -j ACCEPT
iptables -A INPUT -s 192.168.8.0/24 -i eth1 -p udp --dport 53 -j ACCEPT
(...)
<span style="color: rgb(128, 128, 128);"><i>#Acceso internet</i></span>
<span
style="color: rgb(128, 128, 128);"><i>#portpascual</i></span>
iptables -A FORWARD -s 192.168.8.70 -i eth1 -m mac --mac-source 00:08:0D:C8:CE:D9 -j ACCEPT
(...)
<span style="color: rgb(128, 128, 128);"><i>#Acceso al servidor</i></span>
<span
style="color: rgb(128, 128, 128);"><i>#particularidades ordenadores</i></span>
<span
style="color: rgb(128, 128, 128);"><i>#portpascual</i></span>
iptables -A INPUT -s 192.168.8.70 -i eth1 -m mac --mac-source 00:08:0D:C8:CE:D9 -j ACCEPT
(...)
<span style="color: rgb(128, 128, 128);"><i>#Default policy INPUT</i></span>
iptables -A INPUT -s 192.168.8.0/24 -i eth1 -j DROP
<span
style="color: rgb(128, 128, 128);"><i>#Default polity FORWARD</i></span>
iptables -A FORWARD -s 192.168.8.0/24 -i eth1 -j DROP
<span
style="color: rgb(128, 128, 128);"><i>#Filtrado de red 192.168.7.0/248</i></span>
iptables -A INPUT -s 192.168.7.1 -i eth0 -m mac --mac-source 00:13:49:19:BE:A4 -j ACCEPT
iptables -A INPUT -s 192.168.7.0/29 -i eth0 -j DROP
<span
style="color: rgb(136, 0, 136);"><b>echo</b></span> 1 <span
style="color: rgb(34, 51, 136);"><b>></b></span> /proc/sys/net/ipv4/ip_forward
<span
style="color: rgb(128, 128, 128);"><i>#tc "Traffic Control"</i></span>
<span
style="color: rgb(128, 128, 128);"><i>#This command attaches queue discipline HTB to eth0 and gives it the "handle" 1:0</i></span>
<span
style="color: rgb(128, 128, 128);"><i>#This is just a name or identifier with which to refer to it below. The default 20 means that </i></span>
<span
style="color: rgb(128, 128, 128);"><i>#any traffic that is not otherwise classified will be assigned to class 1:20</i></span>
tc qdisc add dev eth0 root handle 1:0 htb default 20
<span
style="color: rgb(128, 128, 128);"><i>#tc class add dev eth0 parent 1:0 classid 1:1 htb rate 576kbit ceil 576kbit prio 1 burst 32k cburst 32k</i></span>
tc class add dev eth0 parent 1:0 classid 1:1 htb rate 576kbit ceil 576kbit prio 1 burst 32k cburst 3200
<span
style="color: rgb(128, 128, 128);"><i>#tc class add dev eth0 parent 1:1 classid 1:5 htb rate 384kbit ceil 576kbit prio 5 burst 16k cburst 16k</i></span>
tc class add dev eth0 parent 1:1 classid 1:5 htb rate 384kbit ceil 576kbit prio 5 burst 16k cburst 1600
<span
style="color: rgb(128, 128, 128);"><i>#tc class add dev eth0 parent 1:1 classid 1:10 htb rate 256kbit ceil 576kbit prio 10 burst 8k cburst 8k</i></span>
tc class add dev eth0 parent 1:1 classid 1:10 htb rate 256kbit ceil 576kbit prio 10 burst 8k cburst 800
<span
style="color: rgb(128, 128, 128);"><i>#tc class add dev eth0 parent 1:1 classid 1:15 htb rate 128kbit ceil 576kbit prio 15 burst 4k cburst 4k</i></span>
tc class add dev eth0 parent 1:1 classid 1:15 htb rate 128kbit ceil 576kbit prio 15 burst 4k cburst 400
<span
style="color: rgb(128, 128, 128);"><i>#tc class add dev eth0 parent 1:1 classid 1:20 htb rate 64kbit ceil 576kbit prio 20 burst 2k cburst 2k</i></span>
tc class add dev eth0 parent 1:1 classid 1:20 htb rate 64kbit ceil 576kbit prio 20 burst 2k cburst 200
<span
style="color: rgb(128, 128, 128);"><i>#tc class add dev eth0 parent 1:1 classid 1:25 htb rate 8kbit ceil 16kbit prio 25 burst 1k cburst 1k</i></span>
tc class add dev eth0 parent 1:1 classid 1:25 htb rate 2kbit ceil 4kbit prio 25 burst 8 cburst 8
<span
style="color: rgb(128, 128, 128);"><i>#</i></span>
tc qdisc add dev eth0 parent 1:5 handle 5:0 sfq perturb 10
tc qdisc add dev eth0 parent 1:10 handle 10:0 sfq perturb 10
tc qdisc add dev eth0 parent 1:15 handle 15:0 sfq perturb 10
tc qdisc add dev eth0 parent 1:20 handle 20:0 sfq perturb 10
iptables -A FORWARD -t mangle -s 192.168.8.0/24 -i eth1 -p tcp --sport 80 -j MARK --set-mark 10
iptables -A FORWARD -t mangle -s 192.168.8.0/24 -i eth1 -p tcp --dport 80 -j MARK --set-mark 10
iptables -A FORWARD -t mangle -s 192.168.8.0/24 -i eth1 -p tcp --sport 443 -j MARK --set-mark 10
iptables -A FORWARD -t mangle -s 192.168.8.0/24 -i eth1 -p tcp --dport 443 -j MARK --set-mark 10
<span
style="color: rgb(128, 128, 128);"><i>#Privileged computers (Whitelist)</i></span>
<span
style="color: rgb(128, 128, 128);"><i>#surera</i></span>
iptables -A OUTPUT -t mangle -o eth0 --source 192.168.7.5 -j MARK --set-mark 5
(...)
<span
style="color: rgb(128, 128, 128);"><i>#</i></span>
tc filter add dev eth0 protocol ip parent 1:0 prio 5 handle 5 fw flowid 1:5
tc filter add dev eth0 protocol ip parent 1:0 prio 10 handle 10 fw flowid 1:10
tc filter add dev eth0 protocol ip parent 1:0 prio 15 handle 15 fw flowid 1:15
tc filter add dev eth0 protocol ip parent 1:0 prio 20 handle 20 fw flowid 1:20
tc filter add dev eth0 protocol ip parent 1:0 prio 25 handle 25 fw flowid 1:25
<span
style="color: rgb(128, 128, 128);"><i>#Print tc statictics</i></span>
<span
style="color: rgb(128, 128, 128);"><i>#tc -s -d class show dev eth0</i></span>
<span
style="color: rgb(128, 128, 128);"><i>#tc -s -d qdisc show dev eth0</i></span>
<span
style="color: rgb(136, 0, 136);"><b>echo</b></span> <span
style="color: rgb(221, 0, 0);">"Outbound shaping added to surera"</span>
<b>}</b>
<span style="color: rgb(255, 0, 255);"><b>stop()</b></span> <b>{</b>
<span
style="color: rgb(136, 0, 136);"><b>echo</b></span> <span
style="color: rgb(221, 0, 0);">"stop ..."</span>
<span
style="color: rgb(128, 128, 128);"><i># Reset everything to a known state (cleared)</i></span>
<span
style="color: rgb(128, 128, 128);"><i>#flush de reglas</i></span>
<span
style="color: rgb(0, 128, 0);">$IPTABLES</span> -F
<span
style="color: rgb(0, 128, 0);">$IPTABLES</span> -X
<span
style="color: rgb(0, 128, 0);">$IPTABLES</span> -Z
<span
style="color: rgb(0, 128, 0);">$IPTABLES</span> -t nat -F
<span
style="color: rgb(128, 128, 128);"><i>#Borrar clase entera</i></span>
<span
style="color: rgb(0, 128, 0);">$TC</span> qdisc del dev eth0 root
<span
style="color: rgb(136, 0, 136);"><b>echo</b></span> <span
style="color: rgb(221, 0, 0);">"Shaping removed on surera"</span>
<b>}</b>
<span style="color: rgb(255, 0, 255);"><b>status()</b></span> <b>{</b>
<span
style="color: rgb(136, 0, 136);"><b>echo</b></span> <span
style="color: rgb(221, 0, 0);">"[iptables]"</span>
<span
style="color: rgb(0, 128, 0);">$IPTABLES</span> -L -v -n
<span
style="color: rgb(0, 128, 0);">$IPTABLES</span> -L -v -n -t nat
<span
style="color: rgb(136, 0, 136);"><b>echo</b></span> <span
style="color: rgb(221, 0, 0);">"---- qdisc parameters ----------"</span>
tc qdisc <span
style="color: rgb(204, 0, 204);"><b>ls</b></span> dev eth0
<span
style="color: rgb(136, 0, 136);"><b>echo</b></span> <span
style="color: rgb(221, 0, 0);">"---- Class parameters ----------"</span>
tc class <span
style="color: rgb(204, 0, 204);"><b>ls</b></span> dev eth0
<span
style="color: rgb(136, 0, 136);"><b>echo</b></span> <span
style="color: rgb(221, 0, 0);">"---- filter parameters ---------"</span>
tc filter <span
style="color: rgb(204, 0, 204);"><b>ls</b></span> dev eth0
<span
style="color: rgb(128, 128, 128);"><i>#Print tc statictics</i></span>
<span
style="color: rgb(136, 0, 136);"><b>echo</b></span> <span
style="color: rgb(221, 0, 0);">"---- tc class statistics -------"</span>
tc -s -d class show dev eth0
<span
style="color: rgb(136, 0, 136);"><b>echo</b></span> <span
style="color: rgb(221, 0, 0);">"---- tc qdisc statistics -------"</span>
tc -s -d qdisc show dev eth0
<b>}</b>
<span style="color: rgb(255, 0, 255);"><b>restart()</b></span> <b>{</b>
<span
style="color: rgb(136, 0, 136);"><b>echo</b></span> <span
style="color: rgb(221, 0, 0);">"restart ..."</span>
start
<b>}</b>
<span style="color: rgb(255, 0, 255);"><b>reload()</b></span> <b>{</b>
<span
style="color: rgb(136, 0, 136);"><b>echo</b></span> <span
style="color: rgb(221, 0, 0);">"start ..."</span>
start
<b>}</b>
<span style="color: rgb(255, 0, 255);"><b>force_reload()</b></span> <b>{</b>
<span
style="color: rgb(136, 0, 136);"><b>echo</b></span> <span
style="color: rgb(221, 0, 0);">"force-reload ..."</span>
start
<b>}</b>
<b>case</b> <span style="color: rgb(0, 128, 0);">$1</span><b> in</b>
start<b>)</b>
start
<b>;;</b>
stop<b>)</b>
stop
<b>;;</b>
status<b>)</b>
status
<b>;;</b>
restart<b>)</b>
restart
<b>;;</b>
reload<b>)</b>
reload
<b>;;</b>
force-reload<b>)</b>
force_reload
<b>;;</b>
*<b>)</b>
<span
style="color: rgb(136, 0, 136);"><b>echo</b></span> <span
style="color: rgb(221, 0, 0);">"Usage: iptables_tc {start|stop|restart|reload|force-reload|status}"</span>
<span
style="color: rgb(128, 128, 128);"><i>#echo "Usage: ${0##*/} {start|stop|restart|reload|status}"</i></span>
<b>;;</b>
<b>esac</b>
<span style="color: rgb(136, 0, 136);"><b>exit</b></span> 0
</pre>
<br>
C Hamel wrote:
<blockquote cite="mid200601261710.07894.yogich@sc2000.net" type="cite">
<pre wrap="">(1) I have set up NAT on kubuntu the same as I did on three other distros
--and was delighted that I didn't have to roll my own kernel, this time! :-)
The rub lies in the fact that I do not know where to save the iptables file.
The command, '/etc/init.d/iptables save' yields an error because the
directory is not there. Obviously, the Debian architecture is different from
Gentoo/SuSE/Red Hat, et. al., and I am uncertain as to where to save the
rules. Consequently (for now) I have unlocked root access to VTs & created
the 'boot.local' file in /etc/init.d with the necessary commands in it which
symlink resides in /etc/rcS.d (again, for now, hopefully) until I can find
out where it actually belongs. I didn't find it in the docs. Did I miss
something?
(2) I like the screen to clear when I log out from a VT. SuSE had a neat
file in /etc/bash called 'bash_logout' in which one could enter the word
'clear' and that would happen automagically from then, on. I emulated that
w/Gentoo but it doesn't seem to work in Debian. Again, no /etc/bash
directory and when it was created it was ignored.
Anyone able to solve these issues will have my blessing. ;-)
Thanks!
</pre>
</blockquote>
<br>
</body>
</html>