Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

I'm aware of other questions with the same topic, but I couldn't get it to work.

I'd like to forward inside my local network all traffic from ip1 to ip2. Only from inside the network, no outside.

I have a router with OpenWRT and I'd like to add an iptables inside the router. I'd like this forwarding being visible from any of the devices connected to my local network.

That means that from my computer (connected via wifi to the openwrt router) if I open a browser and type: 192.168.1.42, it is redirected to 192.168.1.198. Both on port 80 and 3000 (and eventually others)

If I open 192.168.1.198 I see my little http server.

I tried various combination of iptables via ssh to the OpenWRT router:

iptables -t nat -A PREROUTING -p tcp -d 192.168.1.42 -j DNAT --to-destination 192.168.1.198
iptables -t nat -A OUTPUT -p tcp -d 192.168.1.42 -j DNAT --to-destination 192.168.1.198

Nothing is working. In particular.. where can I see the logs?

EDIT:

I've also done it from the web panel luck in the OpenWRT. Seems correct to me: enter image description here

Of course there is nothing at 192.168.1.42 (I meant it as a virtual fixed ip)

share|improve this question
    
Why is it not an option to use 192.168.1.198 in any place that you would otherwise use 192.168.1.42? –  Robbie Mckennie Jun 17 at 12:49
    
192.168.1.198 is actually dynamic: from DHCP. 192.168.1.42 should a static IP. So that: each time the embedded system that now is at 192.168.1.198 is on sends a message to the router and the router set the iptable to redirect. This is a workaround because I haven't managed to set the embedded device with a static ip... –  nkint Jun 17 at 12:52
1  
It seems to me that it would be a lot easier to give 192.168.1.198 a static ip that to redirect traffic to a dynamic ip. I'm no expert on OpenWRT, but I know that this is trivial to do in a more generic set up by editing dhcpd.conf –  Robbie Mckennie Jun 17 at 12:57
    
how to do it? I mean: I need to have a static ip for a specific MAC address without touching the embedded device.. –  nkint Jun 17 at 13:03
    
I don't know how to do it under OpenWRT, but this page has a section for static ip allocation: wiki.openwrt.org/doc/uci/dhcp. I'd refer you to that. –  Robbie Mckennie Jun 17 at 13:16

1 Answer 1

As you described it, this can't be done with iptables from your router. iptables only operates on packets being routed through your router (good name, huh?). Packets that going between 2 hosts on the same physical network have all their routing down by hosts themselves; no need for going through your router.

If 192.168.1.42 doesn't actually exist, you could potentially give 192.168.1.198 a second 'alias' ip address. Or even give some third machine the alias ip, and forward traffic from it to 192.168.1.198.

share|improve this answer
    
I need to do it for all devices connected to my local network (see the edits) –  nkint Jun 17 at 12:37
1  
@nkint What OS is 192.168.1.198 running? –  Robbie Mckennie Jun 17 at 12:40
    
alias seems nice: so the machine that is at 192.168.1.198 has actually 2 ip: 192.168.1.198 (the real one) and 192.168.1.42 (the aliased one). How to do it? –  nkint Jun 17 at 12:40
    
another openWRT inside an embedded device BUT I don't want to touch it (I tried to do it but I made some messy works and nothing was working so I'd like to do it on the router side only. Much more safe) –  nkint Jun 17 at 12:42
    
@nkint The only way to give a host an alias to to change the configuration on that host itself –  Robbie Mckennie Jun 17 at 12:43

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.