TCP connection between two openshift containers - tcp

I have two applications (diy container type) which have to be connected via TCP. Let's take as example application clusternode1 and clusternode2.
Each one has TCP listener set up for $OPENSHIFT_DIY_IP:$OPENSHIFT_DIY_PORT.
For some reason clusternode1 fails to connect to any of the following options for clusternode2:
$OPENSHIFT_DIY_IP:$OPENSHIFT_DIY_PORT
$OPENSHIFT_APP_DNS
Can you please help in understanding what should be url for external TCP connection?

You might check the logs to see if the OPENSHIFT_DIY_IP for both apps are within the same subnet. If one, say, is...
1.2.3.4
...and the other is...
1.5.6.7
...for example, then you might not expect Amazon's firewalls to just arbitrarily allow TCP traffic from one subnet to another. If this were allowed by default then one person's app might try to hack another's.
I know that when you're dealing directly with Amazon AWS and you spin up multiple virtual servers you have to create virtual zones to allow traffic between them. This might be something that's necessary.
Proxy Ports I don't know if this is useful but it's possible that a private IP address is being bound to your application(s) and then a NAT server is translating that into a public IP address.

Related

What hostname did the client use to connect to my TCP server?

In http the client supplies the hostname it used to connect to the service with. Now, for bare TCP connections, is there something similar one can do? My scenario is I have a service that has multiple open TCP ports and that works fine, but for convenience I would like to use the same port and subdomains. Is there any layer I can add on top (like a load balancer), or change the service? I have control over most things, basically anything goes.
Example:
Today I can connect to two TCP services like so: foobar.com:1001 and foobar.com:1002. Is it possible to have e.g. service-1.foobar.com:1000 go to foobar.com:1001 and service-2.foobar.com:1000 go to foobar.com:1002.
Different services can bind to same port but on different IP. Hence different domains shall resolve to different IPs : Port combination [where Port is same for all services]. And you can use Proxy service as from HA Proxy to route connections to final destination.
If I understand your question correctly based on your example then no it is not possible. In this case, there is no difference between an HTTP and TCP connection.
In both cases, the hostname is simply resolved to an ip address. If you setup DNS resolution for foobar.com, service-1.foobar.com, service-2.foobar.com to point to the same ip address then they will all go to the same machine.
I have at times needed to have a service running on a different port internally than it is accessible externally. For that, if you are running on Linux, you can simply use iptables to do the port forwarding.
You can find other stack overflow questions/answers for setting up the port forwarding.
https://serverfault.com/questions/140622/how-can-i-port-forward-with-iptables

if I have a local ipv4 address can I use it from outside a network to talk across a NAT

I have an application where I want a device inside a network behind a NAT to make a call to the public network giving a server its local address, Later, say 10 or 20 minutes later, I'd like the server to be able to contact the device inside the network.
Is there any protocol generally supported by firewalls/routers etc. that would direct me to the local node if I provided its actual current local address?
Thanks
No, there is no such protocol. Moreover, in the case of multiple NAT, the local node can only know its address behind the innermost NAT, and the server can only know the public address outside the outermost NAT, so you have no means of mapping through multiple NATs, or even knowing how many exist in the path.
The local node will have to initiate and maintain an open connection with the server if it wants to receive anything from the server.
No there is not a protocol for mapping the IP address, though you can use portmapping/port forwarding to map specific a port to an IP Address
This is the sort of thing UPNP is meant to solve. Note that there are still challenges -- the network equipment needs to support it and the feature needs to be enabled. Many network admins will not enable it for good reason.

how to redirect connections to IPs behind the NAT to NATted (public ) IPs at the source?

I have an application that relies on IP addresses for communication (Domain names simply does not work. :(... )
Its function is to connect to its peer on the other machine and send data over after establishing trust. During the "trust establishing" phase they both exchange their IPs for future communication. They both are behind the two different firewalls and are NATted. One is in our NATted office network and other is in the cloud NATted behind their firewall. The applications knows their respective private IPs and exchange that (the 10.x.xxx.xxx range), when they try to connect back to each other (using the private IPs with range 10.x.xxx.xxx) for transferring data they fail. The connection is TCP and the port range is pretty varied.
I am curious if there is anyway I can hard code (for this one time) a rule (at may be firewall level or some place outside my application) that says if there is a connection being initiated for IP address 10.x.xxx.xxx then redirect it to 205.x.xxx.xxx?
Private IP address ranges like 10.x.y.z are, by their very nature, private.
You can't do any meaningful resolution unless each node in between the endpoints has rules in place to translate these.
Translation is tricky, all the main tools you would use cater for static translation (port forwarding, e.g. where a particular port is forwarded to a particular IP). This is one avenue, but it is a hacky one (it requires you to open lots of ports, procedurally update your router and probably have some sort of broker server to maintain mappings).
Alternatively, you could run the isolated networks over a VPN, which would give your endpoints mutual private IPs which you can use to connect to eachother. It would simply be a case of binding to this new address and communicating across the VPN. This would also potentially encrypt your communication over the internet.
Other possibilities are to use NAT/TCP punchthrough techniques which can allow traversal, but these are really a patch to a broken network topology (Read up on IPv6 to see how this can be alleviated).
Alternatively, you could route all the connections over a proxy, but this will complicate matters compared to a VPN.
To answer the question about hardcoding a rule, port forwarding is the solution here. It will obviously depend on your router configuration for the peer accepting the connection, but this client should have the port target port forwarded to the machine. This will obviously not scale very well and is really shifting to a server/client architecture for one connection!
Depending on your hardware, you may be able to forward a range of ports (if a single port cannot be established) and limit the port forwarding to certain incoming connections (the external IPs).
Information on port forwarding can be found at http://portforward.com/
This sounds a lot like what you'd want out of a VPN. Is there anyway that you could set one up? Basically the Site-To-Site VPN between you and the cloud would say 'oh hey, here is an ip located on the remote network, go ahead and connect through the link'. Would this kind of solution work in your case?
Something along these lines: http://i.msdn.microsoft.com/dynimg/IC589512.jpg

Network Systems Help: How to route an external request, by hostname to an internal ip?

Welcome to my first question on stack overflow.
I've looked around, and I haven't found this question asked yet. However, that may be because I don't know how to ask the question that I need answered.
THE INFORMATION:
I'm a programmer who left the public sector that had a, surprisingly, well-managed IT department that had all this crap working for me. I now work for a private company that needs a bit of network systems help.
We have:
A SQL Server
An Application Server
A File Server
A Web Server
multiple web services
team foundation server
share point services
5 desktops
all on our internal network.
We also have:
- No domain controller
- No Internal DNS / NAT / DHCP Server.
We're currently using a router for DHCP and Port Forwarding. We are getting a static IP assigned today.
THE QUESTION:
What do I need to setup in order to point our external domains / subdomains to our new static IP and have those requests routed (by the hostname used) to hit a specific server?
Current Configuration (Port Forwarding)
ourdomain.com:1234 -> router/port-forwarding -> SQL Server:1433
ourdomain.com:1235 -> router/port-forwarding -> Web Service 1:8081
ourdomain.com:1236 -> router/port-forwarding -> Web Service 2:8082
ourdomain.com:1237 -> router/port-forwarding -> Application Server:5410
What I think I want:
sql.ourdomain.com:80 -> ??? -> SQL Server:1433
svc1.ourdomain.com:80 -> ??? -> Web Service 1:80 (host: svc1.ourdomain.com)
svc2.ourdomain.com:80 -> ??? -> Web Service 2:80 (host: svc2.ourdomain.com)
app.ourdomain.com:80 -> ??? -> Application Server:5410
The (host: xxx) is where I would specify the host in the IIS website configuration.
There will be some instances where port-forwarding is necessary, but it's not ideal for every instance. I want to remember meaningful names, not arbitrary port numbers.
If what I'm asking here is completely ridiculous, well, thanks for reading. I'm just looking for some direction.
Thanks!
<edit>
12:01 am PDT 4/19/2012
Sorry, let me clarify a few things.
We only have a single static public IP address.
Assume that we can acquire / setup the necessary hardware / software to achieve this.
If what it comes down to is that we need to buy some enterprise level routing hardware, that's just what it takes. I know this has to be possible because at my last job, we had 40 or 50 domains all pointed to the same IP that routed to different servers once inside the internal network. :/ Or at least that's what happened to the best of my knowledge.
I actually called them up today and asked them, but the main dude who set it all up quit.
I'm really pushing for us to just get our crap out into the cloud, since no one wants to hire a network engineer or systems analyst, much less build a data center.
</edit>
An easy way that this could work if each subdomain resolves into different public ip addresses (e.g. if your DNS was configured such that sql.ourdomain.com resolves to 1.1.1.1 and svc1.ourdomain.com resolves to 1.1.1.2).
sql.ourdomain.com IN A 1.1.1.1
svc1.ourdomain.com IN A 1.1.1.2
Your router can only make decisions based on limited information contained inside of the ip packets. Commonly, routers can look at the ip or port information. In the case where your router is configured with port forwarding, the router looks at the port number and makes address translation decisions using that the port.
rule: incoming port 1000, forward to 192.168.1.100:1433
rule: incoming port 1001, forward to 192.168.1.101:80
However, if the port is the same, the router needs other information to decide how to perform the translation. Most low-end routers (e.g. Cisco ASA series, Juniper SRX series) can use the ip to make this address translation decision. The downside is that that you'll need to purchase multiple ip addresses from your ISP.
rule: incoming ip 1.1.1.1, forward to 192.168.1.100:1443
rule: incoming ip 1.1.1.2, forward to 192.168.1.101:80
IIS, which operates on a much higher layer on the network stack, can make this differentiation by looking at the HTTP headers. This works for multiplexing a single ip and single port to multiple websites. In this case, since SQL and your web server speak different protocols, you won't be able to leverage this.
Another technology that you may want to consider is IPsec tunneling (VPN) if your device supports IPsec passthrough. The downside is that your coworkers (who I assume are using this) needs to perform additional configuration.

How to tamper with source IP address on Windows

We meet a testing scenario which needs to tamper with source IP address of a Http request to simulate clients coming from different countries. Do you know any tool help on this?
Last but not least, our web site is built with ASP.NET.
Thanks.
In a test environment it usually isn't difficult. First read this SO question about virtual network interfaces.
If the server and client are on the same machine, all you have to do is figure out how to get your client software to bind to your virtual interface.
wget for instance has the --bind-address option to specify which local address to bind to. Web browsers are a bit more difficult to do this with; you may need to just run it in a VM.
If your server and client are on the same LAN, you just need to configure your router with some static routes to your client machine. In this case you probably don't need a virtual network interface, just set a static IP for your client machine; as long as the gateway is set up correctly it should be able to send packets to the server, and as long as the route is set up correctly the replies should find their way back to the client.
If the client and server are separated by an internet, it's rather more difficult. One option is to set up a network tunnel endpoint on the server and tunnel it to the client machine, which "knows" that it has the virtual network interface.
As noted in answers to the ServerFault question "Are IP addresses trivial to forge", you cannot easily forge source addresses in a protocol that required two way communication (e.g. TCP). Note that this "two way communication" is required at the packet level. You cannot just say "no problem, I want to send requests and ignore HTTP responses." To establish a TCP session, you need to receive data. Your best bet is to use a proxy server.
I am unsure if the IP standard allows for this, but if you are working in a Lab environment, where you don't need internet connectivity during the test, I can see it working under following circumstances:
Basically, I would set the server's network interface to use netmask 0.0.0.0 and flush the rest of the routing table.
Then you could configure a client machine to take on any IP address as long as you use netmask 0.0.0.0. And two-way communication should be possible.
Server[1.2.3.4/0] <---> Client[x.x.x.x/0]
But please bear with me. I haven't tested this, so I could be wrong :-)
If you have access to your infrastructure, you can add an interface off the router and then place a static route on the router to that network.
Server-----Router----Internet
/
Test_PC----/
Alternatively you can look into PBR (Policy Based Routing) and on the routers you can flag source packets and change the source on the fly, so your server will think they are coming from where you'd like them to come from.
Server-------------Router_with_PBR-------------Internet----- PC
SCR:4.2.2.2 Change SCR:6.6.6.6 to 4.2.2.2 6.6.6.6
But you have to ask yourself why do you want to see when packets come from different countries. Some countries have massive proxy servers that filter access ( "Great Firewall of China"), so the above tests will not prove much.
Your best bet then is using proxy servers or if your looking for a long term solution then setup a server (virtual is great for this) and use RDP for testing. I'm sure you can rent a virtual server somewhere for a month or two.
That's not possible. Because when you forge the ip address, the response is never going to come back, which is required for http.
The best way is to use proxies. See also this question on serverfault.
If you change your source IP address, that means no traffic from your web server will be able to reach back to the client.
You might be able to use some kind of proxy and/or address translation filter to do the remapping while still allowing two-way communication.

Resources