LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Networking
User Name
Password
Linux - Networking This forum is for any issue related to networks or networking.
Routing, network cards, OSI, etc. Anything is fair game.

Notices


Reply
  Search this Thread
Old 03-07-2005, 10:27 PM   #1
narmida
Member
 
Registered: Mar 2005
Location: Alphen aan den Rijn , netherlands
Distribution: core
Posts: 57

Rep: Reputation: 15
Question [IPTABLES] FTP doesnt work with ls command


I have a problem with this script it makes a ftp connection but doesnt give a ls
(bit to much ftp rules btw but i tried everything)
another problem is that from the server itself i cannot go to the internet
ssh work and the emule ports work also

also any comment on this script is welcome

what i also need to know is it ressistent agains brute force etc etc
dont want any supprises

if it works good ill make more $variables etc i will upload it to here for others




#!/bin/bash

echo Load modules
modprobe ip_conntrack_ftp
modprobe iptable_nat
modprobe ip_nat_ftp

#---------------------------------------------------------------
# FLUSH ALL
#---------------------------------------------------------------
echo Flush firewall rules
/sbin/iptables --flush
/sbin/iptables -t nat --flush
/sbin/iptables -t mangle --flush
echo Remove all chains
/sbin/iptables --delete-chain
/sbin/iptables -t nat --delete-chain
/sbin/iptables -t mangle --delete-chain
#---------------------------------------------------------------
# DROP ALL (never remove) and dont reject plz
#---------------------------------------------------------------
echo Setting DROP ALL
/sbin/iptables --policy INPUT DROP
/sbin/iptables --policy OUTPUT DROP
/sbin/iptables --policy FORWARD DROP
#---------------------------------------------------------------
# Allow local loopback everything needed for X etc...
#---------------------------------------------------------------
echo Local loopback accept all in and out
/sbin/iptables -A INPUT -i lo -j ACCEPT
/sbin/iptables -A OUTPUT -o lo -j ACCEPT
#---------------------------------------------------------------
# Allow DNS queries to be made in and out
#---------------------------------------------------------------
echo Outgoing DNS port 53
/sbin/iptables -A OUTPUT -p udp -o eth0 --dport 53 --sport 1024:65535 -j ACCEPT
echo Incoming DNS port 53
/sbin/iptables -A INPUT -p udp -i eth0 --sport 53 --dport 1024:65535 -j ACCEPT
#---------------------------------------------------------------
# Dont break the connections already running.
#---------------------------------------------------------------
echo Dont break the connections already running.
/sbin/iptables -A OUTPUT -o eth0 -m state --state ESTABLISHED,RELATED -j ACCEPT
#---------------------------------------------------------------
# Define local trusted network
#---------------------------------------------------------------
echo Allow all from local network
/sbin/iptables -A INPUT -j ACCEPT -p all -s 192.168.5.0/24 -i eth1
/sbin/iptables -A OUTPUT -j ACCEPT -p all -d 192.168.5.0/24 -o eth1
#---------------------------------------------------------------
# Allow masquerading
# - Interface eth0 is the internet interface
# - Interface eth1 is the private network interface
#---------------------------------------------------------------
echo Allow routing from local network
/sbin/iptables -A POSTROUTING -t nat -o eth0 -s 192.168.5.0/24 -d 0/0 -j MASQUERADE
#/sbin/iptables -A POSTROUTING -t nat -o lo -s 127.0.0.0/8 -d 0/0 -j MASQUERADE
/sbin/iptables -A FORWARD -t filter -i eth1 -m state --state NEW,ESTABLISHED,RELATED -j ACCEPT
#---------------------------------------------------------------
# Incase of DHCP on the WAN side we look for the IP given
# If not DHCP still this is valid
# also handy for ppp connections
# works only on linux not unix etc
#---------------------------------------------------------------
echo Locate external ip
external_int="eth0"
external_ip="`ifconfig $external_int | grep 'inet addr' | awk '{print $2}' | sed -e 's/.*://'`"
#---------------------------------------------------------------
# log unsolicited tcp udp and icmp packets
#---------------------------------------------------------------
echo log unsolicited tcp udp and icmp packets
/sbin/iptables -A INPUT -i $external_ip -p tcp -j LOG -m limit --limit 2/minute --log-prefix 'firewall-tcp ' --log-level info
/sbin/iptables -A INPUT -i $external_ip -p udp -j LOG -m limit --limit 2/minute --log-prefix 'firewall-udp ' --log-level info
/sbin/iptables -A INPUT -i $external_ip -p icmp -j LOG -m limit --limit 2/minute --log-prefix 'firewall-icmp ' --log-level info
#---------------------------------------------------------------
# Drop pings (should be already)
#---------------------------------------------------------------
echo Drop pings
/sbin/iptables -A INPUT -i $external_ip -p icmp --icmp-type ping -j DROP
#---------------------------------------------------------------
# Allowed ports CUSTOM
#---------------------------------------------------------------

echo allow HTTP
/sbin/iptables -A INPUT -p tcp -i eth0 -d $external_ip --dport 80 -j ACCEPT
/sbin/iptables -A OUTPUT -j ACCEPT -m state --state NEW -o $external_ip -p tcp -m multiport --dport 80

echo allow HTTPS

/sbin/iptables -A INPUT -p tcp -i eth0 -d $external_ip --dport 443 -j ACCEPT
/sbin/iptables -A OUTPUT -j ACCEPT -m state --state NEW -o $external_ip -p tcp -m multiport --dport 443

echo Allow SSH
/sbin/iptables -A INPUT -p tcp -i eth0 -d $external_ip --dport 22 -j ACCEPT

echo Allow FTP
/sbin/iptables -A INPUT -p tcp -i eth0 -d $external_ip --dport 21 -j ACCEPT
/sbin/iptables -A INPUT -p udp -i eth0 -d $external_ip --dport 21 -j ACCEPT
/sbin/iptables -A INPUT -p tcp -i eth0 -d $external_ip --dport 20 -j ACCEPT
/sbin/iptables -A INPUT -p udp -i eth0 -d $external_ip --dport 20 -j ACCEPT
/sbin/iptables -A OUTPUT -p tcp -d $external_ip -m state --state ESTABLISHED -m multiport --dport 21 -j ACCEPT
/sbin/iptables -A OUTPUT -p udp -d $external_ip -m state --state ESTABLISHED -m multiport --dport 21 -j ACCEPT
/sbin/iptables -A OUTPUT -p tcp -d $external_ip -m state --state ESTABLISHED -m multiport --dport 20 -j ACCEPT
/sbin/iptables -A OUTPUT -p udp -d $external_ip -m state --state ESTABLISHED -m multiport --dport 20 -j ACCEPT
/sbin/iptables -A OUTPUT -j ACCEPT -m state --state NEW -o $external_ip -p tcp -m multiport --dport 20


#---------------------------------------------------------------
# Allowed forwards CUSTOM
#---------------------------------------------------------------
echo Forward emule ports to .99
/sbin/iptables -t nat -A PREROUTING -p tcp -i eth0 -d $external_ip --dport 26187 --sport 1024:65535 -j DNAT --to 192.168.5.99:26187
/sbin/iptables -t nat -A PREROUTING -p udp -i eth0 -d $external_ip --dport 26198 --sport 1024:65535 -j DNAT --to 192.168.5.99:26198
/sbin/iptables -A FORWARD -p tcp -i eth0 -o eth1 -d 192.168.5.99 --dport 26187 --sport 1024:65535 -m state --state NEW -j ACCEPT
/sbin/iptables -A FORWARD -p udp -i eth0 -o eth1 -d 192.168.5.99 --dport 26198 --sport 1024:65535 -m state --state NEW -j ACCEPT

echo Forward emule ports to .98 1 point higer then normal ports
/sbin/iptables -t nat -A PREROUTING -p tcp -i eth0 -d $external_ip --dport 26188 --sport 1024:65535 -j DNAT --to 192.168.5.98:26188
/sbin/iptables -t nat -A PREROUTING -p udp -i eth0 -d $external_ip --dport 26199 --sport 1024:65535 -j DNAT --to 192.168.5.98:26199
/sbin/iptables -A FORWARD -p tcp -i eth0 -o eth1 -d 192.168.5.98 --dport 26188 --sport 1024:65535 -m state --state NEW -j ACCEPT
/sbin/iptables -A FORWARD -p udp -i eth0 -o eth1 -d 192.168.5.98 --dport 26199 --sport 1024:65535 -m state --state NEW -j ACCEPT

#---------------------------------------------------------------
# Allow routing
#---------------------------------------------------------------
# internet routing
/sbin/iptables -A FORWARD -t filter -i eth1 -m state --state NEW,ESTABLISHED,RELATED -j ACCEPT
/sbin/iptables -A FORWARD -t filter -i eth0 -m state --state ESTABLISHED,RELATED -j ACCEPT
echo 1 > /proc/sys/net/ipv4/ip_forward

echo end
echo give list
route
/sbin/iptables -L

Last edited by narmida; 03-07-2005 at 10:30 PM.
 
Old 03-08-2005, 11:45 AM   #2
lapazzo
LQ Newbie
 
Registered: Mar 2005
Posts: 7

Rep: Reputation: 0
if you are using passive ftpd then port ftp-data is not used. when your server is also configured in passive mode, then there shouldn't be anything special in the firewall itself. just open the ftp port ... and that's it.

hope it helps
 
Old 03-09-2005, 12:54 AM   #3
narmida
Member
 
Registered: Mar 2005
Location: Alphen aan den Rijn , netherlands
Distribution: core
Posts: 57

Original Poster
Rep: Reputation: 15
hmmm im using passive ftp but only with port 20 open it doest work.
maybe the MASQ is the problem
 
Old 03-11-2005, 12:51 PM   #4
lapazzo
LQ Newbie
 
Registered: Mar 2005
Posts: 7

Rep: Reputation: 0
give me an email or icq 29382263 ... i'll give you my firewall.
 
  


Reply



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 Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Http and Ftp doesnt work Anthraxnz Linux - Newbie 7 09-18-2005 07:22 AM
iptables / FTP masquerading: Port command illegal radiowhiz Linux - Networking 1 03-23-2005 05:15 PM
My router command doesnt work digital bots Linux - Networking 1 05-24-2004 01:23 PM
./wlanup command doesnt work Kilahchris Linux - Wireless Networking 4 05-10-2004 09:48 PM
Export command doesnt work correctly basix Linux - Software 6 02-28-2004 10:54 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Networking

All times are GMT -5. The time now is 08:05 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration