Confused about subnet routing

Hello,
I am confused about the correct way to manage routing between 2 subnets behind a firewall.

Here is a network diagram:

The outside computer gets a DHCP provided address from the outside router and works as normal.
The inside computer gets a 192.168.2.XX address from the openwrt router and only can connect if I have IP masquerading on in the firewall rules. I would like to be able to use non-masquerade connections between the inside => outside as well as outside => inside.

here is my network file:

config interface 'loopback'
	option device 'lo'
	option proto 'static'
	option ipaddr '127.0.0.1'
	option netmask '255.0.0.0'

config globals 'globals'
	option ula_prefix 'fdfd:84f4:5814::/48'

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

config device
	option name 'eth0'
	option macaddr '22:4e:7f:82:5d:03'

config interface 'lan'
	option device 'br-lan'
	option proto 'static'
	option netmask '255.255.255.0'
	option ip6assign '60'
	option ipaddr '192.168.2.1'

config switch
	option name 'switch0'
	option reset '1'
	option enable_vlan '1'
	option blinkrate '2'

config switch_vlan
	option device 'switch0'
	option vlan '1'
	option ports '0 1 2 3 5'

config switch_port
	option device 'switch0'
	option port '1'
	option led '6'

config switch_port
	option device 'switch0'
	option port '2'
	option led '9'

config switch_port
	option device 'switch0'
	option port '5'
	option led '2'

config interface 'wan'
	option device 'wlan1'
	option proto 'static'
	option ipaddr '192.168.0.25'
	option netmask '255.255.255.0'
	option gateway '192.168.0.1'

Here is my firewall file:



config defaults
	option input 'ACCEPT'
	option output 'ACCEPT'
	option synflood_protect '1'
	option forward 'ACCEPT'

config zone
	option name 'wan'
	option input 'ACCEPT'
	option output 'ACCEPT'
	option forward 'ACCEPT'
	list network 'wan'
	option masq '1'

config zone
	option name 'lan'
	option input 'ACCEPT'
	option output 'ACCEPT'
	option forward 'ACCEPT'
	list network 'lan'

config forwarding
	option src 'lan'
	option dest 'wan'

config forwarding
	option src 'wan'
	option dest 'lan'

Thanks for looking.

Do you really need two subnets?

1 Like

They have to be different subnets if the 5 GHz link is a regular AP-STA connection (not WDS).

For it to work without NAT, "Outside Router" needs a route to the 192.168.2.0 "inside" LAN. Install a static route in Outside Router: 192.168.2.0/24 via 192.168.0.25. If that router is not running OpenWrt, stock or other firmwares usually also support installing routes.

It's also a good idea to set up a DHCP reservation so that "Inside Router" always has the same IP on Outside's LAN. Routes are defined by IP address not name.

The default OpenWrt firewall allows lan->wan forwarding. You will need to add wan->lan if you want the Outside PC to be able to reach Inside machines. wan->lan forwarding will not work with NAT enabled on wan.

1 Like

A couple of clarifications....

The config I uploaded is currently working, but if I take out option masq '1' in wan zone of the firewall config, it doesn't work. My question is why?

I have a static route on the outside router to point to the inside lan. The inside router mac has a static reservation on the outside router.

The openwrt inside router is an old netgear wndrmacv2 with the wireless configured as a client to the outside router, and that is why there has to be a subnet for the inside router/computers. Everything would be simpler if I could make that bridge transparent.

Thank you,
Henry

Because the outside router receiver traffic with IP addresses from the inside network, and it is not configured to handle it.

Adding to what @eduperez said...

When masquerading is enabled, the router 'masquerades' all of the devices behind the router such that the traffic to appear as if it is a single device on connected to the upstream network. This is why you only need a single IPv4 address for your entire home network to be connected to the internet. Regardless if you have one device or many, the router will sort all the traffic accordingly, but the ISP/upstream network only knows about the one address (usually assigned to the wan), so it doesn't need any details about what's behind that address.

If you turn off masqureading, the actual address of the devices behind the router is reported as the source (and eventually destination for the response traffic). The problem arises when the response traffic comes into the upstream router -- if the router doesn't know how to get that traffic back to the requester, it can only drop the packets. So... when the outside router gets traffic that is destined for the network of the inside router, it has no idea how to send it there. A static route is required to say "here's the gateway for that address" -- in your case...

The 192.168.0.25 is the device on the network that the outer router is responsbile for and it serves as the gateway (or pathway) to send traffic to 192.168.2.0/24.

If this route isn't installed on the main router, you must use masquerading on the second router.

1 Like

Still not working the way I expect.
I already had a static route set on the outside router

When I log in to the openwrt router:
I can ping the inside subnet (good, that is the subnet the router is responsible for, the router is at .2.1 ).
I can ping the outside subnet (good, the router is connected to that as .0.25 )
I can ping the internet (good, connection thru the outside router is working)

Here's where it gets weird;
From a computer on the inside subnet
I can ping the inside router at 192.168.2.1
I can ping the inside router at 192.168.0.25
I can ping the outside router at 192.168.0.1
Cannot ping my pi-hole raspberry pi at 192.168.0.3
Cannot ping anything on the internet

As soon as I enable masq in the firewall, everything works normally.

Also pinging from computer on outside subnet to computer on inside subnet does not work reliably.
(might work, first ping shows redirect from the .0.1 router to the .0.25 gateway then pings work, a few seconds later pings dont show the redirect and fail.)
I think that might be an issue with the outside router though.

Then use relayd or mesh, problem solved.

1 Like

Has your config changed since the first post? If so, please post the complete config (wireless, firewall, network, dhcp).

EDIT: Please post all 4 files anyway, regardless if there have been any changes. This way we have the complete picture.

Since the first config I posted, I believe the changes are adding inbound/outbound static routes in network.

dhcpd

config interface 'loopback'
	option device 'lo'
	option proto 'static'
	option ipaddr '127.0.0.1'
	list network 'wwan'
	list network 'wwan2'
	option masq '1'

config zone
	option name 'lan'
	option input 'ACCEPT'
	option output 'ACCEPT'
	option forward 'ACCEPT'
	list network 'lan'

config dnsmasq
	option domainneeded '1'
	option localise_queries '1'
	option rebind_protection '1'
	option rebind_localhost '1'
	option local '/lan/'
	option domain 'lan'
	option expandhosts '1'
	option authoritative '1'
	option readethers '1'
	option leasefile '/tmp/dhcp.leases'
	option resolvfile '/tmp/resolv.conf.d/resolv.conf.auto'
	option localservice '1'
	option ednspacket_max '1232'

config dhcp 'lan'
	option interface 'lan'
	option start '100'
	option limit '150'
	option leasetime '12h'
	option dhcpv4 'server'
	option dhcpv6 'server'
	option ra 'server'
	list ra_flags 'managed-config'
	list ra_flags 'other-config'

config odhcpd 'odhcpd'
	option maindhcp '0'
	option leasefile '/tmp/hosts/odhcpd'
	option leasetrigger '/usr/sbin/odhcpd-update'
	option loglevel '4'

Network

config interface 'loopback'
	option device 'lo'
	option proto 'static'
	option ipaddr '127.0.0.1'
	list network 'wwan'
	list network 'wwan2'
	option masq '1'

config zone
	option name 'lan'
	option input 'ACCEPT'
	option output 'ACCEPT'
	option forward 'ACCEPT'
	list network 'lan'

	option reset '1'
	option enable_vlan '1'
	option blinkrate '2'

config switch_vlan
	option device 'switch0'
	option vlan '1'
	option ports '0 1 2 3 5'

config switch_port
	option device 'switch0'
	option port '1'
	option led '6'

config switch_port
	option device 'switch0'
	option port '2'
	option led '9'

config switch_port
	option device 'switch0'
	option port '5'
	option led '2'

config device
	option name 'wlan0'

config interface 'wwan2'
	option proto 'dhcp'

config interface 'wwan'
	option proto 'dhcp'

config route
	option target '192.168.0.0/24'
	option gateway '192.168.2.1'

config route
	option target '192.168.2.0/24'
	option gateway '192.168.2.1'

Firewall


config defaults
	option input 'ACCEPT'
	option output 'ACCEPT'
	option synflood_protect '1'
	option forward 'ACCEPT'

config zone
	option name 'wan'
	option input 'ACCEPT'
	option output 'ACCEPT'
	option forward 'ACCEPT'
	list network 'wwan'
	list network 'wwan2'
	option masq '1'

config zone
	option name 'lan'
	option input 'ACCEPT'
	option output 'ACCEPT'
	option forward 'ACCEPT'
	list network 'lan'

config forwarding
	option src 'lan'
	option dest 'wan'

config forwarding
	option src 'wan'
	option dest 'lan'

Wireless


config wifi-device 'radio0'
	option type 'mac80211'
	option path 'pci0000:00/0000:00:11.0'
	option band '2g'
	option htmode 'HT20'
	option country 'US'
	option cell_density '0'
	option distance '100'
	option channel 'auto'

config wifi-device 'radio1'
	option type 'mac80211'
	option path 'pci0000:00/0000:00:12.0'
	option band '5g'
	option country 'US'
	option cell_density '0'
	option distance '100'
	option htmode 'HT40'
	option txpower '20'
	option channel 'auto'

config wifi-iface 'wifinet1'
	option device 'radio0'
	option mode 'sta'
	option network 'wwan2'
	option ssid 'HandE'
	option encryption 'sae'
	option key 'passwordgoesboo'

config wifi-iface 'wifinet3'
	option device 'radio1'
	option mode 'sta'
	option network 'wwan'
	option encryption 'sae'
	option key 'passwordgoesboo'
	option ieee80211w '1'
	option ssid 'HandE-5g'

Huh, Relayd looks like exactly what I want. Thank you.
Will try that.

This is a completely jumbled and confusing set of configs... there are things in each file that don't belong there whatsoever. I'm not sure how this ended up as it appears now, but it's not going to work... further, it is going to be more difficult to fix it than it will be to start from scratch. Please reset to defaults and we'll start over.

relayd is what you want if you actually want all of your devices to be on the same subnet. If you're trying to setup multiple subnets and route between them as an intentional network topology, you want to operate in a normal routed mode.

Either way, you need to reset your router to defaults because the current state of your configs will be quite difficult to fix. You'll want to start with a clean slate and adjust based on the method you choose (relayd vs routed).

1 Like

I just started following the excellent directions on

Took less than 10 min.
Everything is working perfectly. Separate subnets was a thing I was doing because I didn't know about relayd.

Thank you all for your help. lets mark this solved.
Henry :grinning:

1 Like

How do you reset to defaults when you get as deep in the mud as I did?

in an ssh session:

firstboot -y && reboot

or, in LuCI, there is a reset to defaults option on the firmware upgrade page.

got it. Resetting and going with relayd again.

In general terms, what was such a hot mess in the configs?

Quite literally, everything. For example, I'm not sure how an interface definition and a firewall zone ended up in the dhcp file. Then your network file had a messed up loopback and a lan firewall zone defined in there. Switch port stanzas that don't belong there and routes that were unnecessary. Your firewall file was also clearly gutted... there were just so many things in the wrong places that it wouldn't make sense to try to fix it.. resetting was the best way to go.

Thank you for all your advice. Reset to defaults , followed the directions in the relayd setup.
All working great.

once again, thanks!

1 Like

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