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 05-01-2015, 05:40 PM   #1
mr_future
LQ Newbie
 
Registered: May 2015
Posts: 8

Rep: Reputation: Disabled
iptables port mirroring issue


Hello!

Using iptables, I am mirroring all traffic on udp port 1514 from a production CentOS server to a dev CentOS server. As such, the dev server receives a copy of all udp 1514 packets sent to the production server. Here is the command I used:

iptables -t mangle -D PREROUTING -i ens160 -p udp --dport 1514 -j TEE --gateway 10.88.72.40

When capturing these packets on the second server, the destination IP is that of the production server. This is a problem because I want a service to interact with this traffic. How do I "trick" the second server into thinking that the mirrored packets are meant for it? Have been looking into rewriting the destination IP of the packets, but no luck so far. Thanks.
 
Old 05-02-2015, 12:37 AM   #2
lazydog
Senior Member
 
Registered: Dec 2003
Location: The Key Stone State
Distribution: CentOS Sabayon and now Gentoo
Posts: 1,249
Blog Entries: 3

Rep: Reputation: 194Reputation: 194
Quote:
Originally Posted by mr_future View Post
iptables -t mangle -D PREROUTING -i ens160 -p udp --dport 1514 -j TEE --gateway 10.88.72.40
You are aware that the above is used to delete the rule.
 
Old 05-02-2015, 12:17 PM   #3
mr_future
LQ Newbie
 
Registered: May 2015
Posts: 8

Original Poster
Rep: Reputation: Disabled
Yes, that was a typo. I know that rule works because I'm seeing all of the redirected packets running tcdump on the second server. I used this command:

iptables -t mangle -A PREROUTING -i ens160 -p udp --dport 1514 -j TEE --gateway 10.88.72.40
 
Old 05-04-2015, 09:15 AM   #4
lazydog
Senior Member
 
Registered: Dec 2003
Location: The Key Stone State
Distribution: CentOS Sabayon and now Gentoo
Posts: 1,249
Blog Entries: 3

Rep: Reputation: 194Reputation: 194
Quote:
Originally Posted by mr_future View Post
Have been looking into rewriting the destination IP of the packets, but no luck so far. Thanks.
Have your tried this:

Code:
iptables -t nat -A PREROUTING -p tcp -d <real server> --dport 1514 -j DNAT --to-destination <fake server>
Might need to create a new change and do everything in there so it is all grouped together.
 
Old 05-04-2015, 11:33 AM   #5
mr_future
LQ Newbie
 
Registered: May 2015
Posts: 8

Original Poster
Rep: Reputation: Disabled
Lazydog, would I add your policy to the first server (mirroring the traffic) or the second (receiving packets with wrong destination IP)?
 
Old 05-04-2015, 02:54 PM   #6
lazydog
Senior Member
 
Registered: Dec 2003
Location: The Key Stone State
Distribution: CentOS Sabayon and now Gentoo
Posts: 1,249
Blog Entries: 3

Rep: Reputation: 194Reputation: 194
You would need to do this on the host where you have the other rules to send the traffic to the second system.

I would think a new chain would be best. Traffic comes in and then is pushed to the chain where you could change the ip address and then send it off to the second system.

Last edited by lazydog; 05-04-2015 at 02:56 PM.
 
Old 05-05-2015, 11:12 AM   #7
mr_future
LQ Newbie
 
Registered: May 2015
Posts: 8

Original Poster
Rep: Reputation: Disabled
I'm new to iptables. Could you show me a config example of what you're talking about?
 
Old 05-05-2015, 02:51 PM   #8
lazydog
Senior Member
 
Registered: Dec 2003
Location: The Key Stone State
Distribution: CentOS Sabayon and now Gentoo
Posts: 1,249
Blog Entries: 3

Rep: Reputation: 194Reputation: 194
On second thought you might be able to do this on the second seerver. The server would see that the packet is for itself and then do what you want it to do.
 
Old 05-07-2015, 10:43 AM   #9
mr_future
LQ Newbie
 
Registered: May 2015
Posts: 8

Original Poster
Rep: Reputation: Disabled
I have discovered that, on the second machine, I cannot use iptables to route packets addressed to other IPs to localhost. I'm running Centos7, which doesn't support kernel 3.6, which is needed to do this.

So my plan is to add a second interface on the original server. Then:

iptables -t mangle -A PREROUTING -i ens160 -p udp --dport 1514 -j TEE --gateway 10.88.72.43

where 10.88.72.43 is the second NIC of the same server. The problem is that I cannot detect any packets reaching this interface. Please advise on how I can redirect TEE packets to a different interface on the same host.
 
Old 05-07-2015, 11:36 AM   #10
lazydog
Senior Member
 
Registered: Dec 2003
Location: The Key Stone State
Distribution: CentOS Sabayon and now Gentoo
Posts: 1,249
Blog Entries: 3

Rep: Reputation: 194Reputation: 194
Have you tried to use PREROUTE on the incoming packet to set the ip address?
 
Old 05-07-2015, 01:36 PM   #11
mr_future
LQ Newbie
 
Registered: May 2015
Posts: 8

Original Poster
Rep: Reputation: Disabled
If I did that, then the application on the first server wouldn't be able to see the packets.
 
Old 05-07-2015, 02:03 PM   #12
lazydog
Senior Member
 
Registered: Dec 2003
Location: The Key Stone State
Distribution: CentOS Sabayon and now Gentoo
Posts: 1,249
Blog Entries: 3

Rep: Reputation: 194Reputation: 194
On the second server.
 
Old 05-07-2015, 03:50 PM   #13
mr_future
LQ Newbie
 
Registered: May 2015
Posts: 8

Original Poster
Rep: Reputation: Disabled
Yes, on the second server I tried:

iptables -t nat -A PREROUTING -p udp -d 10.88.72.41 --dport 1514 -j NETMAP --10.88.72.40

where 10.88.72.40 is the IP of the second server. In my tcpdump capture on the second server, the destination IP is still 10.88.72.41 .
 
Old 05-08-2015, 07:04 AM   #14
lazydog
Senior Member
 
Registered: Dec 2003
Location: The Key Stone State
Distribution: CentOS Sabayon and now Gentoo
Posts: 1,249
Blog Entries: 3

Rep: Reputation: 194Reputation: 194
TCPDUMP is capturing the packet before it has transversed the stack.
 
Old 05-08-2015, 10:03 AM   #15
mr_future
LQ Newbie
 
Registered: May 2015
Posts: 8

Original Poster
Rep: Reputation: Disabled
I found the answer. On the second server, create a virtual loopback device with the same IP as the first server.
 
  


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] IPtables : ssh port forwarding one port to another port issue routers Linux - Networking 7 08-07-2018 08:41 AM
iptables port forwarding not working - routing issue huafist Linux - Networking 7 02-01-2011 09:39 AM
[SOLVED] iptables port forward issue leosophy Linux - Networking 17 08-31-2010 02:28 AM
Open port in iptables and apf issue jolly Linux - Security 1 10-02-2006 08:45 PM
iptables port forwarding issue Garak Linux - Security 7 09-29-2006 04:31 PM

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

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