LinuxQuestions.org
Help answer threads with 0 replies.
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-03-2008, 08:23 AM   #1
mrlinux2000
Member
 
Registered: Feb 2008
Posts: 144

Rep: Reputation: 15
iptables


this is the commands that i want to apply so from external ppl can get access to my http local port


iptables -A PREROUTING -t nat -p tcp -d int-ip --dport 23 -j DNAT --to-destination 198.168.1.12:23
iptables -A PREROUTING -t nat -p tcp -d int-ip --dport 80 -j DNAT --to-destination 198.168.1.12:80


and it is OK

but when i apply this commands before

IPTABLES -P INPUT DROP
IPTABLES -P FORWARD DROP

IPTABLES -F -t filter
IPTABLES -F -t nat
IPTABLES -F -t mangle

i cannot ping and no access to the local http or telnet even if i specify
external address
iptables -A PREROUTING -t nat -p tcp -s allowed-ip -d int-ip --dport 23 -j DNAT --to-destination 198.168.1.12:23

nothing and even no ping !

any help
 
Old 03-03-2008, 12:13 PM   #2
mtimbro
Member
 
Registered: Feb 2008
Location: Montreal, Canada
Distribution: RedHat 3/4, Ubuntu 7.10
Posts: 86

Rep: Reputation: 15
Exclamation

Quote:
Originally Posted by mrlinux2000 View Post
this is the commands that i want to apply so from external ppl can get access to my http local port


iptables -A PREROUTING -t nat -p tcp -d int-ip --dport 23 -j DNAT --to-destination 198.168.1.12:23
iptables -A PREROUTING -t nat -p tcp -d int-ip --dport 80 -j DNAT --to-destination 198.168.1.12:80


and it is OK

but when i apply this commands before

IPTABLES -P INPUT DROP
IPTABLES -P FORWARD DROP

IPTABLES -F -t filter
IPTABLES -F -t nat
IPTABLES -F -t mangle

i cannot ping and no access to the local http or telnet even if i specify
external address
iptables -A PREROUTING -t nat -p tcp -s allowed-ip -d int-ip --dport 23 -j DNAT --to-destination 198.168.1.12:23

nothing and even no ping !

any help
The problem is you're dropping all packets regardless, as your default policy for the INPUT chain is DROP.

Under your PREROUTING rules you have to ACCEPT incoming packets for both your ports, i.e.:

iptables -A INPUT -p tcp -m state --state NEW --dport 80 -i eth1 -j ACCEPT
iptables -A INPUT -p tcp -m state --state NEW --dport 23 -i eth1 -j ACCEPT

Hope this helps.

Last edited by mtimbro; 03-03-2008 at 12:52 PM.
 
Old 03-03-2008, 02:56 PM   #3
archer
LQ Newbie
 
Registered: Mar 2008
Posts: 28

Rep: Reputation: 15
Unhappy enable/disable access

Hi I want to know how to disable/enable access to a site with iptables.
I have read many tutorials for iptables.Could someone tell me how to do it.(If it cannot be done reply me that it cannot be done).And something more:If what I asked for can be done how do we discover the ip of a site?

I am sorry if you became tired reading my post!
(please try to answer quickly)
thank you very much!
 
Old 03-04-2008, 04:51 AM   #4
mrlinux2000
Member
 
Registered: Feb 2008
Posts: 144

Original Poster
Rep: Reputation: 15
sorry but this didnt work ...
thank you
 
Old 03-04-2008, 05:17 AM   #5
rossonieri#1
Member
 
Registered: Jun 2007
Posts: 359

Rep: Reputation: 34
@ archer :

to enable or disable access : yes - both can be done.
to discover the IP : turn on iptables logging feature.

@ mrlinux :

dont just do the -P forward DROP without explicitly state what can be forward --> that will stop all forwarding function --> you will go nowhere.

HTH.
 
Old 03-04-2008, 07:38 AM   #6
archer
LQ Newbie
 
Registered: Mar 2008
Posts: 28

Rep: Reputation: 15
Because I am new in iptables could you:
1)How to enable the iptables logging feauture?
2)How can I tell iptables not to have/don't have access in a site.

Sorry for the many questions!
Thank you for the quick answer!
archer
 
Old 03-04-2008, 08:52 AM   #7
rossonieri#1
Member
 
Registered: Jun 2007
Posts: 359

Rep: Reputation: 34
Quote:
Originally Posted by archer View Post
Because I am new in iptables could you:
1)How to enable the iptables logging feauture?
iptables -i <input_interface> -p <protocol> -j LOG

Quote:
2)How can I tell iptables not to have/don't have access in a site.
suppose you being the site :

iptables -i <input_interface> -p <protocol> -j ACCEPT -----> to allow access

iptables -i <input_interface> -p <protocol> -j DROP ----> to deny

Quote:
Sorry for the many questions!
Thank you for the quick answer!
archer
you are very welcome.
 
Old 03-04-2008, 01:45 PM   #8
mrlinux2000
Member
 
Registered: Feb 2008
Posts: 144

Original Poster
Rep: Reputation: 15
please i created this thread to solve my problem , if you dont mind you can create your own
 
Old 03-04-2008, 01:47 PM   #9
mrlinux2000
Member
 
Registered: Feb 2008
Posts: 144

Original Poster
Rep: Reputation: 15
and i still not have a solution,

if i apply iptables -p input drop


and after it
iptables -A PREROUTING -t nat -p tcp -d ext_adr --dport 23 -j DNAT --to-destination 10.10.5.2:23

nothing work even ping !!
 
Old 03-04-2008, 10:16 PM   #10
rossonieri#1
Member
 
Registered: Jun 2007
Posts: 359

Rep: Reputation: 34
hi mrlinux :

you have to exclude your desired protocol on both INPUT and PREROUTING to get your redirection to function.

so you must allow first in PREROUTING - then in INPUT chain.

example :
iptables -t nat -I PREROUTING -i <outside> -p tcp --dport 23 -j DNAT --to <inside:23>
iptables -I INPUT -i <outside> -p tcp --dport 23 -m state --state NEW -j LOG
iptables -I INPUT -i <outside> -p tcp --dport 23 -m state --state NEW -j ACCEPT

HTH.
 
Old 03-05-2008, 03:19 AM   #11
mrlinux2000
Member
 
Registered: Feb 2008
Posts: 144

Original Poster
Rep: Reputation: 15
as always after iptables -p input drop , i cant ping or do anything
 
Old 03-05-2008, 04:43 AM   #12
rossonieri#1
Member
 
Registered: Jun 2007
Posts: 359

Rep: Reputation: 34
hi

OK - lets see what you have in your iptables rules shall we?
so we will not guessing why?
 
Old 03-05-2008, 05:48 AM   #13
mrlinux2000
Member
 
Registered: Feb 2008
Posts: 144

Original Poster
Rep: Reputation: 15
ext_ip : net ip
192.168.1.11: ip of the eth0 card
192.168.1.2 pc that i want to access from the net


iptables -A PREROUTING -t nat -p tcp -d ext_ip --dport 23 -j DNAT --to-destination 192.168.1.2:23
iptables -A OUTPUT -t nat -p tcp -d ext_ip --dport 23 -j DNAT --to-destination 192.168.1.2:23
iptables -A POSTROUTING -t nat -p tcp -d 192.168.1.2 -j SNAT --to-source 192.168.1.11
iptables -I INPUT -i ext_ip -p tcp --dport 23 -m state --state NEW -j LOG
iptables -I INPUT -i ext_ip -p tcp --dport 23 -m state --state NEW -j ACCEPT
iptables -A FORWARD -p tcp -d 10.10.5.208 --dport 23 -j ACCEPT -m state --state NEW,ESTABLISHED,RELATED
it is wrking ...
but everything is open and i see attack on my eth1 so when i add :
iptables -p input drop
iptables -p output drop
it does not work
 
Old 03-05-2008, 07:31 AM   #14
rossonieri#1
Member
 
Registered: Jun 2007
Posts: 359

Rep: Reputation: 34
hi mrlinux

Quote:
ext_ip : net ip
192.168.1.11: ip of the eth0 card
192.168.1.2 pc that i want to access from the net


iptables -A PREROUTING -t nat -p tcp -d ext_ip --dport 23 -j DNAT --to-destination 192.168.1.2:23
iptables -A OUTPUT -t nat -p tcp -d ext_ip --dport 23 -j DNAT --to-destination 192.168.1.2:23
iptables -A POSTROUTING -t nat -p tcp -d 192.168.1.2 -j SNAT --to-source 192.168.1.11
iptables -I INPUT -i ext_ip -p tcp --dport 23 -m state --state NEW -j LOG
iptables -I INPUT -i ext_ip -p tcp --dport 23 -m state --state NEW -j ACCEPT
iptables -A FORWARD -p tcp -d 10.10.5.208 --dport 23 -j ACCEPT -m state --state NEW,ESTABLISHED,RELATED
it is wrking ...
but everything is open and i see attack on my eth1 so when i add :
iptables -p input drop
iptables -p output drop
it does not work
sorry, i got so tired today - and not too comfortable reading.
but your iptables seems not in order.

actually simple - that is because you did not allow localhost 127.0.0.1/8 to communicate also.
Code:
iptables -I INPUT -i lo -s 127.0.0.1/8 -j ACCEPT # allow localhost
iptables -I INPUT -i LAN_IF -s LAN_IP -d LAN_IP -j ACCEPT # allow LAN
iptables -I INPUT -i WAN_IF -m state --state RELATED,ESTABLISHED -j ACCEPT # allow established session from WAN
iptables -I INPUT -i WAN_IF -m state ! --state RELATED,ESTABLISHED -j DROP # drop new or invalid session from WAN

iptables -t nat -I PREROUTING -i WAN_IF -p tcp --dport 23 -j DNAT --to LAN_IP:23 # redirecting telnet to inside
iptables -t nat -I POSTROUTING -o WAN_IF -j MASQUERADE # basic masquerade

iptables -P INPUT DROP

and you dont need to DROP the FORWARD and OUTPUT chain unless you already mastered the iptables. no offense

try step by step - analyze how it works - then customize once you get familier with it.

HTH.

Last edited by rossonieri#1; 03-05-2008 at 07:34 AM.
 
Old 03-05-2008, 08:14 AM   #15
mrlinux2000
Member
 
Registered: Feb 2008
Posts: 144

Original Poster
Rep: Reputation: 15
thank you for helping but it works , because there was no forwarding between two cards

"iptables -A FORWARD -i eth0 -o eth1 -j ACCEPT -m state --state NEW,ESTABLISHED,RELATED"
thank you
 
  


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
iptables v1.2.9: Unknown arg `/sbin/iptables' Try `iptables -h' or 'iptables --help' Niceman2005 Linux - Security 4 12-29-2005 08:20 PM
Iptables - Couldn't load target `ACCPET':/lib/iptables/libipt_ACCPET.so: z00t Linux - Security 3 01-26-2004 02:24 AM
IPtables Log Analyzer from http://www.gege.org/iptables/ brainlego Linux - Software 0 08-11-2003 06:08 AM
iptables book wich one can you pll recomment to be an iptables expert? linuxownt Linux - General 2 06-26-2003 04:38 PM
My iptables script is /etc/sysconfig/iptables. How do i make this baby execute on boo ForumKid Linux - General 3 01-22-2002 07:36 AM

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

All times are GMT -5. The time now is 04:34 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