I have one AWS EC2 instance (say 1.1.1.1). I have a random text file in the home directory of that instance.
I also have another instance (say 2.2.2.2), which has the same file in its home directory. (exact replica of first instance)
Now, when I ssh from another instance (say 3.3.3.3) to 1.1.1.1 to read the file, I want 3.3.3.3 to be directed to 2.2.2.2 and read the file from there instead of 1.1.1.1
So, it will be basically like:
3.3.3.3 --> 1.1.1.1 --> 2.2.2.2
So, basically when I want to read the file from 1.1.1.1, I would be reading the text file in 2.2.2.2.
I am not sure how it can be done with IP tables. So, IP tables based solution would also be helpful.
How could I do this? And, obviously I would be running these commands on 1.1.1.1
PS: All these instances are AWS ubuntu VMs
I don't follow your logic, and I am not sure what you are trying to achieve. All I can think is that maybe you have someone who only has access to server 2.2.2.2, but you don't want anyone from 3.3.3.3 accessing 2.2.2.2 directly.
If that's the case the all I can suggest is setting up rsync so that the file is synced between server 1.1.1.1 and 2.2.2.2.
On server 1.1.1.1
sudo apt-get install ssh rsync
The assuming the file is /home/ubuntu/file.txt on both servers:
rsync ubuntu@2.2.2.2:/home/ubuntu/file.txt home/ubuntu/file.txt
Note that you would have to run this every time you want to sync, it doesn't constantly sync the files.
If this is in line with what you want then I can assist with a cron job that would sync the file on a schedule. This also assumes that no changes will be made on the file on server 1.1.1.1 and all changes are made on 2.2.2.2
Your question is not good in that you aren't telling us what problem you're trying to solve - you're just asking how to implement your solution - so the answer may not be what you're looking for.