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 10-12-2005, 08:44 AM   #1
Fordor
Member
 
Registered: Jun 2004
Location: Tallinn
Distribution: Slackware/Crux/SuSE
Posts: 84

Rep: Reputation: 15
iptables basic question


I have setup a webserver on port 81 on my network and would like it to be accesible from the internet and I use iptables. But I have a problem setting up the firewall. Here is what I type in the console:

iptables -D INPUT -j DROP
iptables -A INPUT -p tcp --dport 81 -j ACCEPT
iptables -A INPUT -p tcp --dport 80 -j ACCEPT
iptables -t nat -A PREROUTING -i $1 -p tcp --dport 80 -j DNAT
--to-destination $4:81

iptables -A INPUT -j DROP

But still server isn't accesible.

Does anyone know how to properly configure iptables?
 
Old 10-12-2005, 09:20 AM   #2
fataldata
Member
 
Registered: Jun 2002
Location: Breckenridge, Colorado
Distribution: Ubuntu Hardy 8.04
Posts: 101

Rep: Reputation: 15
It's been a while since I have messed with iptables. If you have not been using this linux PC as a firewall/NAT before, one note would be to ensure that you have IP forwarding enabled.

echo 1 > /proc/sys/net/ipv4/ip_forward
 
Old 10-12-2005, 09:33 AM   #3
Fordor
Member
 
Registered: Jun 2004
Location: Tallinn
Distribution: Slackware/Crux/SuSE
Posts: 84

Original Poster
Rep: Reputation: 15
Forwarding is enabled, in fact 3 ports are forwarded already.


I am thinking maybe it's because I have DMZ setup for 1 pc and add forwarding to port 80 after DMZ is set. I think iptables finds the dmz mode and ignores all other entries. Could it be that?

[root@asus root]$ iptables -t nat -L -v -n
Chain PREROUTING (policy ACCEPT 48 packets, 3516 bytes)
pkts bytes target prot opt in out source destination
0 0 DNAT tcp -- * * 0.0.0.0/0 192.168.62.50 tcp dpt:4666 to:192.168.0.53:4666
0 0 DNAT udp -- * * 0.0.0.0/0 192.168.62.50 udp dpt:4672 to:192.168.0.53:4672
0 0 DNAT tcp -- * * 0.0.0.0/0 192.168.62.50 tcp dpt:4999 to:192.168.0.53:4999
3 169 DNAT all -- * * 0.0.0.0/0 192.168.62.50 to:192.168.0.50
0 0 DNAT tcp -- * * 0.0.0.0/0 192.168.62.50 tcp dpt:80 to:192.168.0.1:81

Chain POSTROUTING (policy ACCEPT 25 packets, 1957 bytes)
pkts bytes target prot opt in out source destination
12 1121 MASQUERADE all -- * vlan1 !192.168.62.50 0.0.0.0/0
2 353 MASQUERADE all -- * br0 192.168.0.0/24 192.168.0.0/24

Chain OUTPUT (policy ACCEPT 24 packets, 2141 bytes)
pkts bytes target prot opt in out source destination
[root@asus root]$
 
Old 10-12-2005, 04:06 PM   #4
tvynr
Member
 
Registered: Apr 2004
Distribution: Debian
Posts: 143

Rep: Reputation: 15
I know it's sloppy but, as a general rule, I add most rules I create to INPUT, OUTPUT, and FORWARD via another chain I create:

$ipt -N chain
$ipt -A INPUT -j chain
$ipt -A OUTPUT -j chain
$ipt -A FORWARD -j chain

Then I'm quite picky about the rules I add to it.

$ipt -A chain -i $ext_ifc -p tcp --dport 80 -j ACCEPT
$ipt -t nat -A PREROUTING -d $ext_ip -p tcp --dport 80 -j DNAT --to-destination $ip_webserver:81

Something like that. ("$ext_ifc" is the external interface; "$ext_ip" is the external IP address.) It's ugly, but I've never had any trouble with it.

I seem to remember reading once that, if anything is getting forwarded along, the rule needs to be passed to FORWARD instead of INPUT. But I'm not sure.
 
Old 10-12-2005, 04:23 PM   #5
fataldata
Member
 
Registered: Jun 2002
Location: Breckenridge, Colorado
Distribution: Ubuntu Hardy 8.04
Posts: 101

Rep: Reputation: 15
Quote:
I seem to remember reading once that, if anything is getting forwarded along, the rule needs to be passed to FORWARD instead of INPUT. But I'm not sure.
Man I totally missed that. I think tvynr is correct. The input table applies to packets destined for the kernel. The forward table is for packets to be passed through.
 
Old 10-12-2005, 05:30 PM   #6
Fordor
Member
 
Registered: Jun 2004
Location: Tallinn
Distribution: Slackware/Crux/SuSE
Posts: 84

Original Poster
Rep: Reputation: 15
Yes, thank's that worked out well.

And by the way, the input is for a certain pc to accept the packet, so in this case if a server is on port 81 I need to accept tcp on port 81 and in prerouting I need to forward 80 external to 81 internal.


Thanks
 
  


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
Basic iptables howto??? PeaceTank Linux - Security 2 03-23-2005 01:30 AM
Basic iptables/firewall docs emailssent Linux - Networking 7 10-10-2004 11:02 PM
very basic question about labels in iptables celadoreuk Linux - Networking 0 10-05-2004 10:50 AM
Basic Question insyte Linux - Wireless Networking 4 09-16-2004 11:57 AM
basic question jaina2 Linux - Newbie 1 07-26-2003 02:44 AM

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

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