KB Article #44073

How to translate gateway IP address (NAT)

Problem

How to translate IP address of Gateway


Resolution


For example, a FTP Gateway server in passive mode behind a NAT has to return the public IP address.



The GWHOME/src/exituser/exitftp.c user exit contains the following relevant arrays:


ip4TransTable

ip4LanTable

ip6TransTable

ip6LanTable


Edit the arrays as needed. In the TransTable arrays, the first column is the IP address to match, and if it matches, it will be replaced by the corresponding one in the second column. For example, to translate the private ip address 145.72.141.2 to the public address 85.72.107.30:


static unsigned char ip4TransTable[][2][4] = {
{{145, 72, 141, 2}, {85, 72, 107, 30}},
{{0, 0, 0, 0},{0, 0, 0, 0}}
};


In the LanTable arrays, the pattern is in the first column, and the netmask in the second one:


static unsigned char ip4LanTable[][2][4] = {
{{192, 168, 0, 0}, {255, 255, 0, 0}},
{{ 0, 0, 0}, {0, 0, 0, 0}}
};


Note that the address-translation tables, and most of the ExitFtpRespPasv function, are disabled out of the box (with #if 0/#endif), so be sure to change those to make address translation work.


After making all these changes, recompile the exit.


Note: these functions are used whether the connection is being done directly to Gateway, or through SecureRelay (unless you set up protocol termination in SecureRelay).