<?xml version="1.0" encoding="UTF-8"?><!-- generator="wordpress.com" -->
<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/"
	>

<channel>
	<title>iptables &amp;laquo; WordPress.com Tag Feed</title>
	<link>http://en.wordpress.com/tag/iptables/</link>
	<description>Feed of posts on WordPress.com tagged "iptables"</description>
	<pubDate>Thu, 26 Nov 2009 06:49:00 +0000</pubDate>

	<generator>http://en.wordpress.com/tags/</generator>
	<language>en</language>

<item>
<title><![CDATA[Basic IPTABLES]]></title>
<link>http://sanhom.wordpress.com/2009/11/22/basic-iptables/</link>
<pubDate>Sun, 22 Nov 2009 01:23:38 +0000</pubDate>
<dc:creator>sanhom</dc:creator>
<guid>http://sanhom.wordpress.com/2009/11/22/basic-iptables/</guid>
<description><![CDATA[Title: Basic IPTABLES iptables &#8211;policy INPUT DROP iptables &#8211;policy OUTPUT DROP iptables ]]></description>
<content:encoded><![CDATA[<div class='snap_preview'><p>Title: Basic IPTABLES</p>
<p>iptables &#8211;policy INPUT DROP<br />
iptables &#8211;policy OUTPUT DROP<br />
iptables &#8211;policy FORWARD DROP</p>
<p>[INPUT]<br />
iptables -A INPUT -m state &#8211;state RELATED,ESTABLISHED -j ACCEPT<br />
iptables -A INPUT -p icmp -m icmp &#8211;icmp-type 8 -j ACCEPT<br />
iptables -A INPUT -s 127.0.0.1 -d 127.0.0.1 -j ACCEPT</p>
<p>iptables -A INPUT -s 192.168.111.151 -d 192.168.111.158 -p tcp -m tcp &#8211;dport 80 -j ACCEPT<br />
iptables -A INPUT -s 192.168.111.151 -d 192.168.111.158 -p tcp -m tcp &#8211;dport 22 -j ACCEPT</p>
<p>[OUTPUT]<br />
iptables -A OUTPUT -m state &#8211;state RELATED,ESTABLISHED -j ACCEPT<br />
iptables -A OUTPUT -p icmp -m icmp &#8211;icmp-type 8 -j ACCEPT<br />
iptables -A OUTPUT -s 127.0.0.1 -d 127.0.0.1 -j ACCEPT</p>
<p>iptables -A OUTPUT -s 192.168.111.158 -d 192.168.111.151 -p udp -m udp &#8211;dport 123 -j ACCEPT</p>
<p>iptables -A OUTPUT -s 192.168.111.158 -d 192.168.111.2 -j ACCEPT</p>
</div>]]></content:encoded>
</item>
<item>
<title><![CDATA[ Open Passive FTP in iptable]]></title>
<link>http://amshameer.wordpress.com/2009/11/21/open-passive-ftp-in-iptable/</link>
<pubDate>Sat, 21 Nov 2009 09:28:12 +0000</pubDate>
<dc:creator>Shameer A M</dc:creator>
<guid>http://amshameer.wordpress.com/2009/11/21/open-passive-ftp-in-iptable/</guid>
<description><![CDATA[To Open Passive FTP in iptable root login is require. If you want to open port range from 30000:6400]]></description>
<content:encoded><![CDATA[<div class='snap_preview'><p>To Open Passive FTP in iptable root login is require.</p>
<p>If you want to open port range from 30000:64000 then run the following command from shell.</p>
<p>iptables -A INPUT -p tcp -m tcp –dport 30000:64000 -j ACCEPT</p>
<p>Similarly you can open passive post range as per your requirement.</p>
</div>]]></content:encoded>
</item>
<item>
<title><![CDATA[logowanie zdalne przez ssh w LAN]]></title>
<link>http://trycode.wordpress.com/2009/11/18/logowanie-zdalne-przez-ssh-w-lan/</link>
<pubDate>Tue, 17 Nov 2009 23:43:46 +0000</pubDate>
<dc:creator>trym</dc:creator>
<guid>http://trycode.wordpress.com/2009/11/18/logowanie-zdalne-przez-ssh-w-lan/</guid>
<description><![CDATA[Należy dodać wpis do firewall, plik firewall najlepiej utworzyć w /etc/init.d/ (jeśli takowego nie m]]></description>
<content:encoded><![CDATA[<div class='snap_preview'><p>Należy dodać wpis do firewall, plik firewall najlepiej utworzyć w<em> /etc/init.d/</em> (jeśli takowego nie mamy):</p>
<p><code># touch /etc/init.d/firewall</code></p>
<p>i dodajemy wpis:, który odblokuje port dla ssh (22):</p>
<blockquote><p>iptables -A INPUT -p tcp &#8211;dport 22 -j ACCEPT</p></blockquote>
<p>następnie logujemy się na np. 192.168.1.1, po &#8216;-l&#8217; podajemy login<br />
<code>$ ssh -l bialy 192.168.1.1</code></p>
</div>]]></content:encoded>
</item>
<item>
<title><![CDATA[Stawiamy sobie NAT... oraz troszkę o iptables, a jeszcze mniej o DHCP.]]></title>
<link>http://wojlys.wordpress.com/2009/11/17/stawiamy-sobie-nat-oraz-troszke-o-iptables-a-jeszcze-mniej-o-dhcp/</link>
<pubDate>Tue, 17 Nov 2009 12:56:05 +0000</pubDate>
<dc:creator>wojlys</dc:creator>
<guid>http://wojlys.wordpress.com/2009/11/17/stawiamy-sobie-nat-oraz-troszke-o-iptables-a-jeszcze-mniej-o-dhcp/</guid>
<description><![CDATA[Wstęp W wiekszości przypadków ludzie nie mający za wiele wspólnego z systemem Linuks interesują się ]]></description>
<content:encoded><![CDATA[<div class='snap_preview'><h1>Wstęp</h1>
<p>W wiekszości przypadków ludzie nie mający za wiele wspólnego z systemem Linuks interesują się nim w kontekście prostego serwera dostępowego do sieci Internet.<br />
Nie potrzeba mieć jakiejś szczególnej wiedzy, aby zainstalować dzisiaj Linuksa. W sieci jest pełno dystrybucji przyjaznych dla użytkownika, posiadających konfiguratory i/lub automatycznie konfigurujących siec &#8211; to pięknie, ale czasem warto wiedzieć jak coś skonfigurować &#8220;z palca&#8221;.<br />
Poniżej przedstawiam sposób, w jaki ja, na szybko, ustawiłbym serwer dostępowy.<br />
Podany poniżej przepis działał będzie na pewno na debianie/ubuntu, powinien też działać na klonach RedHat (Centos,Whitebox,Fedora) oraz na większości innych dystrybucji.<br />
<!--more--></p>
<h1>Do dzieła </h1>
<p>Po zainstalowaniu czystego systemu operacyjnego (najlepiej bez serwera X i innych zbędnych narzędzi) zalecam zaktualizowanie systemu do najnowszej wersji w ramach danego wydania, zainstalować swój ulubiony edytor tekstowy i przygotować się na trochę pisania na klawiaturze <img src='http://s.wordpress.com/wp-includes/images/smilies/icon_wink.gif' alt=';-)' class='wp-smiley' /> .</p>
<h2>konfiguracja interfejsów</h2>
<p>Aby nasz komputer mógł pracować jako serwer dostępowy do sieci Internet musi posiadać przynajmniej dwa interfejsy sieciowe. Dla celów opisowych przyjmiemy iż:</p>
<ul>
<li>eth0 &#8211; interfejs od strony sieci lokalnej, na której będzie nasłuchiwał serwer DHCP</li>
<li>eth1 &#8211; interfejs od strony sieci Internet, skonfigurowany automatycznie przez DHCP</li>
</ul>
<p>Interfejs eth1 jest konfigurowany automatycznie przez DHCP dostawcy Internetu (jak to ma miejsce w większości przypadków u lokalnych dostawców Internetu), ale nie niczemu nie przeszkadza, jeśli statycznie skonfigurujemy ten interfejs.<br />
Konfiguracja interfejsów sieciowych w systemie ubuntu/debian znajduje się w pliku <b>/etc/network/interfaces</b>.<br />
W tej chwili mój plik wygląda następująco:</p>
<blockquote><p>
 auto lo<br />
 iface lo inet loopback</p>
<p> auto eth1<br />
 iface eth1 dhcp</p>
<p> auto eth0<br />
 iface eth0 inet static<br />
 address 1.1.1.1<br />
 netmask 255.255.255.0<br />
 network 1.1.1.0<br />
 broadcast 1.1.1.255
</p></blockquote>
<p>Interfejs eth1 jest konfigurowany automatycznie, ale można jego deklaracje skasować i ustawić podobnie do tej, z eth0 wypełniając odpowiednio parametry. Należy pamiętać, iż przy ustawianiu statycznym interfejsu od strony Internetu trzeba jeszcze wskazać w pliku <b>/etc/resolv.conf</b>.<br />
Przykład pliku:</p>
<blockquote><p>
search domena.pl<br />
nameserver x.x.x.x<br />
nameserver x.x.x.x
</p></blockquote>
<p>Opcja search powoduje, że w momencie gdy będziemy chcieli odszukać w sieci komputer i nie będzie on możliwy do odnalezienia przy nazwie, która podaliśmy, to do tej nazwy doda domenę i tak zestawioną nazwę hosta postara się odnaleźć.</p>
<p>Parametr nameserver wskazuje adresy IP serwerów nazw dla naszego komputera. Warto je zapamiętać, bo potrzebne będą przy konfiguracji serwera DHCP (o ile nie posiadamy własnego serwera DNS).</p>
<p>Po zmianie w pliku <b>interfaces</b> wydajemy polecenie <b>/etc/init.d/networking restart</b> i aby wszystko sprawdzić, czy się zgadza <b>ifconfig</b></p>
<h2>Konfiguracja DHCP</h2>
<p>DHCP służy do automatycznego konfigurowania komputerów w sieci. Przedstawiony tutaj przykład jest bardzo prosty, z samym serwerem DHCP można zrobić dużo, ale to nie jest temat na ten artykuł.<br />
Instalujemy paczkę <b>dhcp3-server</b> za pomocą polecenia <b>apt-get install</b>, a następnie edytujemy dwa pliki.<br />
<b>/etc/default/dhcp3-server</b><br />
W parametrze INTERFACES wpisujemy &#8220;eth0&#8243;, lub inny interfejs, na którym serwer DHCP na nasłuchiwać.</p>
<p><b>/etc/dhcp3/dhcpd.conf</b><br />
Ustawiamy:</p>
<ul>
<li>option domain-name &#8220;twoja_domena&#8221;;</li>
<li>option domain-name-servers x.x.x.x,y.y.y.y;  &#8211; adresy ip serwerów DNS oddzielonych przecinkami</li>
</ul>
<p>Usuwamy komentarz (znak &#8216;#&#8217;) z sekcji subnet i ustawiamy następująco:</p>
<blockquote><p>
subnet 1.1.1.0 netmask 255.255.255.0 {<br />
range 1.1.1.2 1.1.1.200;<br />
option routers 1.1.1.1;<br />
}
</p></blockquote>
<p>Oczywiście możecie ustawić to w swoich plikach tak, aby odpowiadało waszym zakresom IP.<br />
Parametr &#8220;range&#8221; wskazuje ile adresów IP będzie przydzielanych przez serwer DHCP, routers przekazuje komputerom klienckim adres IP routera.<br />
Po wszystkich tych czynnościach przeładowujemy serwer DHCP <b>/etc/init.d/dhcp3-server restart</b>.<br />
Jeśli będą wyświetlały się jakieś błędy zobaczcie do pliku konfiguracyjnego czy nie zapomnieliście gdzieś dać średnika &#8216;;&#8217; lub czy wszystkie nawiasy są zamknięte. Konkretne miejsce znajdziecie w syslogu.</p>
<h2>Konfiguracja NAT</h2>
<p>NAT w Linuksie konfiguruje się za pomocą iptables.<br />
Ja to robię w następujący sposób:<br />
Tworzę plik o dowolnej nazwie w /etc/init.d i w nim podaję regułki firewall:<br />
<code><br />
echo '1' &#62; /proc/sys/net/ipv4/ip_forward<br />
iptables -t nat -F<br />
iptables -t nat -A POSTROUTING -o eth0 -j MASQUERADE<br />
</code></p>
<p>pierwsza linia pozwala na przekazywanie pakietów między interfejsami, druga czyści łańcuch &#8220;nat&#8221;, trzecia ustawia maskowanie pakietów &#8211; tutaj podajemy nazwę interfejsu od strony Internetu.</p>
<p>Tak przygotowany plik ustawiamy jako wykonywujący (chmod +x nazwa_pliku) oraz linkujemy go do rcx.d (ln -s /etc/init.d/nazwa_pliku /etc/rc2.d/S99nazwapliku). Owe rcx.d jest odpowiedzialne za uruchamianie odpowiednich usług w zależności od trybu działania systemu (wykracza to poza zakres tego artykułu). Jeśli nie jesteście pewni to zlinkujcie ten plik do rc2.d, rc3.d i rc5.d.</p>
<p>Po restarcie systemu sprawdźcie, czy wszystko działa.</p>
</div>]]></content:encoded>
</item>
<item>
<title><![CDATA[Como colocar L7 no seu debian usando os pacotes do debian]]></title>
<link>http://knoppixdebian.wordpress.com/2009/11/15/como-colocar-l7-no-seu-debian-usando-os-pacotes-do-debian/</link>
<pubDate>Mon, 16 Nov 2009 00:04:59 +0000</pubDate>
<dc:creator>knoppixdebian</dc:creator>
<guid>http://knoppixdebian.wordpress.com/2009/11/15/como-colocar-l7-no-seu-debian-usando-os-pacotes-do-debian/</guid>
<description><![CDATA[Este é um artigo explicando como colocar o suporte ao Layer7 no Debian Lenny e para isso precisaremo]]></description>
<content:encoded><![CDATA[<div class='snap_preview'><p><ins><ins></ins></ins> Este é um artigo explicando como colocar o suporte ao <em>Layer7</em> no <em>Debian Lenny</em> e para isso precisaremos modificar tanto o pacote .deb do kernel quanto do iptables, porque ambos precisarão ter suporte à este. O Debian é uma distribuição GNU/<a href="http://www.vivaolinux.com.br/linux/">Linux</a> bem tradicionalista, muito estável, com excelente performance e com mais de 20.000 pacotes binários em seus repositórios oficiais.</p>
<p>Vamos precisar dos seguintes pacotes já pré-instalados para que não tenhamos erros na compilação dos pacotes:</p>
<p><strong># aptitude install fakeroot libncurses5-dev kernel-package dpkg-dev file gcc g++ libc6-dev make patch  <a href="http://www.vivaolinux.com.br/artigo/Adicionando-suporte-ao-Layer7-no-Debian-Lenny#">perl</a> autoconf automake dh-make debhelper devscripts fakeroot gnupg g77 gpc xutils lintian quilt libtool libselinux1-dev linuxdoc-tools zlib1g-dev</strong></p>
<p>Primeiramente vamos baixar o fonte do kernel, porque a partir dele vamos aplicar os patches que necessitamos e logo após geraremos novos pacotes .deb. Abaixo nós temos os comandos para baixarmos nosso fonte do kernel e logo após descompactarmos ele:</p>
<p><strong># cd /usr/src<br />
# aptitude install linux-source-2.6.26<br />
# tar -xvjpf linux-source-2.6.26.tar.bz2</strong></p>
<p>Criaremos um link simbólico para facilitar nossa vida:</p>
<p><strong># ln -sf linux-source-2.6.26 linux</strong></p>
<p>Agora baixaremos o Layer7 para aplicarmos no kernel e no iptables mais tarde. Para isso acessaremos  <a href="http://sourceforge.net/projects/l7-filter/files/">http://sourceforge.net/projects/l7-filter/files/</a> e baixaremos o netfilter-layer7-v2.22.tar.gz em /usr/src. Logo em seguida descompactaremos nosso programa:</p>
<p><strong># cd /usr/src<br />
# tar -xvzpf netfilter-layer7-v2.22.tar.gz</strong></p>
<p>Agora que temos os arquivos necessários precisamos copiar o patch para o kernel e aplicá-lo. Como nosso kernel no Debian Lenny é o 2.6.26, então usaremos o patch para kernels de 2.6.25 à 2.6.28:</p>
<p><strong># cd netfilter-layer7-v2.22<br />
# cp kernel-2.6.25-2.6.28-layer7-2.22.patch /usr/src/linux/<br />
# cd /usr/src/linux<br />
# patch -p1 &#60; kernel-2.6.25-2.6.28-layer7-2.22.patch</strong></p>
<p>Agora que aplicamos o patch no kernel, precisamos habilitá-lo antes de compilarmos nosso novo kernel:</p>
<p><strong># cp /boot/config-2.6.26-2-686 /usr/src/linux/.config<br />
# make menuconfig</strong></p>
<p>Siga o menu abaixo para habilitar o Layer7 no kernel:</p>
<p>Networking &#8212;&#62; Networking options &#8212;&#62; Network packet filtering framework (Netfilter) &#8212;&#62; Core Netfilter Configuration &#8212;&#62;<br />
&#60;M&#62;   &#8220;layer7&#8243; match support<br />
[ ]     Layer 7 debugging output</p>
<p>Volte e saia salvando. Agora para gerarmos nosso novo kernel faremos os comandos abaixo:</p>
<p><strong># make-kpkg clean<br />
# fakeroot make-kpkg &#8211;initrd &#8211;append-to-version=-custom kernel_image kernel_headers </strong></p>
<p>Bem, nesse momento seria interessante uma pipoca e um bom filme, pois esse procedimento levará bastante tempo. Se tudo correr bem no final teremos o pacote .deb do kernel e instalaremos como abaixo:</p>
<p><strong># cd /usr/src<br />
# dpkg -i linux-image-2.6.26-custom_2.6.26-custom-10.00.Custom_i386.deb</strong></p>
<p>Agora que instalamos nosso novo kernel, precisamos apontar ele no <em>/boot/grub/menu.lst</em> alterando o parâmetro &#8220;default 0&#8243; para o seu novo kernel. No meu caso aqui ficou &#8220;default 2&#8243;. Tendo feito isso, reinicie seu sistema e certifique-se de entrar com seu novo kernel. Após o boot, para ter certeza execute:</p>
<p><strong># uname -a</strong><br />
Linux debian 2.6.26-custom #1 SMP Mon Oct 19 17:36:31 BRST 2009 i686 GNU/Linux</p>
<p>Lá está nosso kernel custom carregado. Agora partiremos para o iptables.</p>
<p>Copiaremos xt_layer7.h do kernel para o lugar correto onde será usado na hora da compilação do iptables:</p>
<p><strong># cp /usr/src/linux-source-2.6.26/include/linux/netfilter/xt_layer7.h /usr/include/linux/netfilter/</strong></p>
<p>Agora vamos instalar nosso fonte do iptables. Antes certifique-se que os repositórios de fontes estão habilitados no <em>/etc/apt/sources.list</em>:</p>
<p><strong># cat /etc/apt/sources.list</strong></p>
<div>deb http://ftp.br.debian.org/debian/ lenny main<br />
deb-src http://ftp.br.debian.org/debian/ lenny main # repositório de fonte<br />
deb http://security.debian.org/ lenny/updates main<br />
deb-src http://security.debian.org/ lenny/updates main # repositório de fonte<br />
deb http://volatile.debian.org/debian-volatile lenny/volatile main<br />
deb-src http://volatile.debian.org/debian-volatile lenny/volatile main</div>
<p>Para instalar o fonte do iptables façamos:</p>
<p><strong># cd /usr/src<br />
# apt-get source iptables</strong></p>
<p>Agora vamos copiar os arquivos necessários para que layer7 seja incorporado ao nosso iptables:</p>
<p><strong># cp /usr/src/netfilter-layer7-v2.22/for_older_iptables/iptables-1.4.1.1-for-kernel-2.6.20forward/* /usr/src/iptables-1.4.2/extensions</strong></p>
<p>Bem, só precisamos gerar nosso novo pacote iptables e para isso façamos os procedimentos abaixo:</p>
<p><strong># cd /usr/src/iptables-1.4.2<br />
# dpkg-buildpackage -rfakeroot</strong></p>
<p>No final do comando acima teremos nosso pacote .deb do iptables e para instalá-lo façamos:</p>
<p><strong># cd /usr/src<br />
# dpkg -i iptables_1.4.2-6_i386.deb</strong></p>
<p>Isso vai nos gerar um problema, porque quando fizermos um &#8220;aptitude dist-upgrade&#8221;, por exemplo, o sistema vai querer atualizar o iptables com a versão oficial. Para que isso não ocorra criaremos, se não existir, o arquivo <em>/etc/apt/preferences</em> e colocaremos nele as seguintes linhas:</p>
<div>Package: iptables<br />
Pin: version 1.4.2<br />
Pin-Priority: 1001</div>
<p>Para usarmos nosso novo sistema de filtragem Layer7 também precisaremos dos protocolos que iremos utilizar, que podem ser baixados do seguinte site:</p>
<ul>
<li> <a href="http://l7-filter.sourceforge.net/protocols">http://l7-filter.sourceforge.net/protocols</a></li>
</ul>
<p>São os arquivos .pat e devem ser colocados em /etc/l7-protocols/. Esse diretório não vai existir, logo precisamos criá-lo:</p>
<p><strong># mkdir /etc/l7-protocols/</strong></p>
<p>Agora vamos fazer um teste prático. Baixaremos o .pat do ssh:</p>
<p><strong># cd /etc/l7-protocols<br />
# wget -c</strong> <a href="http://l7-filter.sourceforge.net/layer7-protocols/protocols/ssh.pat">http://l7-filter.sourceforge.net/layer7-protocols/protocols/ssh.pat</a></p>
<p>Vamos carregar nosso módulo:</p>
<p><strong># modprobe xt_layer7</strong></p>
<p>E agora a nossa regra para bloquear o protocolo &#8220;ssh&#8221;, mas o &#8220;telnet&#8221; na porta 22 funcionará. Estamos bloqueando o protocolo independente da sua porta.</p>
<p>Em nosso servidor fiz a regra abaixo que diz para bloquear qualquer ssh da estação 192.168.10.253 para ele:</p>
<p><strong># iptables -I INPUT -s 192.168.10.253 -m layer7 &#8211;l7proto ssh -j DROP</strong></p>
<p>Da estação 192.168.10.253 fiz primeiro um telnet na porta 22 para mostrar que a regra permite o acesso:</p>
<p><strong># telnet 192.168.10.175 22</strong><br />
Trying 192.168.10.175&#8230;<br />
Connected to 192.168.10.175.<br />
Escape character is &#8216;^]&#8217;.<br />
SSH-2.0-OpenSSH_5.1p1 Debian-5</p>
<p>Como podem ver a conexão fechou com o serviço ssh. Agora farei o ssh para o servidor:</p>
<p><strong># ssh 192.168.10.175</strong><br />
&#8230;&#8230;</p>
<p>Não conecta porque o protocolo ssh está bloqueado. Funcionou perfeitamente!</p>
<p>Bem, espero ter ajudado. <img src='http://s.wordpress.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
<p>Marcelo Gondim &#60;gondim @ linuxinfo.com.br&#62;</p>
<p>Eu encontrei no vivaolinux</p>
<p>olhem bem como unstable ja tem um pacote com os protocolos do l7 ok</p>
</div>]]></content:encoded>
</item>
<item>
<title><![CDATA[Tutorial básico de iptables]]></title>
<link>http://pratesdicas.wordpress.com/2009/11/12/tutorial-basico-de-iptables/</link>
<pubDate>Thu, 12 Nov 2009 17:14:17 +0000</pubDate>
<dc:creator>alexandreprates</dc:creator>
<guid>http://pratesdicas.wordpress.com/2009/11/12/tutorial-basico-de-iptables/</guid>
<description><![CDATA[O iptables é uma interface de configuração do netfilter, um firewall que funciona como um filtro de ]]></description>
<content:encoded><![CDATA[<div class='snap_preview'><p>O iptables é uma interface de configuração do netfilter, um firewall que funciona como um filtro de pacotes em sistemas Linux. Sua principal função é proteger a rede de ataques externos.</p>
<p>O netflter começou a ser implementado no kernel Línux a partir da versão 2.4. Você pode encontrar a documentação completa <a href="http://www.netfilter.org/"> aqui </a>.</p>
<p>O iptables trabalha com a seguinte configuração:</p>
<p>#iptables [-t tabela] [opção] [chain] [dados] -j [ação]</p>
<p>A tabela default é a tabela filter e contem as seguintes opções:</p>
<p>INPUT &#8211; todos os pacotes que entram no computador através para internet.<br />
OUTPUT &#8211; todos os pacotes que o computador envia pela rede.<br />
FORWARD &#8211; pacote que são encaminhado para outros computadores da rede.</p>
<p>Na figura abaixo é descrito o funcionamento do filtro do iptable:</p>
<div id="attachment_21" class="wp-caption alignnone" style="width: 336px"><img class="size-full wp-image-21" title="IPTables" src="http://pratesdicas.wordpress.com/files/2009/11/iptables.jpeg" alt="IPTables" width="326" height="367" /><p class="wp-caption-text">Diagrama de funcionamento do iptables</p></div>
<p><strong>Principais opções da tabela filter</strong></p>
<p>-p &#8211;&#62; Policy (política). É a politica do firewall, inicialmente esta configurada como ACCEPT para INPUT, OUTPUT e FOWARD, ou seja aceita qualquer pacote. Para negar o trafego de qual pacote deve usar a opções DROP.</p>
<p>-A &#8211;&#62; Append (anexar). Acrescenta uma nova regra a tabela atual. A opção -A tem prioridade sobre a opção -p, por isso é normal negar todas entradas e saídas de pacotes da rede com DROP, e depois usar o -A para liberar pacotes específicos.</p>
<p>-L &#8211;&#62; lista as regras atuais.</p>
<p>-D &#8211;&#62; (Delete). Apaga uma regra. Pode usado apos <strong><em>tabela numero da linha </em></strong></p>
<p>-F &#8211;&#62; (Flush) &#8211; Apaga todas as regras, mas não altera  a politica.</p>
<p>Dados:</p>
<p>-s &#8211;&#62; source . Especifica a origem dos dados. pode ser um endereço IP.</p>
<p>-d &#8211;&#62; (Destination) . ESpecifica o destino do pacote.</p>
<p>-p &#8211;&#62; (Protocol) &#8211; Especifica o protocolo a ser filtado.</p>
<p>-i &#8211;&#62; In interface &#8211; Especifica a interface de saída.</p>
<p>-o &#8211;&#62; Out-Interface (interface de saída). Especifica a interface de saída. Similar a -i, inclusive nas flexibilidades. O -o não pode ser utilizado com a chain INPUT.</p>
<p>-! &#8211;&#62; Exclusão. Utilizado com -s, -d, -p, -i, -o e outros, para excluir o argumento.</p>
<p>&#8211;sport &#8211;&#62; Source Port. Porta de origem. Só funciona com as opções -p udp e -p tcp.</p>
<p>&#8211;dport &#8211;&#62; Destination Port. Porta de destino. Só funciona com as opções -p udp e -p tcp.</p>
<p>Ações<br />
As principais ações são:</p>
<p>ACCEPT &#8211;&#62; Aceitar. Permite a passagem do pacote.</p>
<p>DROP &#8211;&#62; Abandonar. Não permite a passagem do pacote, descartando-o. Não avisa a origem sobre o ocorrido.</p>
<p>REJECT &#8211;&#62; Igual ao DROP, mas avisa a origem sobre o ocorrido (envia pacote icmp unreachable).</p>
<p>LOG &#8211;&#62; Cria um log referente à regra, em /var/log/messages. Usar antes de outras ações.</p>
</div>]]></content:encoded>
</item>
<item>
<title><![CDATA[OpenVPN connected but No Surf in Ubuntu]]></title>
<link>http://jaidane.wordpress.com/2009/11/10/openvpn-connected-but-no-surf-in-ubuntu/</link>
<pubDate>Tue, 10 Nov 2009 00:26:47 +0000</pubDate>
<dc:creator>Maher</dc:creator>
<guid>http://jaidane.wordpress.com/2009/11/10/openvpn-connected-but-no-surf-in-ubuntu/</guid>
<description><![CDATA[If you&#8217;re using an OpenVPN Server to surf in Ubuntu, maybe you experienced this strange proble]]></description>
<content:encoded><![CDATA[<div class='snap_preview'><p style="text-align:left;">If you&#8217;re using an OpenVPN Server to surf in Ubuntu, maybe you experienced this strange problem : <span style="color:#ff9900;">you can connect but you cannot surf</span> <img class="alignnone size-full wp-image-161" title="icon_questiongif" src="http://jaidane.wordpress.com/files/2009/04/icon_questiongif.png" alt="icon_questiongif" width="18" height="18" /> !    <a href="http://jaidane.wordpress.com/2009/11/10/openvpn-connected-but-no-surf-in-ubuntu/#more-573"><span style="color:#ffff00;"><strong><span style="color:#fbea74;">This how to fix it..</span>.</strong></span></a></p>
<p><strong><br />
</strong></p>
<p><img class="aligncenter size-full wp-image-599" title="vpn" src="http://jaidane.wordpress.com/files/2009/11/vpn.png" alt="vpn" width="321" height="161" /></p>
<p><!--more--></p>
<p>Before we start check your current <a href="http://www.ip-adress.com/" target="_blank">IP online </a> and save it.</p>
<p>The first thing you have to know is that you shouldn&#8217;t use NetworkManager Applet to configure your OpenVPN Connexion, it seems that there&#8217;s a problem with vpn connections when using this applet (atleast with Intrepid), you can connect but traffic isn&#8217;t redirected correctly, so <span style="color:#b9f905;">let&#8217;s first make sure you&#8217;re correctly  connected</span><span style="color:#b9f905;"> !</span> The best thing to do is to download the configuration files from the OpenVPN Server&#8217;s website (just look in the forum if you don&#8217;t find it, it&#8217;s generally an archive file with a *.conf file and a *.crt file, this last one is the certificate) and use&#8217;em directly in a shell console.</p>
<p>Copy the archive content files to</p>
<p><span style="color:#f7e807;">/etc/openvpn/</span></p>
<p>Type :</p>
<p><span style="color:#f7e807;">cd /etc/openvpn &#38;&#38; sudo openvpn yourserver.conf</span></p>
<p>Enter your login and password and wait till you see :</p>
<p><span style="color:#f7e807;">Initialization Sequence Completed</span></p>
<p>It means that you&#8217;re in.</p>
<p>Now to <span style="color:#b9f905;">make sure that you&#8217;re not facing a routing problem</span>, just type :</p>
<p><span style="color:#f7e807;">route -n</span></p>
<p>If you see tunX connections with new IPs, it&#8217;s OK you&#8217;re connected, if one of your web connected peripheral connections (ethX, athX&#8230;) is showing the IP of your OpenVPN Server as a destination you&#8217;re correctly routed.</p>
<p>Now <span style="color:#b9f905;">try to ping the tunX IP with a gateway</span>, if you&#8217;ve got this message :</p>
<p><span style="color:#f7e807;">ping: sendmsg: Operation not permitted </span></p>
<p><span style="color:#ffcc00;">You got the fix ! It&#8217;s a SIMPLE FIREWALL PROBLEM</span> <img class="alignnone size-full wp-image-153" title="icon_biggringif" src="http://jaidane.wordpress.com/files/2009/04/icon_biggringif.png" alt="icon_biggringif" width="18" height="18" /><span style="color:#ffcc00;"> !</span></p>
<p>To solve it, you have to edit :</p>
<p><span style="color:#f7e807;">/etc/firestarter/user-pre</span></p>
<p>First thing to do is to make it writable (it&#8217;s a read-only file) then paste these lines and save the file :</p>
<p><span style="color:#f7e807;"># Allow OpenVPN traffic<br />
$IPT -A INPUT -i tun+ -j ACCEPT<br />
$IPT -A OUTPUT -o tun+ -j ACCEPT</span></p>
<p>Restart Firestarter :</p>
<p><span style="color:#f7e807;">sudo /etc/init.d/firestarter restart</span></p>
<p>It should work now <img class="alignnone size-full wp-image-80" title="icon_smilegif" src="http://jaidane.wordpress.com/files/2009/04/icon_smilegif.png" alt="icon_smilegif" width="18" height="18" /> ! Just re-check your <a href="http://www.ip-adress.com/" target="_blank">Online IP</a> to see if it changed !</p>
</div>]]></content:encoded>
</item>
<item>
<title><![CDATA[Firewall/iptables...]]></title>
<link>http://krisagon.wordpress.com/2009/11/04/firewalliptables/</link>
<pubDate>Wed, 04 Nov 2009 13:27:05 +0000</pubDate>
<dc:creator>krisagon</dc:creator>
<guid>http://krisagon.wordpress.com/2009/11/04/firewalliptables/</guid>
<description><![CDATA[Para quem gostaria de estudar o tema, ai vai alguns link&#8217;s bem legais. http://www.vivaolinux.c]]></description>
<content:encoded><![CDATA[<div class='snap_preview'><p>Para quem gostaria de estudar o tema, ai vai alguns link&#8217;s bem legais.</p>
<p><a href="http://www.vivaolinux.com.br/artigo/Mecanismo-de-firewall-e-seus-conceitos">http://www.vivaolinux.com.br/artigo/Mecanismo-de-firewall-e-seus-conceitos</a><br />
<a href="http://www.tchelinux.org/2009/cultura/slides/Iptables-Entenda.pdf">http://www.tchelinux.org/2009/cultura/slides/Iptables-Entenda.pdf</a><br />
<a href="http://www.vivaolinux.com.br/artigo/Estrutura-do-Iptables/">http://www.vivaolinux.com.br/artigo/Estrutura-do-Iptables/</a><br />
<a href="http://www.vivaolinux.com.br/artigo/Estrutura-do-IPTables-2-a-tabela-nat/">http://www.vivaolinux.com.br/artigo/Estrutura-do-IPTables-2-a-tabela-nat/</a><br />
<a href="http://www.vivaolinux.com.br/artigo/255.255.255.0-A-matematica-das-mascaras-de-rede/">http://www.vivaolinux.com.br/artigo/255.255.255.0-A-matematica-das-mascaras-de-rede/</a><br />
<a href="http://www.vivaolinux.com.br/artigo/Seguranca-com-iptables-1/">http://www.vivaolinux.com.br/artigo/Seguranca-com-iptables-1/</a></p>
</div>]]></content:encoded>
</item>
<item>
<title><![CDATA[Linux Securirty Notes 15: IPTables 8: DMZ]]></title>
<link>http://kiranjith.wordpress.com/2009/11/04/linux-securirty-notes-15-iptables-8-dmz/</link>
<pubDate>Wed, 04 Nov 2009 09:11:00 +0000</pubDate>
<dc:creator>kiranjith</dc:creator>
<guid>http://kiranjith.wordpress.com/2009/11/04/linux-securirty-notes-15-iptables-8-dmz/</guid>
<description><![CDATA[IPTables with DMZ Let consider the interface to setup/understand the DMZ. eth0: external interface (]]></description>
<content:encoded><![CDATA[<div class='snap_preview'><p><b><span style="font-size:large;">IPTables with DMZ</span></b><br />
Let consider the interface to setup/understand the DMZ.</p>
<ul>
<li>eth0: external interface (192.168.1.0/24)</li>
<li>eth1: Internal Interface (10.0.0.0/8)</li>
<li>eth2: The DMZ zone  (172.16.0.0/16)</li>
</ul>
<p><b>Step 1:</b><br />
Create DNAT for all the servers in the DMZ zone (eth2) for accessing the service externally</p>
<div class="command">
<div style="color:blue;">
<i><b># iptables -t nat -A PREROUTING -d 192.168.1.2 -p tcp &#8211;dport 80 -j DNAT &#8211;to-destination 172.16.0.2</b></i>
</div>
<div style="color:blue;">
<i><b># iptables -t nat -A PREROUTING -d 192.168.1.2 -p tcp &#8211;dport 443 -j DNAT &#8211;to-destination 172.16.0.2</b></i>
</div>
</div>
<p>If any request comes to firewall with the destination IP as 192.168.1.2 and port as 80 will be DNATed to 172.16.0.2 in DMZone.<br />
Now test accessing the service in DMZone from Internel as well externel network. From both the network we will be able to access the server in the DMZone using the IP 192.168.1.2.</p>
<p><b>Step2:</b><br />
Configure the split DNS or 2 DNS systems (Inside&#38;Outside of the DMZone).<br />
<b>Step3:</b><br />
Setup rule for trusted network from the outside network(Internet) for the traffic which will allow system access (SSH).</p>
<div class="command">
<div style="color:blue;">
<i><b># iptables -A FORWARD -s 10.0.0.0/8 -j ACCEPT</b></i>
</div>
<div style="color:blue;">
<i><b># iptables -A FORWARD -s 172.16.0.0/16 -m state &#8211;state ESTABLISHED -j ACCEPT</b></i>
</div>
<div style="color:blue;">
<i><b># iptables -P FORWARD DROP</b></i>
</div>
</div>
<p>This will deny all access to the DMZone from the internet hosts, only allows the Internal network. Because the default policy of FORWARD chain is set to drop, we need to create the &#8220;state match&#8221; for the hosts in the DMZone(This will deny sourcing a new connection from the DMZone, only established connection will be permitted).</p>
<p><b><span style="font-size:large;">Dual DMZ Configuration</span></b><br />
This is the way of segmenting the servers to separate DMZones.<br />
Let consider the interface to setup/understand the Dual DMZ.</p>
<ul>
<li>eth0: externel interface (192.168.1.0/24)</li>
<li>eth1: Internel Interface (10.0.0.0/8)</li>
<li>eth2: The DMZ1 zone  (172.16.0.0/16) (Web servers)</li>
<li>eth3: The DMZ2 zone  (172.17.0.0/16) (DBMS, App servers like JBOSS, TOMCAT etc)</li>
</ul>
<p>Using this method we will be able to control the traffic from one DMZone to another. This is used for the scenarios of Application servers which need to contact the DB Servers located on separate server.</p>
<p>Here we have to permit only the DMZ1 to contact the DMZ2. all other traffic will be denied.So the servers in the DMZ2 zone will be more secured.</p>
<div class="command">
<div style="color:blue;">
<b><i># iptables -t nat -A FORWARD -s 172.16.0.0/16 -d 172.7.0.0/16 -j ACCEPT</i></b>
</div>
<div style="color:blue;">
<b><i># iptables -t nat -A FORWARD -m state &#8211;state ESTABLISED -s 172.17.0.0/16 -j ACCEPT</i></b>
</div>
<div style="color:blue;">
<b><i># iptables -t nat -P FORWARD DROP</i></b>
</div>
</div>
<p>This will make only the DMZ1 to contact the DMZ2. And from DMZ2 only the established connection will be permitted. All other request will be dropped in the FORWARD chain.<br />
Note:-<br />
These rules are the basic backbone for setting up the routing and Natting in DMZone. All other rules should be defined according to our network need.</p>
</div>]]></content:encoded>
</item>
<item>
<title><![CDATA[Linux Securirty Notes 15: IPTables 7: NAT]]></title>
<link>http://kiranjith.wordpress.com/2009/11/03/linux-securirty-notes-15-iptables-7-nat/</link>
<pubDate>Tue, 03 Nov 2009 11:06:00 +0000</pubDate>
<dc:creator>kiranjith</dc:creator>
<guid>http://kiranjith.wordpress.com/2009/11/03/linux-securirty-notes-15-iptables-7-nat/</guid>
<description><![CDATA[IPTables NAT&nbsp;&nbsp;&nbsp; Network Address Translation is the feature that makes Linux based fir]]></description>
<content:encoded><![CDATA[<div class='snap_preview'><p><!--.command {    padding: 1em;    border: 1px dashed #2f6fab;    color: black;    background-color: #f9f9f9;    line-height: 1.1em;        font-family: Courier New, Courier, mono;        font-size: 12px;        font-style: italic;}.system {    color: black;        font-family: Courier New, Courier, mono;        font-size: 12px;        font-style: italic;}.highlight {    color: #FF0000;                font-family: Georgia, "Times New Roman", Times, serif;                font-size: 12px;                text-decoration: underline;}--><br /><span style="font-size:large;"><b>IPTables NAT</b></span><br />&#160;&#160;&#160; Network Address Translation is the feature that makes Linux based firewall mostly in use. NAT is commonly used to masquerade the IP address</p>
<p><b>NAT CHAINS</b><br />&#160;&#160;&#160; The NAT table contains 3 chains<br /><b>1. PREROUTING</b><br />&#160;&#160;&#160; The DNAT is defined in the PREROUTING chain. Using this we will make available of our internal service to external (Internet).i.e, from internet to lan (changes the packets before it routes to lan)<br /><b>2. POSTROUTING</b><br />&#160;&#160;&#160; This is responsible for MASQUERADE (dynamic SNAT) &#38; SNAT. When packet needs to leave from one subnet(internel) through the linux firewall to another it traverse through POSTROUTING chain. (Changes the packet after it leaves the route from lan). eg:- MASQUERADE option is used in certain cases like, if ISP provides the DHCP address and the internel LAN needs to brows, then we have to masquerade all the request from the lan to the DHCP address provided by isp<br /><b>3. OUTPUT</b><br />&#160;&#160;&#160; Locally sourced/generated packets are subjected to NAT. Eg:- If the firewall has more than one IP address using this chain we can re-write the packets going out from this linux machine to a single IP.</p>
<p><b><span style="font-size:large;">TYPEs in NAT</span></b><br />&#160;&#160;&#160; 3 types of NATing is used.
<ul>
<li>masquerade</li>
<li>snat</li>
<li>dnat</li>
</ul>
<p><b>1. MASQUERADE</b><br />&#160;&#160;&#160; &#160;&#160;&#160; This feature of NAT is used to dynamically masquerade all the internal address to the external IP</p>
<p>The following example will masquerade all the outgoing traffic to the externel bound IP of the firewall.
<p class="command"><b><i># iptables -t nat -A POSTROUTING -j MASQUERADE</i></b></p>
<p>Another example that masquerades all the traffic from network 10.0.0.0/8 
<p class="command"><i><b># iptables -t nat -A POSTROUTING -j MASQUERADE -s 10.0.0.0/8 </b></i></p>
<p>&#160;&#160;&#160; This will masquerade all the request from the 10.0.0.0/8 subnet to the external ip of the firewall.<br /><i>Test by enabling logging for nat and check the log file.</i></p>
<p><b>Masquerading Port:</b>
<p class="command"><i><b>#iptables -A POSTROUTING -t nat -p tcp -j MASQUERADE &#8211;to-ports 1024-10240</b></i></p>
<p>&#160;&#160;&#160; This will masquerade all the ports to the range from 1024 to 10240. So when a external client makes connection to the internal server (for eg:- # telnet  22) then the port allocated to the client will be in between 1024 to 10240. As a result the internal system will be only able to source the port in range of 1024 to 10240.<br /><b><br />2.SNAT &#160;&#160;&#160; </b><br />&#160;&#160;&#160; &#160;&#160;&#160; This feature of NAT is used to masquerade a particular internal ip adress to a given external address. Though SNAT and masquerading perform the same fundamental function, mapping one address space into another one, the details differ slightly. Most noticeably, masquerading chooses the source IP address for the outbound packet from the IP bound to the interface through which the packet will exit. i.e, SNAT permits 1-to-1 and/or 1-to-many mappings. It is used when we have a static public IP address.</p>
<p>This example will masquerade all the outgoing traffic from the subnet 10.0.0./8 to the ip 123.12.23.43.
<p class="command"><i><b># iptables -t nat -A POSTROUTING -s 10.0.0.0/8 -j SNAT &#8211;to-source 12.34.56.78<br /></b></i></p>
<p>or
<p class="command"><i><b><br /># iptables -t nat -A POSTROUTING -j SNAT -s 10.0.0.0/8 &#8211;to-source 11.22.33.44</b></i></p>
<p><b>SNAT using multiple address:</b>
<p class="command"><i><b># iptables -A POSTROUTING -p tcp -s 10.0.0.55&#160; -j SNAT &#8211;to-source 192.168.1.100<br /># iptables -A POSTROUTING -p tcp -s 10.0.0.0/8 -j SNAT &#8211;to-source 192.168.1.200</b></i></p>
<p>&#160;&#160;&#160; The first rule will nat all the traffic from source 10.0.0.55 to 192.168.1.100, and second rule states that all other traffic from the subnet 10.0.0.0/8 should be NATed to 192.168.1.200.<br /><i>Test the functionality by enabling the LOG and use # netstat -ant</i></p>
<p><b>3.DNAT&#160;&#160;&#160; </b><br />&#160;&#160;&#160; This feature of NAT is used to translate the packet coming to a perticular destination.Destination NAT with netfilter is commonly used to publish or make available of a internal network service to a publicly accessible IP. The connection tracking mechanism of netfilter will ensure that subsequent packets exchanged in either direction (which can be identified as part of the existing DNAT connection) are also transformed.</p>
<p>In this following example, all packets arriving on the router with a destination of 10.10.20.99 will depart from the router with a destination of 10.10.14.2
<p class="command"><i><b># iptables -t nat -A PREROUTING -d 10.10.20.99 -j DNAT &#8211;to-destination 10.10.14.2 </b></i></p>
<p>&#160;Make the internal mail server available for external access.
<p class="command"><i><b># iptables -A PREROUTING -t nat -d mail.domain.com -p tcp &#8211;dport 25 -j DNAT &#8211;to-destination 192.168.1.25<br /># iptables -A PREROUTING -t nat -d mail.domain.com -p tcp &#8211;dport 110 -j DNAT &#8211;to-destination 192.168.1.25</b></i></p>
<p>&#160;&#160;&#160; Here if any request comes to the ip of mail.domain.com with the destination port of 25 or 110, then IPTables will redirect (nat) to the internel address of 192.168.1.25.<br /><span style="font-size:large;"><b><br />Netmap TAGRGET in NAT:</b></span><br />&#160;&#160;&#160; It is implemented in NAT table PREROUTING Chain. This is used to translate the one to one address from one subnet to another subnet.<br />For Eg:-<br />Consider we have one subnet 10.0.0.0/24. and we need to translate all the ip in this subnet equalent to 192.168.1.0/24
<p class="command"><i><b># iptables -A PREROUTING -t nat -s 10.0.0.0/24 -j NETMAP &#8211;to 192.168.1.0/24</b></i></p>
<p>&#160;&#160;&#160; This will convert/rewrite all the packets coming from the subnet 10.0.0.0/24 to 192.168.1.0/24.<br />i.e, the request from the ip 10.0.0.1 will be masked as 192.168.1.1. </p>
</div>]]></content:encoded>
</item>
<item>
<title><![CDATA[To allow forwarding of a port in the server]]></title>
<link>http://2paisasbyviggy.wordpress.com/2009/11/03/to-allow-forwarding-of-a-port-in-the-server/</link>
<pubDate>Tue, 03 Nov 2009 05:14:18 +0000</pubDate>
<dc:creator>viggyprabhu</dc:creator>
<guid>http://2paisasbyviggy.wordpress.com/2009/11/03/to-allow-forwarding-of-a-port-in-the-server/</guid>
<description><![CDATA[Well I needed to forward port 587 in my server so that Thunderbird installed in my local desktop cou]]></description>
<content:encoded><![CDATA[<div class='snap_preview'><p>Well I needed to forward port 587 in my server so that Thunderbird installed in my local desktop could send mails through gmail account.<br />
Here is how I did it.</p>
<p>iptables -I FORWARD -p tcp &#8211;dport 587 -j ACCEPT</p>
<p>What the above command does exactly is writes a (-I) inserts a new rule in the FORWARD chain which (-j) ACCEPTs all packets following (-p) tcp protocol and (&#8211;dport) destination port 587</p>
</div>]]></content:encoded>
</item>
<item>
<title><![CDATA[Linux Securirty Notes 15: IPTables 6: Routing - Forward Chain]]></title>
<link>http://kiranjith.wordpress.com/2009/11/02/linux-securirty-notes-15-iptables-6-routing-forward-chain/</link>
<pubDate>Mon, 02 Nov 2009 09:32:00 +0000</pubDate>
<dc:creator>kiranjith</dc:creator>
<guid>http://kiranjith.wordpress.com/2009/11/02/linux-securirty-notes-15-iptables-6-routing-forward-chain/</guid>
<description><![CDATA[IPTables Routing (Forward Chain)&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; The For]]></description>
<content:encoded><![CDATA[<div class='snap_preview'><p><!--.command {    padding: 1em;    border: 1px dashed #2f6fab;    color: black;    background-color: #f9f9f9;    line-height: 1.1em;        font-family: Courier New, Courier, mono;        font-size: 12px;        font-style: italic;}.system {    color: black;        font-family: Courier New, Courier, mono;        font-size: 12px;        font-style: italic;}.highlight {    color: #FF0000;                font-family: Georgia, "Times New Roman", Times, serif;                font-size: 12px;                text-decoration: underline;}--><br /><b><span style="font-size:large;">IPTables Routing (Forward Chain)</span></b><br />&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; The Forward chain holds the rules that take care of routing<br /><b>Enabling the Routing.</b>
<div class="command"><i> <b>#sysctl</b></i></div>
<p>This is the key utilities which shows the running kernel parameters.
<div class="command">
<div style="color:blue;"><i><b>#syscltl net.ipv4.ip_forward</b></i></div>
</div>
<p>This will show the status of the IPV4 routing in our local system.
<div class="command">
<div style="color:blue;"><i><b># echo 1 &#62; /proc/sys/net/ipv4/ip_forward</b></i></div>
</div>
<p>This will turn on the routing in kernel.
<div class="command">
<div style="color:blue;"><i><b># vim /etcv/sysctl.conf</b></i></div>
<div style="color:purple;"><i><b>net.ipv4.ip_forward = 1</b></i></div>
</div>
<p>This will make the routing permanent.
<div class="command">
<div style="color:blue;"><i><b># route add -net  10.0.0.0 netmask 255.0.0.0 gw 192.168.1.10</b></i></div>
</div>
<p>This will make the net routing in Linux host.</p>
<p><span style="font-size:large;">Forward Chain to Manage the Routing.</span><br />&#160;&#160;&#160;&#160; All the packets that is subjected to route will traverse through Forward Chain in a Linux router.</p>
<p><b>Defining the Forward chain policy</b><br />1. Initially make the default policy to Drop all the routing traffic in firewall
<div class="command">
<div style="color:blue;"><i><b># iptables -P FORWARD DROP</b></i></div>
</div>
<p>This will make all the routing traffic to be dropped as a default policy.<br />2. Specify only certain source network to be routed
<div class="command">
<div style="color:blue;"><i><b># iptables -A FORWARD -s 192.168.1.0/24 -d 10.0.0.0/8 -j ACCEPT</b></i></div>
</div>
<p>This will allow the traffic from 192.168.1.0 network to 10.0.0.0. But the traffic from 10.0.0.0/8 network if comes back will not be accepted until &#38; unless we define a state rule or a rule that allows the traffic from the given source.<br />or
<div class="command">
<div style="color:blue;"><i><b># iptables -A FORWARD -m state &#8211;state NEW,ESTABLISHED -s 192.168.1.0/24 -j ACCPET</b></i></div>
</div>
<p>This will allow and route all the new and established connection from the network 192.168.1.0 to any destination<br />3. Accept the return traffic
<div class="command">
<div style="color:blue;"><i><b># iptables -A FORWARD -m state &#8211;state ESTABLISHED -j ACCEPT</b></i></div>
</div>
<p>This will allow/accept all the established connection in the forward chain. This will allow the return traffic.<br />or define a rule that allows the return traffic from the network 10.0.0.0/8. Here usage of the &#8220;state&#8221; rule makes the definition of the firewall rule more easier and secure.</p>
<p><span style="font-size:large;">Logging the routing traffic in FORWARD Chain:</span>
<div class="command">
<div style="color:blue;"><i><b># iptables -N ROUTELOG</b></i></div>
<div style="color:blue;"><i><b># iptables -A FORWARD -j ROUTELOG</b></i></div>
<div style="color:blue;"><i><b># IPTABLES -I ROUTELOG -j LOG</b></i></div>
</div>
<p>This will create a new chain and starts logging all the routing activities.</p>
<p>Allowing a subnet to access outer world web
<div class="command">
<div style="color:blue;"><i><b># iptables -A FORWARD -s 10.0.0.0/24 -p tcp &#8211;dport 80 -j ACCEPT</b></i></div>
</div>
<p>Allow the UDP(DNS) queries to outside
<div class="command">
<div style="color:blue;"><i><b># iptables -A FORWARD -s 10.0.0.0/24 -p udp &#8211;dport 53 -j ACCEPT</b></i></div>
</div>
</div>]]></content:encoded>
</item>
<item>
<title><![CDATA[Aumentando a segurança para autenticação ssh em sistemas GNU/Linux]]></title>
<link>http://lucianoborguetti.wordpress.com/2009/11/01/aumentando-a-seguranca-para-autenticacao-ssh-em-sistemas-gnulinux/</link>
<pubDate>Mon, 02 Nov 2009 02:06:25 +0000</pubDate>
<dc:creator>lucianoborguetti</dc:creator>
<guid>http://lucianoborguetti.wordpress.com/2009/11/01/aumentando-a-seguranca-para-autenticacao-ssh-em-sistemas-gnulinux/</guid>
<description><![CDATA[Bom aqui vai uma dica para aumentar a segurança para autenticação ssh no seu sistema GNU/Linux usand]]></description>
<content:encoded><![CDATA[Bom aqui vai uma dica para aumentar a segurança para autenticação ssh no seu sistema GNU/Linux usand]]></content:encoded>
</item>
<item>
<title><![CDATA[IPTables]]></title>
<link>http://gurjotsingh52.wordpress.com/2009/11/01/iptables/</link>
<pubDate>Sun, 01 Nov 2009 17:44:04 +0000</pubDate>
<dc:creator>gurjotsingh52</dc:creator>
<guid>http://gurjotsingh52.wordpress.com/2009/11/01/iptables/</guid>
<description><![CDATA[IPTables Included with Red Hat Enterprise Linux are advanced tools for network packet filtering — th]]></description>
<content:encoded><![CDATA[<div class='snap_preview'><p><strong>IPTables</strong></p>
<p>Included with Red Hat Enterprise Linux are advanced tools for network packet filtering — the process of controlling network packets as they enter, move through, and exit the network stack within the kernel. Kernel versions prior to 2.4 relied on ipchains for packet filtering and used lists of rules applied to packets at each step of the filtering process. The 2.4 kernel introduced iptables (also called netfilter), which is similar to ipchains but greatly expands the scope and control available for filtering network packets.</p>
<p>This chapter focuses on packet filtering basics, defines the differences between ipchains and iptables, explains various options available with iptables commands, and explains how filtering rules can be preserved between system reboots.</p>
<p><strong> Packet Filtering</strong></p>
<p>The Linux kernel uses the <strong>Netfilter</strong> facility to filter packets, allowing some of them to be received by or pass through the system while stopping others. This facility is built in to the Linux kernel, and has three built-in tables or rules lists, as follows:</p>
<ul>
<li>filter — The default table for handling network packets.</li>
<li>nat — Used to alter packets that create a new connection and used for Network Address Translation (NAT).</li>
<li>mangle — Used for specific types of packet alteration.</li>
</ul>
<p>Each table has a group of built-in chains, which correspond to the actions performed on the packet by netfilter.</p>
<p>The built-in chains for the filter table are as follows:</p>
<ul>
<li>INPUT — Applies to network packets that are targeted for the host.</li>
</ul>
<p>· OUTPUT — Applies to locally-generated network packets.</p>
<p>· FORWARD — Applies to network packets routed through the host.</p>
<p>The built-in chains for the mangle table are as follows:</p>
<p>·   INPUT — Alters network packets targeted for the host.</p>
<p>· OUTPUT — Alters locally-generated network packets before they are sent out.</p>
<p>· FORWARD — Alters network packets routed through the host.</p>
<p>· PREROUTING — Alters incoming network packets before they are routed.</p>
<p>· POSTROUTING — Alters network packets before they are sent out.</p>
<p>Every network packet received by or sent from a Linux system is subject to at least one table. However, a packet may be subjected to multiple rules within each table before emerging at the end of the chain. The structure and purpose of these rules may vary, but they usually seek to identify a packet coming from or going to a particular IP address, or set of addresses, when using a particular protocol and network service.</p>
<p><strong> </strong><strong>Differences Between IPTables and IPChains</strong><strong></strong></p>
<p>Both ipchains and iptables use chains of rules that operate within the Linux kernel to filter packets based on matches with specified rules or rule sets. However, iptables offers a more extensible way of filtering packets, giving the administrator greater control without building undue complexity into the system.</p>
<p>You should be aware of the following significant differences between ipchains and iptables:</p>
<p><em>Using </em>iptables<em>, each filtered packet is processed using rules from only one chain rather than multiple chains.</em></p>
<p>For example, a FORWARD packet coming into a system using ipchains would have to go through the INPUT, FORWARD, and OUTPUT chains to continue to its destination. However, iptables only sends packets to the INPUT chain if they are destined for the local system, and only sends them to the OUTPUT chain if the local system generated the packets. It is therefore important to place the rule designed to catch a particular packet within the chain that actually handles the packet.</p>
</div>]]></content:encoded>
</item>
<item>
<title><![CDATA[W skrócie.]]></title>
<link>http://xeen.wordpress.com/2009/11/01/w-skrocie/</link>
<pubDate>Sat, 31 Oct 2009 23:08:09 +0000</pubDate>
<dc:creator>nox5</dc:creator>
<guid>http://xeen.wordpress.com/2009/11/01/w-skrocie/</guid>
<description><![CDATA[Minęło trochę czasu bez wpisów. Ale niestety praca zawodowa i studia tego nie ułatwiają. Teraz też l]]></description>
<content:encoded><![CDATA[Minęło trochę czasu bez wpisów. Ale niestety praca zawodowa i studia tego nie ułatwiają. Teraz też l]]></content:encoded>
</item>
<item>
<title><![CDATA[Linux Securirty Notes 15: IPTables 5 :IPTables Targets (-j)]]></title>
<link>http://kiranjith.wordpress.com/2009/10/30/linux-securirty-notes-15-iptables-5-iptables-targets-j/</link>
<pubDate>Fri, 30 Oct 2009 10:12:00 +0000</pubDate>
<dc:creator>kiranjith</dc:creator>
<guid>http://kiranjith.wordpress.com/2009/10/30/linux-securirty-notes-15-iptables-5-iptables-targets-j/</guid>
<description><![CDATA[IPTables Targets(-j)Commonly used targets are 1. ACCEPT &nbsp;&nbsp;&nbsp;&nbsp; Sends packtes to ot]]></description>
<content:encoded><![CDATA[<div class='snap_preview'><p><!--.command {    padding: 1em;    border: 1px dashed #2f6fab;    color: black;    background-color: #f9f9f9;    line-height: 1.1em;        font-family: Courier New, Courier, mono;        font-size: 12px;        font-style: italic;}.system {    color: black;        font-family: Courier New, Courier, mono;        font-size: 12px;        font-style: italic;}.highlight {    color: #FF0000; font-family: Georgia, "Times New Roman", Times, serif; font-size: 12px; text-decoration: underline;}--><b><span style="font-size:large;">IPTables Targets(-j)</span></b><br />Commonly used targets are <br /><b>1. ACCEPT </b><br />&#160;&#160;&#160;&#160; Sends packtes to other rule or process</p>
<p><b>2. DROP</b><br />&#160;&#160;&#160;&#160; Drops the packet silently. Remote machine will not be aware about what happend to the packet.</p>
<p><b>3. REJECT</b><br />&#160;&#160;&#160;&#160; When the rule met an error msg is send to client.<br />Eg of Reject:-
<p class="command"><i><br /><b># iptables -A INPUT -p icmp &#8211;icmp-type echo-request -j REJECT</b></i></p>
<p>This will reject all the echo request part with a msg icmp-port-unreachable. If we ping to the host we will get a destination host unreachable.</p>
<p><b>4. REDIRECT</b><br />&#160;&#160;&#160;&#160; This is used to redirect a current traffic to a desired target. It is applied to PREROUTING chain of NAT table.<br />Eg:- 
<p class="command"><i><b># iptables -t nat -A PREROUTING -p tcp &#8211;dport 3128 -j REDIRECT &#8211;to-port 80</b></i></p>
<p>&#160;&#160;&#160;&#160; This will redirect all the trafic coming to the destination port 3128 to 80.
<p class="command"><i><b># iptables -L -n -t nat -v</b></i></p>
<p>&#160;&#160;&#160;&#160; Test with the verbose mode to get the packet count which hits the rule.</p>
<p><b>5. LOG</b><br />&#160;&#160;&#160;&#160; This allow us to log the traffic which meets the rules from the level of debug to emergency using syslog.</p>
<p><span style="font-size:large;"><b>IPTable Logs:</b></span><br />&#160;&#160;&#160;&#160; It relies upon the kernel(kern) facility in syslog. So have to setup the syslog for logging the iptables activities.</p>
<p><b>Setup Logging</b><br />&#160;&#160;&#160;&#160; Primarily we enable the logging in IPTables<br /><b>Enabling the Log for a chain</b>
<p class="command"><i><b># iptables -I INPUT 1 -p tcp &#8211;dport 22 -j LOG</b></i></p>
<p>This will start logging for the traffic which meets the above rule.(Logs all the incoming ssh request.) The default level of logging is warning. The Log level corresponds to the syslog. 
<p class="command"><i><b># iptables -L -n -v</b></i></p>
<p>Check any packets hits the log
<p class="command"><i><b># tail -f /var/log/messages</b></i></p>
<p>This is the default place where undefined facilities logs to.So we the kern facility has been logging to /var/log/messages.<br /><b>Configure syslog to log iptables activity separately:</b><br />We will change the facility to log to a seperate file  
<p class="command"><i><b># vi /etc/syslog.conf</b></i><br /><i>kern.none /var/log/messeges</i><br /><i>kern.* /var/log/firewall.log</i></p>
<p>This will stop the kern facility to log to /var/log/messeges and redirects all levels of logs to /var/log/firewall.log
<p class="command"><i><b># service syslog reload</b></i></p>
<p>This will restart the syslog daemon and creates the file /var/log/firewall.log.<br />Test the Logging information by creating the traffic to port 22 on host.
<p class="command"><i><b># tail -f /var/log/firewall.log</b></i></p>
<p><b> </b><br />brief about the log format:- <br />time- syslog facility &#8211; interface that revived the tracfic- MAC address of the remote system- MAC address of the local system &#8211; SRC IP- DSTIP &#8211; ID=packet sequence number &#8211; SPT=source port &#8211; DPT=destination port etc</p>
<p>Note:-<br />Generally logging should be enabled for separate chains &#38; a specific rule. A catch all log for all the traffic will grow the log file numerously.</p>
<p><b>Loging All trafic</b>
<p class="command"><i><b># iptables -A INPUT -j LOG</b></i><br /><i><b># tail -f /var/log/firewall.log</b></i></p>
<p>This will Log all traffic destined to the local server(INPUT). This will log all the protocols</p>
<p><b>Log All except a perticular protocol from host 192.168.1.53 </b>
<p class="command"><i><b># iptables -I INPUT 1 -p tcp ! &#8211;dport 22 -src 192.168.1.53 -j LOG</b></i><br /><i><b># tail -f /var/log/firewall.log</b></i></p>
<p>This will log everything except traffic to destination port 22</p>
<p><b>Log Excluding Multiple port in single rule</b>
<p class="command"><i><b># iptables -I INPUT 1 -m multiport -p tcp &#8211;dport !80,8080 -j LOG</b></i><br /><i><b># tail -f /var/log/firewall.log</b></i></p>
<p>This will log all traffic except packet destined to port 80 and 8080.</p>
<p><b><span style="font-size:small;">Log using separate chains</span></b><br />Now we will check how to create a separate chain in IPTables for logging activities.<br />Create a New chain
<p class="command"><i><b># iptables -N LOGGER</b></i></p>
<p>Create a reference in INPUT chain to new chain LOG
<p class="command"><i><b># iptables -I INPUT 1 -j LOGGER</b></i></p>
<p>Create the logging rule in chain LOG
<p class="command"><i><b># iptables -A LOGGER -m multiport -p tcp &#8211;dport 21,22,80,143,8080 -j LOG</b></i><br /><i><b># tail -f /var/log/firewall.log</b></i></p>
<p>This will start logging ports 21,22,80,143 &#38; 8080. </p>
<p><b>Loging the ssh access to the console.</b><br />In iptables:<br />Create a New CHAIN
<p class="command"><i><b># iptables -N SSHLOG</b></i></p>
<p>Create a reference in INPUT chain to new chain SSHLOG
<p class="command"><i><b># iptables -I INPUT 1 -j SSHLOG</b></i></p>
<p>Create the loging rule in chain LOG
<p class="command"><i><b># iptables -A LOGGER -p tcp &#8211;dport 22 -j LOG</b></i></p>
<p>In syslog:
<p class="command"><i><b># vim /etc/syslog.conf</b></i><br /><i>kern.* /dev/console</i><br /><i><b># service syslogd restart</b></i></p>
<p>This will start logging any ssh access to the console.</p>
<p><b>Prefixing Interesting Traffic with a Log Prefix(&#8211;log-prefix &#8220;log prefix&#8221;)</b>
<p class="command"><i><b># iptables -A LOGGER -p tcp &#8211;dport 22 -j LOG &#8211;log-prefix &#8220;SSH Access Logs&#8221;</b></i></p>
<p>This will prefix the given string to the log. So it is easy to grep/awk the content from the log file.<br />Note:-<br />The Maximum prefix length is 29 characters.</p>
<p>Note:-<br />&#8211;log-level (debug to emer)<br />This will decide the level of log from debug to emergency level.</p>
</div>]]></content:encoded>
</item>
<item>
<title><![CDATA[Linux Securirty Notes 15: IPTables 4 :IPTables Statefullness]]></title>
<link>http://kiranjith.wordpress.com/2009/10/30/linux-securirty-notes-15-iptables-4-iptables-statefullness/</link>
<pubDate>Fri, 30 Oct 2009 05:25:00 +0000</pubDate>
<dc:creator>kiranjith</dc:creator>
<guid>http://kiranjith.wordpress.com/2009/10/30/linux-securirty-notes-15-iptables-4-iptables-statefullness/</guid>
<description><![CDATA[IPTables Statefullness(-m state &#8211;state):&nbsp;&nbsp;&nbsp; IPTables provide state fullness. Th]]></description>
<content:encoded><![CDATA[<div class='snap_preview'><p><!--.command {    padding: 1em;    border: 1px dashed #2f6fab;    color: black;    background-color: #f9f9f9;    line-height: 1.1em;        font-family: Courier New, Courier, mono;        font-size: 12px;        font-style: italic;}.system {    color: black;        font-family: Courier New, Courier, mono;        font-size: 12px;        font-style: italic;}.highlight {    color: #FF0000; font-family: Georgia, "Times New Roman", Times, serif; font-size: 12px; text-decoration: underline;}--><br /><b><span style="font-size:large;">IPTables Statefullness(-m state &#8211;state):</span></b><br />&#160;&#160;&#160; IPTables provide state fullness. The state full firewall is considered more secure than stateless firewall because of their connection tracking capability and their ability to determine whether or not the session is new,related, invalid or established. Based on this criteria we can create more powerfull rules.<br /><b>State Module:</b>
<div class="command"><i><b># rpm -ql iptables &#124; grep -i conntrack</b></i><br /><i><br /></i><i>/lib/iptables/libipt_conntrack.so</i></p>
</div>
<div style="color:purple;"><i> </i></div>
<p><i></i><br />&#160;&#160;&#160; This is the module that makes IPTables to behave as statefull. It is applicable for all the protocols (TCP/UDP/ICMP)<br /><b>The states are:</b><br /><i>NEW (The First SYN traffic)<br />ESTABLISHED<br />RELATED(SESSION/STATE)<br />INVALID</i><br />&#160;&#160;&#160; When a user creates a TCP/UDP based session IPTables can follow the connection. Here IPTable will keep a track with SYN, ACK-SYN, ACK and labelled with NEW(for SYN), ESTABLISHED or RELATED (For all other subsequent connections).</p>
<p><b>Example:</b><br />Permit Host to Initialte the connection and deny other hosts from initiating traffic to our host.
<div class="command"># Default Policy to Drop All connection<br /><i><b># iptables -P INPUT DROP<br /># iptables -P OUTPUT DROP</b></i><br /># State Rule <br /><i><b># iptables -A OUTPUT -m state &#8211;state NEW,ESTABLISHED -j ACCEPT</b></i><br />&#160;&#160;&#160; This will allow creating a NEW session (SYN) with outside and continue the ESTABLISHED&#160; connections(regardless of protocol(UDP/TCP))<br /><i><b># iptables -A INPUT -m state &#8211;state ESTABLISHED -j ACCEPT</b></i><br />&#160;&#160;&#160; After initiating a traffic to any other machine, the traffic will be permitted when it comes back.(regardles of protocol(UDP/TCP))</div>
<p><b>End Result:</b><br />The host will be able to make all connections to out side(NEW &#38; ESTABLISHED is allowed in OUTPUT chain). <br />All new connection coming to our system will be dropped(No NEW is defined in INPUT chain only&#160; ESTABLISED as well the default rule of DROP) only allows the ESTABLISHED connections(Initiated by our host)</p>
<p><b>The details of the connection tracking will be stored in</b>
<div class="command"><i><b># cat /proc/net/ip_conntrack</b></i></p>
</div>
<p>&#160;&#160;&#160; This file contains the status of all the established connections in the system for all protocols. The number of packets that transmitted, The <br />source and destination address, source and destination port etc.</p>
</div>]]></content:encoded>
</item>
<item>
<title><![CDATA[Linux Securirty Notes 15: IPTables 3: Matching Traffic]]></title>
<link>http://kiranjith.wordpress.com/2009/10/29/linux-securirty-notes-15-iptables-3-matching-traffic/</link>
<pubDate>Thu, 29 Oct 2009 09:47:00 +0000</pubDate>
<dc:creator>kiranjith</dc:creator>
<guid>http://kiranjith.wordpress.com/2009/10/29/linux-securirty-notes-15-iptables-3-matching-traffic/</guid>
<description><![CDATA[IPTables Building Rules with Source, Destination of IP, MAC, Protocols &amp; Port&nbsp;&nbsp;&nbsp; ]]></description>
<content:encoded><![CDATA[<div class='snap_preview'><p><!--.command {    padding: 1em;    border: 1px dashed #2f6fab;    color: black;    background-color: #f9f9f9;    line-height: 1.1em;        font-family: Courier New, Courier, mono;        font-size: 12px;        font-style: italic;}.system {    color: black;        font-family: Courier New, Courier, mono;        font-size: 12px;        font-style: italic;}.highlight {    color: #FF0000; font-family: Georgia, "Times New Roman", Times, serif; font-size: 12px; text-decoration: underline;}--><br /><b><span style="font-size:large;">IPTables Building Rules with Source, Destination of IP, MAC, Protocols &#38; Port</span></b><br />&#160;&#160;&#160; <br />&#160;&#160;&#160; Here we will deal with the possibilities to match the traffic to define the rule, i.e, matching destination &#38; source IP/MAC/PORT/PROTOCOL, Interfaces,Usage of Wildcards etc.</p>
<p><span style="font-size:large;">Matching the traffic based on Source and destination:</span><br /><i>&#8211;src/-s/&#8211;source<br />&#8211;dst/-d/&#8211;destination</i><br />&#160;&#160;&#160; These are the switches used to match the source and destination of the traffic. Widely used while rules created based on source and destination address<br />Eg:-<br /><i></i><b>Blocking all the traffic from a source (192.168.1.200) (&#8211;src)</b>
<p class="command"><i><b># iptables -A INPUT &#8211;src 192.168.1.200 -j DROP</b></i></p>
<p>&#160;&#160;&#160; This Drops all the incoming traffic to out server from the Source 192.168.1.200. Here the match of source is used by &#8220;&#8211;src&#8221;.<br /><b>Blocking all the traffic To a destination from our server (&#8211;dst)</b>
<p class="command"><i><b># iptables -A OUTPUT &#8211;dst 192.168.1.200 -j DROP</b></i></p>
<p>&#160;&#160;&#160; This Drops all the outgoing traffic in our server to 192.168.1.200. Here the match of destination is used by &#8220;&#8211;dst&#8221;.</p>
<p><span style="font-size:large;">Matching Based on Interface:</span><br />&#160;&#160;&#160; It is useful while creating the rules based on a particular interface.<br /><i>(-i eth0/eth1.. etc)</i><br />&#160;&#160;&#160; switch &#8220;-i&#8221; is used to match the traffic with the interface to define the rule.<br />Eg:-<br />(-i eth1)
<p class="command"><i><b># iptables -A INPUT -i eth1 &#8211;src 192.168.1.200 -j DROP</b></i></p>
<p>&#160;&#160;&#160; Any incoming traffic from the ip address on the interface eth1 will be dropped.</p>
<p><span style="font-size:large;">Negation rule:</span>
<p class="command"><i><b># iptables -A INPUT -i eth1 &#8211;src !192.168.1.200 -j DROP</b></i></p>
<p>&#160;&#160;&#160; This will Drop all the incoming traffic to the interface eth1 other than the IP 192.168.1.200. Only the incoming traffic from ip 192.168.1.200 will be accepted.
<p class="command"><i><b># iptables -A INPUT -i eth1 -j DROP</b></i></p>
<p>&#160;&#160;&#160; This Drops all the incoming traffic on the interface eth1.</p>
<p><span style="font-size:large;">Wildcard for Matching all interfaces(eth+):</span><br />For eg:- <br />&#160;&#160;&#160; IF we have more interfaces like eth0, eth1, eth2, eth3, eth4 etc and need to define a rule that matched all the interface, we can use the wild-card eth+ . eth+ will match all the interfaces starting with &#8220;eth&#8221;.<br />For Eg:-
<p class="command"><i><b># iptables -A INPUT -i eth+ -p tcp &#8211;dport 23 -j DROP</b></i></p>
<p>&#160;&#160;&#160; This will drop all the incoming telnet traffic to all interfaces, which starts with eth.</p>
<p><span style="font-size:large;">TCP Based Matching (&#8211;protocol/-p): (Connection Oriented)</span><br />&#160;&#160;&#160;&#160; Majority of the rules are based on TCP . TCP is on Transport Layer (layer 4).<br /><i><b>-p tcp/ &#8211;protocol tcp</b></i><br />&#160;&#160;&#160; This switch will make IPTables to initiate the tcp modules and allow/deny the tcp based traffic. This switch makes sense to IPTables about the three way handshake of TCP. The protocol type (tcp/udp) has to be specified while using the &#8220;-p&#8221; match.<br /><i><b>&#8211;sport/&#8211;source-port</b></i><br />&#160;&#160;&#160; Generally the &#8211;sport of TCP client will be greater than 1024, and it is generaly picked arbitrarily from greater than 1024. So usally we wont filter based on the source port for TCP based traffic until and unless we know exactly how a application behaves.<br /><i><b>&#8211;dport/&#8211;destination-port</b></i><br />&#160;&#160;&#160; This is the common match that used along with the &#8220;-p&#8221; switch. Each and every TCP connection will have a well defined destination port. so based on this destination port we created/matched the rule.<br /><i><b>&#8211;tcp-flags SYN, ACK SYN, ACK, FIN</b></i><br />&#160;&#160;&#160; This is used to match the three way handshake of the tcp protocols.<br />&#160;&#160;&#160; SYN &#8211; Step 1 of Three way Handshake (Initial synchronization) (From Server)<br />&#160;&#160;&#160; ACK SYN &#8211; Step 2 of three way Handshake (To Acknowledge that the SYN has recieved) (From Client)<br />&#160;&#160;&#160; ACK &#8211; Step 3 of Three way HandShake(From Server)<br />&#160;&#160;&#160; FIN (Finishing a TCP Session)<br />Eg:-
<p class="command"><i><b># iptables -A INPUT -p tcp &#8211;dport 23 -j DROP</b></i></p>
<p>&#160;&#160;&#160; Here Match is made with the protocol TCP having the destination port of 23. So all the incoming traffic to telnet will be dropped.
<p class="command"><i><b># iptables -A OUTPUT -p tcp &#8211;dport 21 -j DROP</b></i></p>
<p>&#160;&#160;&#160; This will Drop all the FTP outbound traffic(all request to ftp access from our server)</p>
<p><span style="font-size:large;">UDP Based Match: (Connection Less)</span><br />&#160;&#160;&#160; Some of the UDP based applications are TFTP:69, Syslog:514, NTP:123, DHCP:67/68, DNS:53<br /><i><b>-p udp/&#8211;protocol udp<br />&#8211;dport/&#8211;destination-port<br />&#8211;sport/&#8211;source-port</b></i><br />&#160;&#160;&#160; In majority of the cases, the UDP based traffic having same source port as the destination port.Eg:- The NTP client packets has same destination-port and source-port as 123 in header.<br />Eg:-<br />If we are running the syslogd daemon we have to block all other traffic to the service other than the syslog server.
<p class="command"><i><b># iptables -A INPUT -p udp &#8211;dport 514 -s !192.168.1.3 -j DROP</b></i></p>
<p>&#160;&#160;&#160; So here only the traffic from the host 192.168.1.3 with UDP:514 will be accepted and all other source will be denied. Here the match is made with the protocol UDP and &#8211;dport 514 along with the Source(-s) using Negation(!).</p>
<p><span style="font-size:large;">ICMP based traffic Match.</span><br />&#160;&#160;&#160; This is designed to communicate the status information.<br /><b>various types of ICMP:</b><br />&#160;&#160;&#160; echo-request &#8211; PING (sends the request via output chains using echo-request to destination)<br />&#160;&#160;&#160; echo-reply -&#160;&#160; PONG (Remote system Recieves the echo-request and responds with an echo-reply (PONG))<br /><i><b>-p icmp/&#8211;protocol icmp</b></i><br />&#160;&#160;&#160; Here defines the protocol type<br /><i><b>&#8211;icmp-type name/number of icmp type</b></i><br />&#160;&#160;&#160; Here we specifies the ICMP-Types. It can be name or number.eg:- echo-reply, icmp-request etc.<br />To get the list of icmp types that supported by the IPTables
<p class="command"><i><b># iptables -p icmp &#8211;help</b></i></p>
<p>&#160;&#160;&#160; &#160;&#160;&#160; Using this we can build the rules. The above command can be used for both the tcp and udp protocols
<p class="command"><i><b>&#160;&#160;&#160; # iptables -p tcp &#8211;help<br />&#160;&#160;&#160; # iptables -p udp &#8211;help</b></i></p>
<p>Eg:-
<p class="command"><i><b># iptables -A INPUT -p icmp &#8211;icmp-type echo-reply -j DROP</b></i></p>
<p>&#160;&#160;&#160; All the echo-reply from outside will be droped.<br /><b>Rule to drop all the echo-request to our filrewall from all outbound destination.</b>
<p class="command"><i><b># iptables -A INPUT -i eth1 -p icmp &#8211;icmp-type echo-request -j DROP</b></i></p>
<p>&#160;&#160;&#160; This will disable all the echo-request from the outside interface. But from this server we will be able to ping to any other system because we have not doped any incoming echo-reply.</p>
<p><span style="font-size:large;">Multiport Matching in single rule (-m):</span><br />&#160;&#160;&#160; This feature uses to match multiple ports in a single rule.<br /><i><b>-m multiport</b></i><br /><b>&#160;Checking the Multiport module installation</b>
<p class="command"><i><b># rpm -ql iptables &#124;grep multiport</b></i><br /><i>/lib/iptables/libipt_multiport.so</i></p>
<p>&#160;&#160;&#160; This is the modlue responsible for multiport<br />Eg:-
<p class="command"><i><b><br /># iptables -A INPUT -p tcp -m multiport &#8211;dport 21,23 -j DROP</b></i></p>
<p>&#160;&#160;&#160; Here we defined the multiple ports in single rule.</p>
<p><span style="font-size:large;">Matching Layer 2 Traffic (MAC-address):</span><br />&#160;&#160;&#160; The MAC address is least changable.<br /><b>Checking the capability of iptables to match the Layer 2 traffic</b>
<p class="command"><i><b># rpm -ql iptables &#124;grep mac</b></i><br /><i>/lib/iptables/libipt_mac.so</i></p>
<p>&#160;&#160;&#160; This is the modlue responsible for mac address based rule.<br /><b><i>-m mac</i></b><br />&#160;&#160;&#160; This will tell iptables to consult the libipt_mac.so module for processing the rule<br /><i><b>&#8211;mac-source </b></i><br />&#160;&#160;&#160; Source MAC address. Same as the &#8211;src option in Layer 3 (IP Adress)<br /><i><b>&#8211;mac-destination</b></i><br />&#160;&#160;&#160; Destination MAC address. Same as the &#8211;dst option in Layer 3 (IP Address)<br />Eg:-
<p class="command"><i><b># iptables -A INPUT -p tcp -m mac &#8211;mac-source 00:09:8F:3E:10:3A -j DROP</b></i></p>
<p>&#160;&#160;&#160; IF the source mac address is matched then the traffic will be DROPed.<br />Filtering based on Layer 2 (MAC Address) is more secure because the IP Address can easily be changed.</p>
</div>]]></content:encoded>
</item>
<item>
<title><![CDATA[Linux Securirty Notes 15: IPTables 2: Chain Management]]></title>
<link>http://kiranjith.wordpress.com/2009/10/28/linux-securirty-notes-15-iptables-2-chain-management/</link>
<pubDate>Wed, 28 Oct 2009 09:16:00 +0000</pubDate>
<dc:creator>kiranjith</dc:creator>
<guid>http://kiranjith.wordpress.com/2009/10/28/linux-securirty-notes-15-iptables-2-chain-management/</guid>
<description><![CDATA[IPTables Chain ManagementListing all the chains in Table Filter # iptables -L -n &nbsp;&nbsp;&nbsp; ]]></description>
<content:encoded><![CDATA[<div class='snap_preview'><p><!--.command {    padding: 1em;    border: 1px dashed #2f6fab;    color: black;    background-color: #f9f9f9;    line-height: 1.1em;        font-family: Courier New, Courier, mono;        font-size: 12px;        font-style: italic;}.system {    color: black;        font-family: Courier New, Courier, mono;        font-size: 12px;        font-style: italic;}.highlight {    color: #FF0000; font-family: Georgia, "Times New Roman", Times, serif; font-size: 12px; text-decoration: underline;}--><br /><b><span style="font-size:large;">IPTables Chain Management<br /></span></b><br /><b>Listing all the chains in Table Filter</b>
<div class="command"><i><b># iptables -L -n</b></i></p>
</div>
<p>&#160;&#160;&#160; It lists INPUT, FORWARD and OUTPUT chains and rules associated with. Each of the chains will have a default policy. i.e the default policy is accept the traffic in IPTables.
<div class="command"><i><b># iptables -L OUTPUT</b></i></p>
</div>
<p>&#160;&#160;&#160; It will list all the rules in the chain OUTPUT for the default table.</p>
<p><b>Listing all the chains in Table NAT. </b>
<div class="command"><i><b># iptables -L -n -t nat</b></i> </p>
</div>
<p>&#160;&#160;&#160;&#160; It contains the chains PREROUTING(will use NAT before routing occurred -destination nat-),&#160; POSTROUTING(uses NAT to after the packets get routed&#160; -source nat-) &#38; OUTPUT (Reserved for packets that sourced locally that need the NAT)</p>
<p><b>Listing all the chains in Table Mangle. </b>
<div class="command"><i><b># iptables -L -n -t mangle</b></i></p>
</div>
<p>&#160;&#160;&#160; It contains chains INPUT,OUTPUT,FORWARD, PREROUTE &#38; POSTROUTE. Mangle Table is the ANDing of Filter &#38; NAT table.</p>
<p><b>To List the amount of traffic that processed by the a chain</b>
<div class="command"><i><b># iptables -L -n -v -t filter</b></i></p>
</div>
<p>&#160;&#160;&#160; This will show the total amount of traffic in each chains. Even if there is no rule defined it shows the traffic in chains. This is because there is default rule of accept all in IPTables.</p>
<p><b>Determine the Line number of the rule in a chain</b>
<div class="command"><i><b># iptables -L -n -v &#8211;line-numbers<br /># iptables -L -n -v &#8211;line-numbers -t nat</b></i></p>
</div>
<p>&#160;&#160;&#160; This will show the line numbers column for all the chains.</p>
<p><b><span style="font-size:large;">Appending(-A) and Inserting(-I) rules to Chains</span></b></p>
<p>&#160;&#160;&#160; We will&#160; try to understand each chains with a real time scenario<br /><i>Source (192.168.1.1)pings to -&#62; destination (192.168.254)</i><br />&#160;&#160;&#160; In this case the source sends a ICMP (echo-request) packet to 192.168.254 which pass across the OUTPUT chain in filter table. Once the request reaches the destination it responds with a echo-reply to the source 192.168.1.1 which pass across the INPUT chain in filter table.</p>
<p>Now we will create rule in source all traffic for SSH will be permitted and Telnet traffic will be denied<br /><b>Appending a rule(-A):</b>
<div class="command"><i><b># iptables -A INPUT -p tcp &#8211;dport 22 -j ACCEPT<br /># iptables -A INPUT -p tcp &#8211;dport 23 -j DROP</b></i></p>
</div>
<p>&#160;&#160;&#160; This will make the server to accept only the ssh based connection and telnet sessions wll be droped. <br />The append (-A) will add the rule to the last rule in the chain(to the end of the rule list in chain).
<div class="command"><i><b># iptables -L -n -v &#8211;line-number</b></i></p>
</div>
<p>&#160;&#160;&#160; This will list the newly added rule</p>
<p><b>Inserting a rule (-I):</b><br />We can insert the rule into a particular line number using this option. (Keep in mind the iptable checks the rule from above to bottom and once it matches the criteria it executes the rule).(We can even insert a same rule to the chain, creating a duplicate rule. IPTables doesn&#8217;t have a feature to detect the duplicate rules that have appended or inserted.
<div class="command"><i><b># iptables -I INPUT 1 -p tcp &#8211;dport 23 -j DROP<br /># iptables -L -n -v &#8211;line-number</b></i></p>
</div>
<p>&#160;&#160;&#160; Here we can see that the rule for dropping the telnet session has been added to first line in the chain. So IPTables will process the rule number 1 before it hitting the rule number 2.<br />Other examples:
<div class="command"><i><b># iptables -I INPUT 2 -p tcp &#8211;dport 21 -j DROP</b></i></p>
</div>
<p>&#160;&#160;&#160; It inserts a rule to line number 2 in INPUT Chain for the table Filter,for Dropping all FTP traffic.</p>
<p><b><span style="font-size:large;">Deleting(-D) and Replacing(-R) Rules</span></b><br /><b>Deleting a Rule:</b><br />Syntax for deleting the rule from the chain:<br /><i><b># iptables -D  <br /># iptables -D </b></i><br /><b>Type 1</b>
<div class="command"><i><b># iptables -L -n -v &#8211;line-number<br /># iptables -D INPUT 2</b></i></p>
</div>
<p>&#160;&#160;&#160; This will delete the 2nd rule in the chain INPUT.<br /><b>Type 2</b>
<div class="command"><i><b># iptables -D INPUT -p tcp &#8211;dport 21 -j DROP</b></i></p>
</div>
<p>&#160;&#160;&#160; This will delete the rule as mentioned . This need the exact match and in case of any duplicate rules the first match will be deleted.</p>
<p><span style="font-size:large;"><b>Replacing Rules:</b></span><br />Syntax:<br /><i><b># iptables -R   <br /></b></i>
<div class="command"><i><b># iptables -L -n -v &#8211;line-number<br /># iptables -R INPUT 1 -p tcp &#8211;dport 23 -j ACCEPT</b></i></p>
</div>
<p>&#160;&#160;&#160; This will replace the existing rule from DROP to ACCEPT (we had previously denied the telnet access)</p>
<p><b><span style="font-size:large;">Flush(-F) rules and Zero counters (-Z)</span></b></p>
<p><b>Flush rules:</b><br />syntax:<br /><i><b># iptables -F <br /></b></i>
<div class="command"><i><b># iptables -F INPUT</b></i></p>
</div>
<p>&#160;&#160;&#160; This will flush all the rules in the chain INPUT.
<div class="command"><i><b># iptables -F</b></i></p>
</div>
<p>&#160;&#160;&#160; This will flush all the rules from all the chains in default Table. But the flusing will not zero the packet counters (iptables -L -v).</p>
<p><b><span style="font-size:large;">Zero Counters:</span></b><br />Syntax:<br /><i><b># iptables -Z <br /></b></i>
<div class="command"><i><b># iptables -Z INPUT<br /># iptables -L -n -v </b></i></p>
</div>
<p>&#160;&#160;&#160; This will reset the packet count for the chain INPUT
<div class="command"><i><b># iptables -Z</b></i></p>
</div>
<p>&#160;&#160;&#160; This will reset all the chain packet counts in default table.
<div class="command"><i><b># iptables -Z POSTROUTING -t nat</b></i></p>
</div>
<p>&#160;&#160;&#160; This will reset the packet counter for the chain POSTROUTING for table nat.</p>
<p><span style="font-size:large;"><span style="color:black;"><b>User Defined Tables/Chains (Creating (-N) and Renaming (-E old new)):</b></span></span><br />&#160;&#160;&#160; IPTables ships with 3 default tables which cannot be deleted.</p>
<p><b>Creating a New chain called INTRANET</b>
<div class="command"><i><b># iptables -N INTRANET<br /># iptables -L -n</b></i></p>
</div>
<p>&#160;&#160;&#160; This will create a new chain called INTRANET in the filter table. This will create a chain with the default refereces as &#8220;0&#8243;. reference is the link towards the default chains(INPUT, OUTPUT &#38; FORWARD).<br />Now we define the new chain INTRANET how to behave. i.e, which traffic should be this chain responsilbe for.
<div class="command"><i><b># iptables -R INPUT 1 -s 192.168.1.0/24 -j INTRANET</b></i></p>
</div>
<p>&#160;&#160;&#160; This will tell IPTables that &#8211; In rule number 1, any trafic having the source network ID 192.168.1.0 should be contacted the chain INTRANET
<div class="command"><i><b># iptables -L -n</b></i></p>
</div>
<p>&#160;&#160;&#160; Here we can see that a new entry for the Chain is added into the Line number 1 stating that for all the packages having source address in the network 192.168.1.0/24 should jump to target chain INTRANET.</p>
<p><b>Now create the rules </b>
<div class="command"><i><b># iptables -A INTRANET&#160;&#160;&#160; -p tcp &#8211;dport 23 -j DROP</b></i></p>
</div>
<p>&#160;&#160;&#160; So when a packet comes with a source address in 192.168.1.0/24 with the destination port 23. The iptables will refer from the INPUT chain to the INTRANET chain and Then IPTables will start matching the rule. If the packet has the destitantion port 23 then it will DROP.</p>
<p>Note:-<br />&#160;&#160;&#160;<i> User defined chains must have unique names. Because it function has the target (-j).</i></p>
<p><b><span style="font-size:large;">Rename a Chain(-E):</span></b><br />&#160;&#160;&#160; If we need to rename a user defined chain <br />Syntax:<br /><i><b># iptables -E  <br /></b></i>
<div class="command"><i><b># iptables -E INTRANET&#160;&#160;&#160; SUBINTRANET</b></i></div>
<p>&#160;&#160;&#160; This will rename the chain to SUBINTRANET. The iptables &#8220;will update the references as well&#8221;(The reference to the default chain).<br /><b><span style="font-size:large;">Chain Policy (-P):</span></b><br />&#160;&#160;&#160; It is usually &#8220;accept&#8221; in RedHat environment for all the chains in filter table. should be very careful while setting the chain default policy to DROP(Update the iptables to permit the appropriate access, else if we are using a remote session this may freez the access).<br />Syntax:<br /><i><b># iptables -P  <br /></b></i>
<div class="command"><i><b># iptables -P INPUT DROP</b></i><br />&#160;&#160;&#160; This will make the default policy of INPUT chain to DROP.<br /><b><i># iptables -L -n </i></b></div>
<p>&#160;&#160;&#160; Check the &#8220;chain INPUT (policy DROP)&#8221; to verify.<br />Note:-<br />&#160;&#160;&#160; Default DROP Policy may prevent typical TCP/UDP/ICMP communication.So a state matching rule should be added in case of such scenarios.</p>
</div>]]></content:encoded>
</item>
<item>
<title><![CDATA[Linux Securirty Notes 15: IPTables 1: Introduction]]></title>
<link>http://kiranjith.wordpress.com/2009/10/27/linux-securirty-notes-15-iptables-1-introduction/</link>
<pubDate>Tue, 27 Oct 2009 08:15:00 +0000</pubDate>
<dc:creator>kiranjith</dc:creator>
<guid>http://kiranjith.wordpress.com/2009/10/27/linux-securirty-notes-15-iptables-1-introduction/</guid>
<description><![CDATA[IPTABLES&nbsp;&nbsp;&nbsp; The integrated firewall feature in Linux Kernel is IPTables. Using IPTabl]]></description>
<content:encoded><![CDATA[<div class='snap_preview'><p><!--.command {    padding: 1em;    border: 1px dashed #2f6fab;    color: black;    background-color: #f9f9f9;    line-height: 1.1em;        font-family: Courier New, Courier, mono;        font-size: 12px;        font-style: italic;}.system {    color: black;        font-family: Courier New, Courier, mono;        font-size: 12px;        font-style: italic;}.highlight {    color: #FF0000; font-family: Georgia, "Times New Roman", Times, serif; font-size: 12px; text-decoration: underline;}--><br /><span style="font-size:large;"><b>IPTABLES</b></span><br />&#160;&#160;&#160; The integrated firewall feature in Linux Kernel is IPTables. Using IPTables can turn the Linux machine to a fully fledged firewall. Since the IPTable netfilter frame work is capacble to filter pretty much most of the level of OSI models &#38; with in all the various field in TCP, UDP and ICMP packets it has a significant value in corporate enviornment to build the security.</p>
<p><b><span style="font-size:large;">OSI Models</span></b><br />&#160;&#160;&#160; The Open System Interconnection Reference Model (OSI Reference Model or OSI Model) is an abstract description for layered communications and computer network protocol design. It was developed as part of the Open Systems Interconnection (OSI) initiative. In its most basic form, it divides network architecture into seven layers which, from top to bottom, are
<ul>
<li>&#160;&#160;&#160; Layer 1: Physical Layer</li>
<li>&#160;&#160;&#160; Layer 2: Data Link Layer</li>
<li>&#160;&#160;&#160; Layer 3: Network Layer</li>
<li>&#160;&#160;&#160; Layer 4: Transport Layer</li>
<li>&#160;&#160;&#160; Layer 5: Session Layer</li>
<li>&#160;&#160;&#160; Layer 6: Presentation Layer</li>
<li>&#160;&#160;&#160; Layer 7: Application Layer</li>
</ul>
<p><b>some of the Protocols in each Layer are given below.</b><br /><b>7. Application Layer</b><br /><i>NNTP&#160; · SIP&#160; · SSI&#160; · DNS&#160; · FTP&#160; · Gopher&#160; · HTTP&#160; · NFS&#160; · NTP&#160; · SMPP&#160; · SMTP&#160; · SNMP&#160; · Telnet (more)</i><br /><b>6. Presentation Layer</b><br /><i>MIME&#160; · XDR&#160; · SSL&#160; · TLS</i><br /><b>5. Session Layer</b><br /><i>Named Pipes&#160; · NetBIOS&#160; · SAP</i><br /><b>4. Transport Layer</b><br /><i>TCP&#160; · UDP&#160; · PPTP&#160; · L2TP&#160; · SCTP</i><br /><b>3. Network Layer</b><br /><i>IP&#160; · ICMP&#160; · IPsec&#160; · IGMP</i><br /><b>2. Data Link Layer</b><br /><i>ARP&#160; · CSLIP&#160; · SLIP&#160; · Frame relay&#160; · ITU-T G.hn DLL</i><br /><b>1. Physical Layer</b><br /><i>RS-232&#160; · V.35&#160; · V.34&#160; · I.430&#160; · I.431&#160; · T1&#160; · E1&#160; · Ethernet&#160; · POTS&#160; · SONET&#160; · DSL&#160; · 802.11a/b/g/n PHY&#160; · ITU-T G.hn PHY</i><br />&#160;&#160;&#160; <br />&#160;&#160;&#160; IPTables is a front end user space tool to manage Netfilter in Linux kernel. IPTables functions primarily in the Transport (Layer4) and Network (Layer 3), even it can work in the DataLink layer too. IPTables can manage the ICMP .</p>
<p><b>Layer 4 -Transport-</b> Focuses on Protocols &#38; Ports (TCP/UDP &#38; Ports(0-65535)). The ports are based on 16bit value<br /><b>Layer 3 -Network-</b> Focuses on Source &#38; Destination (IP Address). The IP address is based on 32 bit value</p>
<p><b><span style="font-size:large;">Installing IPTables</span></b><br />&#160; &#160; &#160; &#160;&#160; The package IPTables will be installed by default in most of the Linux distro.
<p class="command"><i><b># rpm -qa &#124;grep -i IPTables </b></i></p>
<p>&#160;&#160;&#160; Or download the Latest package of IPTables from <a href="http://www.netfiler.org/">http://www.netfiler.org</a>
<p class="command"><i><b># rpm -ql iptables </b></i><br />&#160;&#160;&#160; IPTables ships with many modules that provides the functionality of Masquerading, Rejecting, Mapping etc. The modules that installed can be found in /lib/iptables/*.so.</p>
<p><b><span style="font-size:large;">Checking the kernel for the support of the IPTables.</span></b></p>
<p>Find the area for &#8220;NETFILTER&#8221; in Kernel config file.
<p class="command"><i><b># uname -a</b></i><br /><i><span style="color:purple;"></span><b><br /># vim /boot/config-</b></i><br /><i><br />CONFIG_NETFILTER=y<br /></i></p>
<p>&#160;&#160;&#160; (y)This means the netfilter basic support has been integrated and compiled to the kernel.If (m) option is defined then this means the module can be loaded on the fly so here we need to check the iptables modules has been loaded by command &#8220;lsmod&#8221;.</p>
<p><b><span style="font-size:large;">Default Tables &#38; Chains in IPTables</span></b><br />&#160;&#160;&#160; There are 3 default tables which cannot be deleted. Each table contains chains and the rules are written to the chains<br /><b>1. Mangle</b><br />&#160;&#160;&#160; This allows to alter packets eg:- Type Of Service, Time To Live etc.<br /><b>2. NAT</b><br />&#160;&#160;&#160; Network Address Translation, This allows to change IP Address &#38; Ports. Eg:- Source NAT / DST NAT etc<br /><b>3. Filter</b><br />&#160;&#160;&#160; Here we perform the Filtering the traffic (INPUT, OUTPUT &#38; FORWARD). It works between Layer 3 &#38; Layer 4.</p>
<p><b><span style="font-size:large;">Rule Syntax IPTables.</span></b></p>
<p><i><b># /sbin/iptables&#160;&#160;&#160; </b></i><br />commands are used in the following syntax:<br /><i>&#160;&#160;&#160; name of chain &#8211; action done to chain (Append/Incert or Replace)<br />&#160;&#160;&#160; name of table &#8211; default it will append to filter table<br />&#160;&#160;&#160; Layer 3 object &#8211; src or dst of ip address<br />&#160;&#160;&#160; Layer 4 object &#8211; protocols &#38; ports <br />&#160;&#160;&#160; Jump/Target &#8211; if the above criteria meets the do this action</i><br /><b><br />Example of iptables</b><br />Drop All the packages from a Host
<p class="command"><i><b># iptables -A INPUT -t filter -s 192.168.1.233&#160;&#160;&#160; -j DROP</b></i></p>
<p>&#160;&#160;&#160; This will Drop all the packages coming from the source 192.168.1.233.<br />Now Test by pinging to the destination host 192.168.1.233<br />&#160;&#160;&#160; &#160;Here we have the OUTPUT chain opened and the rule is defined in INPUT chain. This means our system is able to send the packages to the destination and while the destination machines replies back we drop the packets.</p>
<p><b><span style="font-size:large;">Saving and Restoring the rules in IPTables</span></b>
<p class="command"><i><b># iptables-save</b></i></p>
<p>&#160;&#160;&#160; This will dump the rules to STDOUT(to the terminal). The output will be in the iptables default format.
<p class="command"><i><b># iptables-save &#62; firewall-rules</b></i></p>
<p>&#160;&#160;&#160; This will write the rule the file firewall-rules
<p class="command"><i><b># iptables-restore</b></i></p>
<p>&#160;&#160;&#160; Default reads the rule from STDIN and loads in to the kernel.
<p class="command"><i><b># iptables-restore &#60; firewall-rules</b></i></p>
<p>&#160;&#160;&#160; This will restore the rule that saved in the file firewall-rules.</p>
</div>]]></content:encoded>
</item>
<item>
<title><![CDATA[Simple Configuration of iptables on Debian]]></title>
<link>http://5e6n1.wordpress.com/2009/10/21/simple-configuration-of-iptables-on-debian/</link>
<pubDate>Wed, 21 Oct 2009 07:15:00 +0000</pubDate>
<dc:creator>seanl</dc:creator>
<guid>http://5e6n1.wordpress.com/2009/10/21/simple-configuration-of-iptables-on-debian/</guid>
<description><![CDATA[I do not use any GUI application to configure the network interfaces on my Linux machines. Instead, ]]></description>
<content:encoded><![CDATA[<div class='snap_preview'><p>I do not use any GUI application to configure the network interfaces on my Linux machines. Instead, I simply edit the configuration files.</p>
<p>The simplest way, among many solutions found on the web, was to write a script that runs <code>iptables</code> with various command line switches.</p>
<p>So I wrote a simple script, <code>/etc/network/if-up.d/iptables</code>, as follows. Whenever a network interface is brought up, the scripts in <code>/etc/network/if-up.d</code> are executed.<br />
If the file does not exist, you can create one.</p>
<p><code>#!/bin/sh</code></p>
<p><code># Flushing all rules</code><br />
<code>iptables -F</code><br />
<code>iptables -X<code><br />
<code># Setting default filter policy</code><br />
<code>iptables -P INPUT ACCEPT</code><br />
<code>iptables -P OUTPUT ACCEPT</code><br />
<code>iptables -P FORWARD ACCEPT</code><br />
<code># Block the use of http://www-proxy:3128</code><br />
<code>iptables -A OUTPUT -p tcp --dport 3128 -j DROP</code></p>
<p>Please, refer to the man page if you desire to know what each <code>iptables</code> command does.<br />
Now, all you need to do is run <code>chmod</code> to set the right permission.</p>
<p><code>chmod a+x /etc/network/if-up.d/iptables</code></p>
</div>]]></content:encoded>
</item>
<item>
<title><![CDATA[Practical IPTables]]></title>
<link>http://isal.wordpress.com/2009/10/21/practical-iptables/</link>
<pubDate>Wed, 21 Oct 2009 04:36:31 +0000</pubDate>
<dc:creator>isal</dc:creator>
<guid>http://isal.wordpress.com/2009/10/21/practical-iptables/</guid>
<description><![CDATA[Lagi ngulik command IPtables sebagai firewall tool untuk melindungi server/LAN kita dari hal-hal yan]]></description>
<content:encoded><![CDATA[Lagi ngulik command IPtables sebagai firewall tool untuk melindungi server/LAN kita dari hal-hal yan]]></content:encoded>
</item>
<item>
<title><![CDATA[Limitare trafic metro/extern folosind HTB si mipclasses]]></title>
<link>http://wolffino.wordpress.com/2009/10/19/limitare-trafic-metroextern-folosind-htb-si-mipclasses/</link>
<pubDate>Mon, 19 Oct 2009 08:45:35 +0000</pubDate>
<dc:creator>wolffino</dc:creator>
<guid>http://wolffino.wordpress.com/2009/10/19/limitare-trafic-metroextern-folosind-htb-si-mipclasses/</guid>
<description><![CDATA[Mipclasses se foloseste pentru a marca pechetele http://metropolitana.ineton.ro/ Dupa dezarhivare si]]></description>
<content:encoded><![CDATA[<div class='snap_preview'><p>Mipclasses se foloseste pentru a marca pechetele<br />
<!-- m --> <a href="http://metropolitana.ineton.ro/">http://metropolitana.ineton.ro/</a> <!-- m --></p>
<p>Dupa dezarhivare si instalare ( make &#38; make install ):</p>
<p>Cream un fisier in care vom pune liniile de comanda pentru marcarea pachetelor , de ex in /etc/htb/marcare<br />
<strong>1. Marcare pachete</strong></p>
<blockquote><p>#!/bin/bash<br />
ext_if=eth0<br />
int_if=eth1</p>
<p>iptables -t mangle -N mark_horiz_src<br />
iptables -t mangle -N mark_horiz_dst</p>
<p>iptables -t mangle -A PREROUTING -i $ext_if -j mark_horiz_src<br />
iptables -t mangle -A PREROUTING -i $int_if -j mark_horiz_dst<br />
iptables -t mangle -A OUTPUT -o $ext_if -j mark_horiz_dst</p>
<p>metro=/var/local/metro<br />
mipclasses -s mark_horiz_src -d mark_horiz_dst -m 3 &#60; $metro &#124; iptables-restore -n</p></blockquote>
<p>eth0 = Interfata ce face legatura cu providerul<br />
/var/local/metro = fisierul unde se gasesc clasele de adrese ip ce sunt considerate de catre provider metropolitan. Pachetele ce au ca sursa sau destinatie acele clase vor fi marcate cu 3.</p>
<p>Pentru a verifica ca marcarea s-a efectuat cu succes putem folosi comanda iptables -t manle -L mark_horiz_src -n -v , si urmarim sa vedem trafic pe clasele respective.</p>
<p><strong>2. Limite Download</strong></p>
<blockquote><p>#!/bin/bash<br />
DEV=eth1<br />
TC=/sbin/tc<br />
U32=&#8221;filter add dev $DEV protocol ip parent 1:0 prio 1 u32&#8243;</p>
<p>$TC qdisc del dev $DEV ingress<br />
$TC qdisc del dev $DEV root<em></em></p>
<p><em></em>$TC qdisc add dev $DEV handle ffff: ingress;  &#62;/dev/null 2&#62;&#38;1<br />
$TC qdisc add dev $DEV root handle 1: htb default 3</p>
<p>$TC class add dev $DEV parent 1: classid 1:1 htb rate 100mbit ceil 100mbit burst 64k quantum 1536<br />
#######################################################</p>
<p>###########################<br />
# Definire limite globale #<br />
###########################</p>
<p>#metropolitan<br />
$TC class add dev $DEV parent 1:1 classid 1:2 htb rate 80mbit ceil 100mbit burst 64k prio 3 quantum 1536<br />
$TC qdisc add dev $DEV parent 1:2 handle 2: sfq</p>
<p>#extern<br />
$TC class add dev $DEV parent 1:1 classid 1:3 htb rate 10mbit ceil 15mbit burst 64k prio 1 quantum 1536<br />
$TC qdisc add dev $DEV parent 1:3 handle 3 sfq</p>
<p>#############################<br />
### Definire limite clienti #<br />
#############################</p>
<p>#Client<br />
#limita client metropolitan<br />
$TC class add dev $DEV parent 1:2 classid 1:0&#215;21 htb rate 1mbit ceil 50mbit burst 16k prio 1 quantum 1536<br />
$TC ${U32} match ip dst 94.50.2.10/32 match mark 3 0xffff  flowid 1:0&#215;21</p>
<p>#limita client extern<br />
$TC class add dev $DEV parent 1:3 classid 1:0&#215;22 htb rate 32kbit ceil 1mbit burst 10k prio 2 quantum 1536<br />
$TC ${U32} match ip dst 94.50.2.10/32 flowid 1:0&#215;22</p></blockquote>
<p><strong>3. Limite Upload</strong></p>
<blockquote><p>#!/bin/bash<br />
/sbin/tc qdisc del dev eth0 root<br />
/sbin/tc qdisc del dev eth0 ingress<br />
echo &#8220;Stergere clasa upload&#8221;<br />
/sbin/tc qdisc add dev eth0 handle ffff: ingress; &#62;/dev/null 2&#62;&#38;1<br />
/sbin/tc qdisc add dev eth0 root handle 1: htb default 3 r2q 10<br />
/sbin/tc class add dev eth0 parent 1:0 classid 1:1 htb rate 100mbit ceil 100mbit prio 0 quantum 1536<br />
echo &#8220;Adaugare clasa upload&#8221;</p>
<p>###########################<br />
# Definire limite globale #<br />
###########################</p>
<p>#metropolitan<br />
/sbin/tc class add dev eth0 parent 1:1 classid 1:2 htb rate 80mbit ceil 95mbit prio 4 quantum 1536<br />
/sbin/tc qdisc add dev eth0 parent 1:2 handle 2: sfq<br />
#international<br />
/sbin/tc class add dev eth0 parent 1:1 classid 1:3 htb rate 10mbit ceil 15mbit prio 0 quantum 1536<br />
/sbin/tc qdisc add dev eth0 parent 1:3 handle 3: sfq</p>
<p>#############################<br />
### Definire limite clienti #<br />
#############################</p>
<p>/sbin/tc class add dev eth0 parent 1:2 classid 1:101 htb rate 1mbit ceil 50mbit prio 1 quantum 1536<br />
/sbin/tc filter add dev eth0 protocol ip parent 1:0 prio 1 u32 match ip src 94.50.2.10 match mark 3 0xffff flowid 1:101</p>
<p>/sbin/tc class add dev eth0 parent 1:3 classid 1:100 htb rate 512kbit ceil 5mbit prio 0 quantum 1536<br />
/sbin/tc filter add dev eth0 protocol ip parent 1:0 prio 1 u32 match ip src 94.50.2.10 flowid 1:100</p></blockquote>
<p>Pentru a monitoriza traficul , putem folosi mrtg pentru grafice iar datele le putem extrage din htb in felul urmator:</p>
<p><strong>Trafic Global Metropolitan:</strong></p>
<blockquote><p>/sbin/tc -s -d class show dev eth1 &#124;grep &#8220;htb 1:2 parent&#8221; -A2 &#124; awk &#8216; NR==2 { print $2}&#8217;<br />
/sbin/tc -s -d class show dev eth0 &#124;grep &#8220;htb 1:2 parent&#8221; -A2 &#124; awk &#8216; NR==2 { print $2}&#8217;</p></blockquote>
<p><strong>Trafic Global Extern:</strong></p>
<blockquote><p>/sbin/tc -s -d class show dev eth1 &#124;grep &#8220;htb 1:3 parent&#8221; -A2 &#124; awk &#8216; NR==2 { print $2}&#8217;<br />
/sbin/tc -s -d class show dev eth0 &#124;grep &#8220;htb 1:3 parent&#8221; -A2 &#124; awk &#8216; NR==2 { print $2}&#8217;</p></blockquote>
<p>Dupa cum se vede extragem datele din clasa 1:2 ce reprezinta clasa globala pentru metropolitan si 1:3 pentru extern.</p>
<p>Pentru monitorizarea traficului efectuat de client , se executa comenzile de mai sus pentru clasa din htb din care face parte clientul<br />
In exemplu meu:</p>
<blockquote><p># Extern<br />
/sbin/tc -s -d class show dev eth1 &#124;grep &#8220;htb 1:0&#215;22 parent&#8221; -A2 &#124; awk &#8216; NR==2 { print $2}&#8217;<br />
/sbin/tc -s -d class show dev eth0 &#124;grep &#8220;htb 1:100 parent&#8221; -A2 &#124; awk &#8216; NR==2 { print $2}&#8217;</p></blockquote>
<blockquote><p># Metropolitan<br />
/sbin/tc -s -d class show dev eth1 &#124;grep &#8220;htb 1:0&#215;21 parent&#8221; -A2 &#124; awk &#8216; NR==2 { print $2}&#8217;<br />
/sbin/tc -s -d class show dev eth0 &#124;grep &#8220;htb 1:101 parent&#8221; -A2 &#124; awk &#8216; NR==2 { print $2}&#8217;</p></blockquote>
</div>]]></content:encoded>
</item>
<item>
<title><![CDATA[Ubuntu 8.04环境下服务器常用维护命令 NGINX,PHP-FPM, APC,Memcached, MYSQL,VSFTP,Iptables,Fail2Ban]]></title>
<link>http://freshventure.wordpress.com/2009/10/19/ubuntu-8-04%e7%8e%af%e5%a2%83%e4%b8%8b%e6%9c%8d%e5%8a%a1%e5%99%a8%e5%b8%b8%e7%94%a8%e7%bb%b4%e6%8a%a4%e5%91%bd%e4%bb%a4-nginxphp-fpm-apcmemcached-mysqlvsftpiptablesfail2ban/</link>
<pubDate>Mon, 19 Oct 2009 03:13:21 +0000</pubDate>
<dc:creator>freshventure</dc:creator>
<guid>http://freshventure.wordpress.com/2009/10/19/ubuntu-8-04%e7%8e%af%e5%a2%83%e4%b8%8b%e6%9c%8d%e5%8a%a1%e5%99%a8%e5%b8%b8%e7%94%a8%e7%bb%b4%e6%8a%a4%e5%91%bd%e4%bb%a4-nginxphp-fpm-apcmemcached-mysqlvsftpiptablesfail2ban/</guid>
<description><![CDATA[1. top命令查看使用CPU最高的进程，还有进阶版htop。通常需要安装：sudo apt-get install htop 2. 更改php.ini和nginx.conf配置文件后，用/etc/i]]></description>
<content:encoded><![CDATA[<div class='snap_preview'><p>1. top命令查看使用CPU最高的进程，还有进阶版htop。通常需要安装：sudo apt-get install htop</p>
<p>2. 更改php.ini和nginx.conf配置文件后，用<strong>/etc/init.d/fp-php reload </strong>和<strong>/etc/init.d/nginx reload</strong>重启服务。<br />
只要没有添加、更改模块，不用restart参数。重启更平滑</p>
<p>3. iptables -L -v 可以查看当前防火墙的详细配置， iptables -L可以看个简化版的</p>
<p>4. fail2ban-client status ssh 或者fail2ban-client status vsftpd可以查看IP封禁状况</p>
<p>5. netstat -tap 可以查看当前开启的端口，如果memcache成功启动的话，就可以在这里看到</p>
</div>]]></content:encoded>
</item>

</channel>
</rss>
