Ubuntu: Fake ip address

2

1

I have a software package which is hard-coded to open a connection to a certain local IP address. Unfortunately, the local network settings have changed, And I can't access the source code (long story).

Is there a way - like ssh tunneling - to redirect a certain ip address to another?

For example, my software would contact 192.168.1.100, which will be redirected to 192.168.1.15, a real address on another machine, in a transparent way.

Any Ideas?

Adam Matan

Posted 2009-10-05T14:30:03.197

Reputation: 5 930

Answers

4

A colleague of mine introduced me to iptables:

iptables -t nat -A OUTPUT -d 192.168.1.100 -j DNAT --to-destination 192.168.1.15

Adam Matan

Posted 2009-10-05T14:30:03.197

Reputation: 5 930

1

Add a static route for the server IP to the server's real IP on the client. Add the server IP address as a subinterface on the server.

server# ifconfig eth0:1 192.168.1.100

client# route add -host 192.168.1.100 gw 192.168.1.15

wfaulk

Posted 2009-10-05T14:30:03.197

Reputation: 5 692

0

Add the server IP as a subinterface on the server. Add another IP in that network to the client machine as a subinterface.

This assumes they are currently on the same network.

server# ifconfig eth0:1 192.168.1.100

client# ifconfig eth0:1 192.168.1.101

wfaulk

Posted 2009-10-05T14:30:03.197

Reputation: 5 692

0

I think that's the way to go:

sudo ip addr add 192.168.1.100 dev eth0

That simply adds an IP address to eth0

Johannes Weiss

Posted 2009-10-05T14:30:03.197

Reputation: 1 362

in which machine? – Adam Matan – 2009-10-06T06:45:54.957

@Udi, good question: if one could assign the target machine that extra IP address (if not used elsewhere to start with) then I guess this would be the same as reverting back to the old local network settings, which I assume does not work for you. In other words: I don't think you can use this (unless you actually need 192.168.1.100 to refer to localhost, which you don't). – Arjan – 2009-10-06T12:47:26.343