0

I have a server in LAN (192.168.1.0/24) with static IP address 192.168.1.100, now I would like all service on this server to be accessible using 192.168.100.100 for hosts in the same LAN(192.168.1.0/24), eg. when trying to access 192.168.100.100:1234, the request is handled by 192.168.1.100:1234. How can I achieve this?

I've tried modifying the ARP arp -s 192.168.100.100 m:ac:of:se:rv:er on the router but no luck.

I also tried applying the iptables to the router: iptables -t nat -A PREROUTING -d 192.168.100.100 -j DNAT --to-destination 192.168.1.100. Pinging server results in a timeout.

Background: I used to host file and media service on 192.168.100.100 in LAN 192.168.100.0/24, now I'm migrating the hosts to another LAN 192.168.1.0/24 temporarily. The client uses 192.168.100.100 to reach the server and it will be too much work modifying all applications on the clients. It is obvious that using the hostname rather than IP address is better, but in my situation, the clients use localhost DNS, ignoring the router's DNS. I only know little about IP.

2 Answers 2

0

The question is if the hosts which need to access 192.168.100.100 are on the 192.168.1.0/24 or somewhere else. If the latter then the rule which you added on the router (assuming it gets the traffic destined for 192.168.100.100) should be sufficient (of course you also need to enable forwarding but I assume this is obvious for the router).

If these are the hosts from 192.168.1.0/24 network trying to go to the 192.168.100.100 then it is a bit more complicated. They will send the request with source address of 192.168.1.x to destination 192.168.100.100 to the router which will do the DNAT and will send the packets to 192.168.1.100, back on the same network segment. The problem is that the response will have the source ip of 192.168.1.100 and destination ip of 192.168.1.x and will not pass back through the router to have effects of DNAT reverted. The packet received by originating host WILL NOT match any known connection and will be dropped. To work around this you additionally need to have SNAT on the packets which are routed back to this network segment:

iptables -t nat -A POSTROUTING -s 192.168.1.0/24 --ctstate DNAT -j SNAT --to-source 192.168.1.r

where 192.168.1.r is the ROUTER's ip address on the 192.168.1.0/24 subnet.

1
  • Thanks a lot, I finally got this work after adding this iptables -t nat -I POSTROUTING -s 192.168.1.0/24 -d 192.168.1.100 -m conntrack --ctstate DNAT -j SNAT --to-source 192.168.1.1. My OpenWrt router failed to SNAT and it took me the whole day to figure it out. In the end, a firmware update saved me. Jul 7, 2018 at 10:47
0

This is the reason you need to use DNS from the start.

The only solution here I see is that you add have a router between 192.168.1.0/24 and 192.168.100.0/24 networks. Then you specify on the hosts on 192.168.1.0/24 network that they need to send packets to 192.168.100.100/24 via the router, and vice versa.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .