[CentOS] port mapping

Sun Jan 20 20:13:57 UTC 2008
Barry Brimer <lists at brimer.org>


On Mon, 21 Jan 2008, Sobari Tanuwijaya wrote:

> Yes.
>
> I plan to use centos as the OS on the gateway server.
>
>
> Barry Brimer wrote:
>> 
>> 
>> On Sun, 20 Jan 2008, Sobari Tanuwijaya wrote:
>> 
>>> Here is what I want to do:
>>> I installed a database server on centos, it has a private IP,
>>> the database server run on a certain port (for e.g. port 5555)
>>> 
>>> From other place connected to the internet I try to do some kind of sync
>>> to the database server, so I think I have to set the port mapper in the 
>>> gateway to pass the access to port 5555 to the centos server.
>>> 
>>> 
>> So you're trying to determine what you need to do to forward connections 
>> from your system to port 5555 on the remote system via your gateway it 
>> seems.  What is your gateway running?  Is it running CentOS?

I would use something like:

iptables -t nat -I PREROUTING -d <public ip address of server> -p tcp 
--dport 5555 -j DNAT --to <private IP address of database server>

If you are not already masquerading traffic out, this should handle that.
"iptables -t nat -A POSTROUTING -s <internal network/mask> -j MASQUERADE"


Once you see that work, you can do a "service iptables save" to save the 
configuration and "chkconfig iptables on" to make sure it starts on boot.

Barry