Tag Archives: firewall

iptables router

Sveiki,

susilaukiau klausimu, kaip pasidalinti internetu su kitu kompu turint dvi tinklo plokstes.

Taigi labai paprasta. Tikriausiai Jus naudojate standartini branduoliuka, del to ten bus visi branduolio moduliai ijungti.
Bet del viso ko galite pasibandyti, jei tingit, pereinam prie FW script’uko:


lsmod | grep ip_tables
lsmod | grep x_tables


Jei ten negauname rezultato:


~# lsmod | grep ip_tables
ip_tables 22042 3 iptable_filter,iptable_nat,iptable_mangle
x_tables 19073 11 ip_tables,iptable_filter,iptable_nat,ipt_MASQUERADE,xt_state,xt_tcpudp,ipt_LOG,ipt_REJECT,xt_limit,xt_multiport,iptable_mangle
~# lsmod | grep x_tables
x_tables 19073 11 ip_tables,iptable_filter,iptable_nat,ipt_MASQUERADE,xt_state,xt_tcpudp,ipt_LOG,ipt_REJECT,xt_limit,xt_multiport,iptable_mangle


Tuomet tiesiog pameginkime juos uzkrauti 🙂


modprobe ip_tables
modprobe x_tables


Ir issisaugoti automatiskai kraunamu moduliu sarase:


echo "ip_tables" >> /etc/modules
echo "x_tables" >> /etc/modules


SVARBU!

IPTABLES skaito taisykles EILES TVARKA!!! Taigi UZDAROME PABAIGOJE!

Taigi beliko tik pasirasyti FW script’uka (P.S. pas jus gal neveiks conntrack –ctstate , tai keiskite state –state):


#!/bin/bash
#
export PATH="/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin"
# apsirasom IPTABLES
IPTABLES="/sbin/iptables"
# Isvalom esamas taisykles
$IPTABLES -F
$IPTABLES -X
$IPTABLES -t nat -F
$IPTABLES -t nat -X
$IPTABLES -P INPUT ACCEPT
$IPTABLES -P OUTPUT ACCEPT
$IPTABLES -P FORWARD ACCEPT
# Local interface:
LOCAL_IF=eth1
# External (Internetas) interface:
INTER_IF=eth0
# jei Jusu IP statinis siulau nurotyri rankiniu budu:
INTER_IP="11.222.33.4"
# Pas mane dinaminis IP todel as ji gaudau per skriptuka... Jei Jusu statinis IP, uzkomentuokite sia eilute
INTER_IP=`ip addr show eth0 | grep "inet " | awk '{print $2}' | cut -f1 -d\/`
#
# Ijungiu FORWARDinima:
echo "1" > /proc/sys/net/ipv4/ip_forward
$IPTABLES -t nat -A POSTROUTING -o $INTER_IF -j MASQUERADE
# Tinklas LAN'ui
$IPTABLES -A FORWARD -i $INTER_IF -o $LOCAL_IF -m conntrack --ctstate ESTABLISHED,RELATED -j ACCEPT
# Jei neveikia -m conntrack --ctstate ...
# $IPTABLES -A FORWARD -i $INTER_IF -o $LOCAL_IF -m state --state ESTABLISHED,RELATED -j ACCEPT
$IPTABLES -A FORWARD -i $LOCAL_IF -o $INTER_IF -j ACCEPT
#
# Kuriu naujas/papildomas grandis:
$IPTABLES -N TCP_DROP_LOG
$IPTABLES -N UDP_DROP_LOG
$IPTABLES -N TCP_ACCEPT_LOG
$IPTABLES -N UDP_ACCEPT_LOG
$IPTABLES -N LOGDROP
$IPTABLES -N LOGDROP2
#
# Leidziu VISKA is VIDAUS
$IPTABLES -A INPUT -i $LOCAL_IF -j ACCEPT
#
# Accept PING, kartais naudinga, patikrint ar jusu servas gyvas
$IPTABLES -A INPUT -p icmp --icmp-type echo-request -j ACCEPT
$IPTABLES -A OUTPUT -p icmp --icmp-type echo-reply -j ACCEPT
#
# Leidziu uzmegstas sesijas
$IPTABLES -A INPUT -m conntrack --ctstate ESTABLISHED,RELATED -j ACCEPT
#
# $IPTABLES -A INPUT -m conntrack --ctstate ESTABLISHED,RELATED -j ACCEPT
#
# Visus kas kreipiasi i 22 poerta is isores, loginam :)
$IPTABLES -A INPUT -d $INTER_IP --proto tcp --dport 22 -j LOGDROP
#
### PORT FORWARDING
### PORT FORWARD
#
# SSH SERVER internete pasiekiamas per 212 porta, nors realiai kito LAN'e esancio kompo (192.168.168.192) 22 portas
# $IPTABLES -t nat -A PREROUTING -i $INTER_IP --proto tcp --dport 212 -j DNAT --to 192.168.168.192:22
#
# rdp forward i 192.168.111.252 win xp winxp XP masina
$IPTABLES -t nat -A PREROUTING -i $INTER_IP --proto tcp --dport 3389 -j DNAT --to 192.168.111.252:3389
#
#
$IPTABLES -A LOGDROP2 -j LOG --log-prefix "DROPPED " --log-level 4 --log-ip-options --log-tcp-options --log-tcp-sequence
$IPTABLES -A LOGDROP2 -j DROP
$IPTABLES -A LOGDROP -m limit --limit 1/second --limit-burst 10 -j LOGDROP2
$IPTABLES -A LOGDROP -m limit --limit 2/minute --limit-burst 1 -j LOG --log-prefix "LIMITED " --log-level 4
$IPTABLES -A LOGDROP -j DROP
#
##### Po sios komandos, isijungia FIREWALL! ATSARGIAI!
#
$IPTABLES -A INPUT -i $INTER_IF -j DROP
#
logger -p info -t syslog "firewall updated"
exit 0


Na va pas jus toks minimalus, noob’iskas firewall’as 🙂

External links

Gentoo iptables for newbies

skanaus 🙂