Hello Everybody,
I have a Linux on PC as gateway (lets call it GW). GW has 3 interfaces. 2 of
them (ETH0, ETH1) have 2 different public IP adresses (IP_0, IP_1) and are
conneted via my ISP to the Internet. Third interface (ETH2) is a local
interface with not public IP (IP_2). In the local network there is a
computer (SERVER) with local IP(IP_S). Lets call this configuration Company.
I would like to connect to Company SERVER from home computer (IP_H), so I
redirected all traffic from my home computer to the SERVER:
/sbin/iptables -A INPUT -s IPH -d IP_0 -i eth0 -j ACCEPT
/sbin/iptables -t nat -A PREROUTING -t nat -s IPH -d IP_0 -j DNAT --to IP_S
/sbin/iptables -A INPUT -s IPH -d IP_1 -i eth1 -j ACCEPT
/sbin/iptables -t nat -A PREROUTING -t nat -s IPH -d IP_1 -j DNAT --to IP_S
I also have two routing tables with two default gateways on GW. If I ping
IP_0 from the Internet (not home computer) i have response from IP_0 and if
I ping IP_1 I have response from IP_1.
I understand that if I want my connection from HOME to SERVER works I have
to configure NAT for SERVER.
How do I have to configure this NAT???
I tried:
/sbin/iptables -t nat -A POSTROUTING -s IP_S -d 0.0.0.0/0 -o eth0 -j
MASQUERADE
/sbin/iptables -t nat -A POSTROUTING -s IP_S -d 0.0.0.0/0 -o eth1 -j
MASQUERADE
but it wont work.
If I leave MASQUARADE only on eth0 interface, then I can connect from home
to SERVER but only via IP_0. If i try to connect via IP_1, my packets going
to SERVER via IP_1 but returning via IP_0.
Please help me. I would like to choose if I connect from my home computer to
SERVER via IP_0 or IP_1.
Regards
Tomek
|