Configuring global routing

There is a global IPv4 address a.b.c.0/24 and I am assigned a part of them. I am also assigned IPv4 addresses a.b.d.e, to which all packets destined to IP addresses a.b.c.x - a.b.c.y will be forwarded. It means that IP address a.b.d.e is the next hop for IP addresses a.b.c.x - a.b.c.y.

Now, I am trying to build two routers using OpenWrt:

  • The first router has IP address a.b.d.e and forwards all packets destined to IP address a.b.c.x to the second.
  • The second router has a.b.c.x and allows the computers under it to communicate with the outside world through these routers.

How should I configure the first router as the next hop for IP addresses a.b.c.x?

I have tried changing various settings for static routes and firewalls, but through trial and error, I have encountered the following problem:

  • The packets would come back to this router again and loop.
  • When I accessed a.b.d.e from the outside with a browser, I would see LuCI.
  • The first router was not seen in the results of traceroute from outside to a.b.c.x.

Current configure of the first router is following:

config interface 'lan'
        option device 'br-lan'
        option proto 'static'
        option force_link '0'
        option delegate '0'
        list ipaddr 'a.b.c.1/24'

config device
        option type 'bridge'
        option name 'br-lan'
        list ports 'eth2'

config interface 'wan'
        option proto 'dhcp'  ## dhcp will offer a.b.d.e
        option delegate '0'
        option device 'eth1.240'

config device
        option name 'eth1.240'
        option type '8021q'
        option ifname 'eth1'
        option vid '240'
        option ipv6 '0'
        option promisc '1'

config route  ## this rule do not appear on route / ip route command
        option interface 'lan'
        option target 'a.b.c.0'
        option netmask '255.255.255.0'
        option gateway 'a.b.c.x'
        option onlink '1'
        option table 'main'

With the route:

Can you show the route you made?

???

If this is the route, "onlink" is invalid for plain Ethernet.

1 Like

Thanks for replying!

config route
        option interface 'lan'
        option target 'a.b.c.0'
        option netmask '255.255.255.0'
        option gateway 'a.b.c.x'
        option table 'main'

I added this config, but I don't see the route on a result of route or ip route command.

As you say, it seems like that onlink should be '0'.

It won't show, because you have the same network directly connected on lan interface.

1 Like

A rule like this won't work (or isn't necessary):

because a.b.c.x is already on a.b.c.0/24.

--> if the system already knows how to reach a.b.c.x, it can already reach all of a.b.c.0/24. Conversely, if it doesn't know how to reach a.b.c.0/24, it also doesn't know how to reach a.b.c.x.

A route needs to be defined as:

  • a network that the router doesn't already know about
  • using a gateway that the router does already know how to reach.

So, for example, if I have two cascaded routers:

  • Router A has a LAN of 10.0.50.0/24
  • Router B has a LAN of 172.16.30.0/24, and has an upstream connection to router A with address 10.0.50.32

In order for router A to know how to reach hosts on 172.16.30.0/24, I need to provide a route that looks like this:
172.16.30.0/24 via 10.0.50.32

Or in the config file formatting:

config route
        option interface 'lan'
        option target '172.16.30.0'
        option netmask '255.255.255.0'
        option gateway '10.0.50.32'
        option table 'main'
2 Likes

Since IP address a.b.c.x is just like the one in the lan network, the router already knows the route to a.b.c.x, so there was no need to write the route again.
All that was needed was to allow the forwarding of packets to a.b.c.x coming from a.b.d.e by a traffic rule.

Thanks

This topic was automatically closed 10 days after the last reply. New replies are no longer allowed.