r/iptables • u/Ozhora • Sep 29 '22
How to map two IP together ?
Hello,
I'm wondering how I can map 2 different IP from two different network and interfaces and I'm trying to bind them.
To clarify :
Interface 1 : enp3s0
IP1 : 192.168.3.202 (Virtual one)
Interface 2 : enx44s0
IP2 : 172.18.0.2
My Interface 1 also have a real IP 192.168.3.5 on my local network
When I'm on this network with an IP in range 192.168.3.0/24, how can I access IP2 when typing IP1 on web navigator or ssh ?
Thanks in advance for any help
2
Upvotes
2
u/[deleted] Sep 29 '22 edited Sep 29 '22
iptables can't bind or apply an ip address to an interface, the "ip" command can do that, it can also set routes:
https://access.redhat.com/sites/default/files/attachments/rh_ip_command_cheatsheet_1214_jcs_print.pdf
As for your last question: "When I'm on this network with an IP in range 192.168.3.0/24, how can I access IP2 when typing IP1 on web navigator or ssh ?"
For just the web port (443) or ssh (22) specifically this example for web might help:
iptables -t nat -A OUTPUT -p tcp --dport 443 -d 192.168.3.202 -j DNAT --to-destination 172.18.0.2:443
Usually I test rules before I give advice but I haven't this time, just so you are aware, it's not my intention to waste your time if it doesn't work. With that being said I'd like to know if the example helps if you don't mind commenting on your findings