I have a network which has for example the subnet 172.20.1.0/24. On this, I have one embedded device that tries to access http://192.168.1.1, which is hardcoded. Without making physical changes to the network I would like that device to get a response.
What I tried was to add a static route on that device
$ route add -host 192.168.1.1 dev eth0
$ route
Kernel IP routing table
Destination Gateway Genmask Flags Metric Ref Use Iface
172.20.1.0 * 255.255.255.0 U 0 0 0 eth0
192.168.1.1 * 255.255.255.255 UH 0 0 0 eth0
and then configure one PC on the network to additionally have that static IP address. Now, from my device I could ping it, but unfortunately only if I specify the interface explicitly:
ping 192.168.1.1 # doesnt work
ping -I eth0 192.168.1.1 # works
I could also still not access a webserver on that PC. How can I additionally make that IP address accessible without for example introducing a router?
You need to add an IP alias
192.168.1.1/24
to the same interface where172.20.1.0/24
is configured. The kernel will add a directly connected route automatically. Then you need to configure a web server likenginx
,apache
,lightttpd
to be able to server web pages on http://192.168.1.1