LinuxQuestions.org
Review your favorite Linux distribution.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Software
User Name
Password
Linux - Software This forum is for Software issues.
Having a problem installing a new program? Want to know which application is best for the job? Post your question in this forum.

Notices


Reply
  Search this Thread
Old 11-03-2013, 10:21 AM   #1
beliya
LQ Newbie
 
Registered: Feb 2011
Posts: 20

Rep: Reputation: 0
Question wrong iptables rules on firewall


Hello.

I have firewall with three physical network interfaces running on Debian Linux. The addressing looks as follows:

eth0 - wan - 192.168.168.2
eth1 - lan1 - 10.1.1.1
eth2 - lan2 - 10.2.1.1

I have few servers in the lan1 network from which I want some ports forwarded to the wan network. For example: I want port 22 (ssh) on address 10.1.1.11 forwarded to address 192.168.168.2 and port 6990 so that users in the 192.168.168.0/24 network can connect to the ssh server listening on 10.1.1.11:22. I have the following rules in my iptables script:

Code:
echo 1 > /proc/sys/net/ipv4/ip_forward
iptables -t nat -A POSTROUTING -o eth0 -j MASQUERADE

iptables -t nat -A PREROUTING -p tcp -i eth0 --dport 6990 -j DNAT --to-destination 10.1.1.11:22
However, when I try to connect with ssh client from the firewall I receive the following error:

Code:
root@fw:~$ ssh -p 6990 root@192.168.168.2
ssh: connect to host 192.168.168.2 port 6990: Connection refused
root@fw:~$
I think that I'm doing something wrong here and my rules are not correct.

Can please anybody help me with that?
 
Old 11-03-2013, 12:51 PM   #2
Ser Olmy
Senior Member
 
Registered: Jan 2012
Distribution: Slackware
Posts: 3,340

Rep: Reputation: Disabled
Your NAT rule looks OK, but unless the policy for the FORWARD chain in the filter table is "ACCEPT" (which is not recommended), you'll have to add a corresponding rule in that chain to allow traffic through:
Code:
iptables -A FORWARD -i eth0 -d 10.1.1.11 -p tcp --dport 22 -j ACCEPT
Tha packets hit the FORWARD chain (and the routing table) post-NAT, so the rule must refer to the altered destination address.
 
Old 11-03-2013, 02:37 PM   #3
beliya
LQ Newbie
 
Registered: Feb 2011
Posts: 20

Original Poster
Rep: Reputation: 0
Ser Olmy,

Thank you for replying. Now the part regarding this action in the firewall script looks like this:

Code:
iptables -t nat -A PREROUTING -p tcp -i eth0 --dport 6990 -j DNAT --to-destination 10.1.1.11:22
iptables -A FORWARD -i eth0 -d 10.1.1.11 -p tcp --dport 22 -j ACCEPT
Unfortunately the same thing happens again and I can't connect.
 
Old 11-03-2013, 02:43 PM   #4
Ser Olmy
Senior Member
 
Registered: Jan 2012
Distribution: Slackware
Posts: 3,340

Rep: Reputation: Disabled
Is 10.1.1.1 the default gateway on the 10.1.1.11 host?

Can you open an SSH connection from 10.1.1.1 to 10.1.1.11?

Have you tried running tcpdump on 10.1.1.1 or 10.1.1.11 to see what's happening?
 
Old 11-03-2013, 02:53 PM   #5
beliya
LQ Newbie
 
Registered: Feb 2011
Posts: 20

Original Poster
Rep: Reputation: 0
Yes, 10.1.1.1 is the default gateway for 10.1.1.11.
Yes, I can establish ssh connection from 10.1.1.1 to 10.1.1.11.

I haven't tried using tcpdump to see why the connection is failing. That's actually a very good idea. I will try doing that and then I'll report. This will probably happen tomorrow because it's getting very late and my mind is not sharp enough right now.
 
  


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
What is wrong with my iptables rules for port 80? alex123456 Linux - Security 10 08-25-2012 08:57 AM
Writing firewall rules with iptables bzlaskar Linux - Security 1 02-27-2007 07:41 AM
Iptables rules for basic firewall winxandlinx Linux - Security 7 10-27-2006 07:12 AM
help with firewall rules .. ipfilter<-->iptables playahater Linux - Security 1 03-05-2006 04:00 AM
Problem Iptables, Firewall rules. Can anybody help ? ZliTroX Linux - Networking 9 09-06-2004 04:48 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Software

All times are GMT -5. The time now is 12:20 AM.

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