Answer the question
In order to leave comments, you need to log in
Iptables and ip spoofing?
Good day, Habr!
No one will tell you how to implement ip substitution using iptables? And then I set the binding by ip and now I need to somehow solve the problem.
The essence of the task is this: there is a router and a computer behind the router, you need to connect to it from outside so that the computer on the other side of the router thinks that the connection came from the local ip. My computer is not connected to the router in any way, access to the router is only remote.
Answer the question
In order to leave comments, you need to log in
Well, I managed to do this. I'm telling.
Let's say we have a LAN that gets Internet access through a router.
The router has two interfaces:
192.168.1.0/24 dev eth1 src 192.168.1.1 192.0.2.0/24 dev eth0 src 192.0.2.55 default via 192.0.2.1
iptables -t nat -A POSTROUTING -s 192.168.1.0/24 -o eth0 -j MASQUERADE
iptables -t nat -A POSTROUTING -s 192.168.1.0/24 -o eth0 -j SNAT --to-source 192.0.2.55
192.168.1.22/24
192.168.1.0/24 dev eth0 src 192.168.1.22 default via 192.168.1.1
iptables -t nat -A PREROUTING -s 192.0.2.66 -i eth0 -j DNAT --to-destination 192.168.1.22
iptables -t filter -A FORWARD -s 192.0.2.66 -d 192.168.1.22 -j ACCEPT
iptables -t nat -A POSTROUTING -s 192.0.2.66 -j SNAT --to-source 192.168.1.77
ip addr add 192.168.1.77/24 dev eth1
ip route add 192.168.1.77 via 192.168.1.1
Let's say that the router has 2 interfaces of the following form:
eth0 - Internet, has the address **** / 24 - it doesn't matter
eth1 - local, has the address 192.168.1.1/24
The remote computer has the address 1.2.3.4 The
local computer has the address 192.168.1.22
Local the virtual computer has the address 192.168.1.77
First, you need to add an additional address to eth1, which will serve the router:
ip addr add 192.168.1.77/24 dev eth1
or
ifconfig eth1 add 192.168.1.77
Routing from remote to local:
iptables -t nat -A PREROUTING -s 1.2.3.4 -i eth0 -j DNAT --to-destination 192.168.1.22
iptables -t filter -A FORWARD -s 1.2.3.4 -d 192.168.1.22 -j ACCEPT
iptables -t nat -A POSTROUTING -s 1.2.3.4 -j SNAT --to-source 192.168.1.77
Routing to remote from local:
iptables -t nat -A PREROUTING -d 192.168.1.77 -i eth1 -j DNAT --to-destination 1.2.3.4
iptables -t filter -A FORWARD -d 1.2.3.4 -s 192.168.1.22 -j ACCEPT
POSTROUTING - not needed, because there is already NAT configured by the router itself
IMHO, it should so work. If anything - write what errors, we will understand.
As far as I know, this is done by the SNAT (source NAT) function in the prerouting chain of the nat table
Possibly like this:
-A POSTROUTING -d router_IP/32 -j SNAT --to-source REQUIRED_IP
Do you have Linux on your router or just a piece of iron with a web interface?
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question