Networking Forums

Networking Forums > Computer Networking > Linux Networking > ssh access through iptables

Reply
Thread Tools Display Modes

ssh access through iptables

 
 
gaur_ms@yahoo.co.in
Guest
Posts: n/a

 
      10-26-2005, 05:05 PM
Hi,
I have iptables running on redhat Linux. sshd is running on this
machine. I can access this machine through ssh from within my lan but
from outside internet I am not able to access to any machine within the
LAN (internal IP addresses) the connection times out from internet to
this firewall machine. If I need to access a particular machine through
Ssh through iptables what rules need to be built?
Many thanks in advance
-Karmath

 
Reply With Quote
 
 
 
 
Hans-Juergen Lange
Guest
Posts: n/a

 
      10-26-2005, 06:06 PM
(E-Mail Removed) wrote:
> Hi,
> I have iptables running on redhat Linux. sshd is running on this
> machine. I can access this machine through ssh from within my lan but
> from outside internet I am not able to access to any machine within the
> LAN (internal IP addresses) the connection times out from internet to
> this firewall machine. If I need to access a particular machine through
> Ssh through iptables what rules need to be built?
> Many thanks in advance
> -Karmath
>


Hi,

take this.

BR
Hans-Juergen Lange

!/bin/bash
INET="ppp0"
LAN="eth1"
LO="lo"

LAN_IP_RANGE="192.168.10.0/24"
LAN_IP="192.168.10.1"
LAN_BROADCAST="192.168.10.255"
IPTABLES="/sbin/iptables"

echo "1" > /proc/sys/net/ipv4/ip_forward
echo "1" > /proc/sys/net/ipv4/ip_dynaddr

echo "Setup standard policies"

$IPTABLES -P INPUT DROP
$IPTABLES -P OUTPUT DROP
$IPTABLES -P FORWARD DROP


$IPTABLES -F INPUT DROP
$IPTABLES -F OUTPUT DROP
$IPTABLES -F FORWARD DROP

echo "Setup user defined chain allowed"
$IPTABLES -N allowed
$IPTABLES -F allowed

$IPTABLES -A allowed -p TCP --syn -j ACCEPT
$IPTABLES -A allowed -p TCP -m state --state ESTABLISHED,RELATED -j ACCEPT
$IPTABLES -A allowed -p TCP -j DROP

echo "Allow gnutella"
$IPTABLES -A FORWARD -p TCP -i $INET --dport 8347 -j ACCEPT
$IPTABLES -t nat -A PREROUTING -p TCP -i $INET --dport 8347 -j DNAT \
--to-destination 192.168.10.3

echo "Forward ssh port"
$IPTABLES -A FORWARD -p udp -i $INET --dport 22 -j ACCEPT
$IPTABLES -t nat -A PREROUTING -p udp -i $INET --dport 22 -j DNAT \
--to-destination 192.168.10.3

$IPTABLES -A FORWARD -p TCP -i $INET --dport 22 -j ACCEPT
$IPTABLES -t nat -A PREROUTING -p TCP -i $INET --dport 22 -j DNAT \
--to-destination 192.168.10.3

echo "block incoming connections"
$IPTABLES -A INPUT -p tcp ! --syn -m state --state NEW -j DROP

echo "Accept outgoing"
$IPTABLES -A INPUT -p ALL -i $LAN -s $LAN_IP_RANGE -j ACCEPT
$IPTABLES -A INPUT -p ALL -i $LO -j ACCEPT
$IPTABLES -A INPUT -p ALL -i $LAN -d $LAN_BROADCAST -j ACCEPT

echo "Accept established and related"
$IPTABLES -A INPUT -p ALL -i $INET -m state --state ESTABLISHED,RELATED\
-j ACCEPT

echo "Drop sync packets"
$IPTABLES -A FORWARD -p tcp ! --syn -m state --state NEW -j DROP

echo "Windows block"
$IPTABLES -A FORWARD -p udp -i $LAN --dport 137:139 -j DROP
$IPTABLES -A FORWARD -p udp -i $LAN --dport 135 -j DROP
$IPTABLES -A FORWARD -p udp -i $LAN --dport 500 -j DROP
$IPTABLES -A FORWARD -p tcp -i $LAN --dport 445 -j DROP

echo "Forward all others"
$IPTABLES -A FORWARD -i $LAN -j ACCEPT
$IPTABLES -A FORWARD -m state --state ESTABLISHED,RELATED -j ACCEPT

echo "Output rules"
$IPTABLES -A OUTPUT -p ALL -s 127.0.0.1 -j ACCEPT
$IPTABLES -A OUTPUT -p ALL -s $LAN_IP -j ACCEPT
$IPTABLES -A OUTPUT -p ALL -o $INET -j ACCEPT

echo "Post routing"
$IPTABLES -t nat -A POSTROUTING -o $INET -j MASQUERADE


 
Reply With Quote
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Iptables - nat and internet access from server carlos.yanez.s@gmail.com Linux Networking 1 03-12-2005 07:28 PM
iptables blocks access to some websites? Gururajan Ramachandran Linux Networking 2 09-03-2004 06:38 PM
Iptables Forwarding Works But Now No NFS Access. Gazza Linux Networking 0 07-19-2004 09:17 PM
iptables; allowing external web access to 192.168.0.1; how? =?ISO-8859-1?Q?Ga=E9tan_Martineau?= Linux Networking 4 01-09-2004 11:51 PM
iptables; denying web access to 192.168.0.5; how? =?ISO-8859-1?Q?Ga=E9tan_Martineau?= Linux Networking 1 01-09-2004 08:24 PM



1 2 3 4 5 6 7 8 9 10 11