Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

I have two Linux CentOS servers setup in a local network. ServerA is 192.168.0.1 and serverB is 192.168.0.2.

There's an application on serverA that communicates with serverB using host2.serverAname.com. But, the traffic is blocked on serverB because the port being used has a firewall that only allows traffic on the local network to pass. Thus, serverB needs to see traffic from serverA as originating from 192.168.0.1 (instead of host2.serverA.com).

Is there a way I can configure the /etc/hosts file to ensure traffic always sent between the two servers uses local IP addresses, regardless of what hostname is in use, and for ALL applications?

If so, could someone walk me through an example? I only have 2 servers, so the simpler the better.

share|improve this question

2 Answers 2

up vote 2 down vote accepted

The "stupid" approach should work: add an entry in your /etc/hosts on serverA for every hostname (or combine into a single line - split here for legibility):

192.168.0.2    serverB
192.168.0.2    serverB.serverAname.com
192.168.0.2    host2
192.168.0.2    host2.serverAname.com

Add any other hostnames for that IP as required. On serverB you really only need to have an IP for serverA if it's the one initiating connections, but it's a good idea anyway.

Also check that nothing strange is happening with your routing and default gateways, and triple-check with traceroute.

share|improve this answer
    
Thanks Andrew. Is your example /etc/hosts file above for serverA or B? Silly question -- if I'm editing the /etc/hosts file for serverB having local IP of 192.168.0.2, do all the local IP addresses need to be 192.168.0.2, or can I also include local IP addresses of 192.168.0.1? If this is not how it's intended, how does traffic received at serverB from serverA know to send traffic back to serverA on 192.168.0.1? –  gkdsp Mar 27 '12 at 2:32
    
@gkdsp Updated - that's for serverA. The connection (presumably TCP) has a source IP and port; serverB shouldn't need to know how to resolve serverA to reply, but it doesn't hurt. –  Andrew Mar 27 '12 at 2:51

If I understand you well, you need to be able to connect to the same server from different locations with different destination IPs.

One way to do this is to use Split DNS. This actually includes defining two separate zone files for the same domain. One internal view to be viewed by internal users (private IPs) and other external view to be viewed by external users (public IPs). Have a look at this page and this on configuring multiple views in bind DNS server.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.