Linux - Networking This forum is for any issue related to networks or networking.
Routing, network cards, OSI, etc. Anything is fair game. |
Notices |
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
Are you new to LinuxQuestions.org? Visit the following links:
Site Howto |
Site FAQ |
Sitemap |
Register Now
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
|
 |
10-04-2013, 07:53 AM
|
#1
|
Member
Registered: Mar 2012
Location: England
Distribution: Debian, Kali, CentOS 7
Posts: 64
Rep: 
|
iptables used to route RDP connection across subnet with NAT
First off I am assuming RDP traffic can be forwarded/NAT'd.
I've learnt this stuff from scratch to achieve this so I figure I've made a mistake along the way, so hopefully one of you seasoned iptable'rs has the answer.
I am trying to:
RDP from 10.14.136.x (subnet255.255.252.0) to 10.14.100.21. Via Eth0 10.14.138.72 forwarding to Eth1 10.14.100.2.
None of this is public, just two private networks I own but I want to keep them separate.
Code:
iptables -t nat -A PREROUTING -d 10.14.138.72 -i eth0 -j DNAT --to-destination 10.14.100.21
iptables -t nat -A POSTROUTING -s 10.14.100.21 -o eth0 -j SNAT --to-source 10.14.138.72
iptables -A FORWARD -p tcp -i eth0 -o eth1 -j ACCEPT
Do these rules makes sense? cos I'm getting stuck and I've tried a lot of revisions now...
Thanks in advance!
(as a side note, if anyone knows of a very comprehensive book/resource to crack routing with please reference it.)
Last edited by borgy95; 10-04-2013 at 07:56 AM.
|
|
|
10-05-2013, 04:11 AM
|
#2
|
Senior Member
Registered: Jan 2012
Distribution: Slackware
Posts: 3,348
Rep: 
|
RDP traffic can be NATed, as it uses the TCP transport protocol, and the application protocol itself does not make any references to IP addresses or host names.
Having said that, I'm not entirely sure about what you're trying to accomplish. I understand you have two subnets, 10.14.136.0/22 and 10.14.100.0/<something>. Communication between subnets is a simple matter of routing; the hosts on either network must be using a gateway. NAT is not required.
It seems you want the host 10.14.138.72 to forward RDP traffic destined for itself to 10.14.100.2. In that case, the first and last iptables commands will accomplish that:
Code:
iptables -t nat -A PREROUTING -d 10.14.138.72 -i eth0 -j DNAT --to-destination 10.14.100.21
iptables -A FORWARD -p tcp -i eth0 -o eth1 -j ACCEPT
The first line adds an address rewriting rule to the PREROUTING chain in the nat table, changing the destination address 10.14.138.72 into 10.14.100.21. The last line allows any TCP traffic through the FORWARD chain in the filter table. The rule is perhaps overly broad, but it will allow the NATed RDP packets through.
As mentioned, the host performing NAT in this scenario must either be assigned the 10.14.138.72 address, or it will have to be the gateway for hosts on the 10.14.136.0/22 network. It must also be able to reach the 10.14.100.0/? network via eth1.
The middle rule doesn't really make sense. It changes the source address of the NATed RDP packets to 10.14.138.72. What is the purpose of this rule?
|
|
|
10-07-2013, 03:49 AM
|
#3
|
Member
Registered: Mar 2012
Location: England
Distribution: Debian, Kali, CentOS 7
Posts: 64
Original Poster
Rep: 
|
Thanks Ser!
Let me try to use better english this time...
NAT host: eth0=10.14.138.72/22 eth1=10.14.100.2/25 s destination= 10.14.100.21 source= 10.14.136.0/22
Ok glad to hear the prerouting/forward are correct functional if not perfect. I had the POSTROUTING rule in there to handle the returned traffic, my logic was as RDP runs over TCP that meant there would be a two way stream of traffic and thus the router would need to know how to handle traffic coming back in the opposite direction. Is it not needed, in this context? If not in what normal context would the POSTROUTING rule be used?
Also i will tighten these up to use port 3389 for RDP connections.
Again thank you for taking the time to explain. I'll make some adjustments and post.
|
|
|
10-07-2013, 05:53 AM
|
#4
|
Member
Registered: Mar 2012
Location: England
Distribution: Debian, Kali, CentOS 7
Posts: 64
Original Poster
Rep: 
|
Another assumption i have made is that, when selecting the IP to connect to in the RDP window i should be entering 10.14.138.72 as this is the NIC the source client can see. Then when the traffic reaches 10.14.138.72 it will be translated by the iptables rules to go on to 10.14.100.21. Is this understanding correct?
|
|
|
10-07-2013, 02:57 PM
|
#5
|
Senior Member
Registered: Jan 2012
Distribution: Slackware
Posts: 3,348
Rep: 
|
Quote:
Originally Posted by borgy95
Another assumption i have made is that, when selecting the IP to connect to in the RDP window i should be entering 10.14.138.72 as this is the NIC the source client can see. Then when the traffic reaches 10.14.138.72 it will be translated by the iptables rules to go on to 10.14.100.21. Is this understanding correct?
|
Yes, that's correct.
The packet from the RDP client will go to 10.14.138.72, which doesn't actually have an RDP service running on TCP port 3389, but before it can be processed by the IP stack, it hits the PREROUTING chain of the nat table. The destination address is changed to 10.14.100.21 and, as a result, the packet is processed by the routing engine and sent out eth1.
The question then is, what happens to the return traffic? The RDP server will send reply packets to the source address of the initial packet, which will be a host on the 10.14.136.0/22 network. Unless the RDP server has a route for the 10.14.136.0/22 network with the IP address of the NATing host's address in the 10.14.100.0 network (10.14.100.2) as the next-hop address, the reply packets will never get back to the host on the 10.14.136.0/22 network.
A possible solution would be to use source NAT and change the source address to that of the eth1 interface of the NATing host. All RDP connections will appear to come from that single host, and since the client address would then be in the same network as the RDP server, no routing would be required for the return traffic. The NAT rule would look something like this:
Code:
iptables -t nat -A POSTROUTING -o eth1 -d 10.14.100.21 -p tcp --dport 3389 -j SNAT --to-source 10.14.100.2
(Assuming 10.14.100.2 is the IP address assigned to eth1 on the NATing host, while 10.14.100.21 is the RDP server.)
|
|
|
10-14-2013, 10:48 AM
|
#6
|
Member
Registered: Mar 2012
Location: England
Distribution: Debian, Kali, CentOS 7
Posts: 64
Original Poster
Rep: 
|
Again thanks for the detail. I've got the theory now, i understand the syntax, and its making sense etc. But no Joy I've tried alot combinations now. Including the ones in the above posts. my attempts have led me to the following:
Code:
iptables FORWARD --p tcp -i eth0 -o eth1 -j ACCEPT
iptables FORWARD -p tcp -i eth1 -o eth0 -j ACCEPT
iptables -t nat PREROUTING -s 10.14.138.72 -i eth0 -j DNAT --to-destination 10.14.100.21
iptables -t nat POSTROUTING -s 10.14.138.72 -o eth0 -j SNAT --to-source 10.14.138.72
I've tried so many i think something is out to get me and I've been pretty systematic about it all.
I've now disabled apparmor... But I'm thinking since SLES has both rcSuSEfirewall2 and iptables could there be a conflict? or are they both the same? By running the
Code:
/sbinrcSuSEfirewall2 restart
am I really refreshing the iptables so the rules take hold? Also I'm concerned that when I
Code:
tail /var/logs/messages
the firewall logs show nothing is happening much is happening even though I've been attempting to send RDP traffic through? I would have expected to at least something about packets dropping? perhaps there is somewhere I can view the logs in more detail, maybe this is the wrong place?
|
|
|
All times are GMT -5. The time now is 12:42 PM.
|
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.
|
Latest Threads
LQ News
|
|