LinuxQuestions.org
Share your knowledge at the LQ Wiki.
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 06-26-2012, 01:20 PM   #1
lasantha
Member
 
Registered: Oct 2005
Location: Sri Lanka
Distribution: Red Hat, Cent OS
Posts: 38

Rep: Reputation: 16
Smile Packet redirecting using DNAT


Hi,

I am having a problem in iptables DNAT. My office mail server was decided to move to VPS on one of ISPs VM from local premises. The new mail server was installed and DNS was updated according to that. Users that use mail client porgrame to download and send mails(SMTP/POP) (eudora and outlook) can be connected to new mail server now by changing their outgoing and incoming ip address(same address used).

Because of practical difficulty to change each and every mail client's outgoing and incoming address of more than 300 mail clients, I have tried to use iptable rule in old mail server linux machine to redirect packets that destined to old mail server address (which already configured in every mail client) to new mail servre in ISP VM, using DNAT.

My rules are given below but it not working properly. Pls check and correct me in this.


eth0 is connected to internet
eht1 is connected to LAN 192.168.1.200
new mail server address xx.yy.zz.kk
Code:
echo 1 > /proc/sys/net/ipv4/ip_forward
iptables -P INPUT DROP
iptables -P FORWARD DROP
iptables -P OUTPUT ACCEPT

iptables -F INPUT 
iptables -F FORWARD 
iptables -F OUTPUT 

iptables -A FORWARD -i eth1 -o eth0 -j ACCEPT 
iptables -A FORWARD -i eth0 -o eth1 -m state --state ESTABLISHED,RELATED -j ACCEPT
iptables -t nat -A PREROUTING -i eth0 -p tcp --dport 25 -d 192.168.1.200 -j DNAT --to xx.yy.zz.kk:25
iptables -t nat -A PREROUTING -i eth0 -p tcp --dport 110 -d 192.168.1.200 -j DNAT --to xx.yy.zz.kk:110

service iptables save
service iptables restart
Thank you
 
Old 06-27-2012, 05:57 AM   #2
fukawi1
Member
 
Registered: Apr 2009
Location: Melbourne
Distribution: Fedora & CentOS
Posts: 854

Rep: Reputation: 193Reputation: 193
is ip_forwarding enabled in the kernel?
Code:
$ cat /sys/proc/net/ipv4/ip_forward
1
 
Old 06-27-2012, 10:51 AM   #3
lasantha
Member
 
Registered: Oct 2005
Location: Sri Lanka
Distribution: Red Hat, Cent OS
Posts: 38

Original Poster
Rep: Reputation: 16
It is clearly stated there,, in my code.
 
Old 06-28-2012, 02:34 AM   #4
fukawi1
Member
 
Registered: Apr 2009
Location: Melbourne
Distribution: Fedora & CentOS
Posts: 854

Rep: Reputation: 193Reputation: 193
Indeed it is, sorry I missed that..
Personally, the easiest way to fix this would be to modify the mx record/s so your mail server urls point to the correct address of the VPS. That is assuming you are currently using DNS to identify the local mail server, if you're not, IP changes are a good reason to...

Are routes properly configured?

You probably also need an rule to SNAT (static) or MASQUERADE (dynamic) your internet bound traffic back to the routers internet facing IP.

Ill share a couple of tricks I use when diagnosing iptables rules..
Generate some traffic that will match the rule you are trying to diagnose, with netcat, hping, etc.
You can "watch" the byte/packet counters while generating the traffic.
Code:
watch iptables -nvL INPUT
In some cases you can create logging rules that will match the traffic you are diagnosing rules for, can also give some useful information.
Code:
iptables -t nat -A PREROUTING -p tcp --dport 25 -j LOG --log-prefix "DROP: " --log-ip-options --log-tcp-options --log-level warn
Another is to use tcpdump on each host, to see where things are getting tripped up...

Just one other thought, is the firewall on the VPS configured to accept the traffic...
 
Old 06-28-2012, 04:43 PM   #5
lasantha
Member
 
Registered: Oct 2005
Location: Sri Lanka
Distribution: Red Hat, Cent OS
Posts: 38

Original Poster
Rep: Reputation: 16
thanks for the help. I have managed to write the rule. Now it is working. What i have done is create masquerade rule and forward rule for incoming traffic to the end of the rule set.


Thanks for the help.
 
  


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
[SOLVED] example for netwrok packet code for creating a module and access the packet data oracle89divi22 Linux - Newbie 13 01-13-2012 04:27 PM
Packet Redirecting to another interface of the box chayan.ju Linux - Networking 1 11-19-2010 12:37 PM
DNAT on first SYN ACK packet sseeley Linux - Networking 2 08-24-2010 01:33 PM
A packet filter using libipq which uses ether type field to capture the packet can26_manish Programming 2 10-16-2007 05:35 AM
Strange DNAT behaviour... packet don't pass to PREROUTING and go directly in INPUT !! cbettero Linux - Networking 7 03-09-2007 02:37 PM

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

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