Routing between interfaces

I have installed dnsmasq and hostapd on a PC with the idea of using the PC as an Access Point.

eth0 uses DHCP from my Internet Gateway, and gets an IP of 192.168.1.20, and wlan0 has a static IP address of 192.168.2.1. How do I route wifi clients to the 192.168.1.0 network?
 
With your /etc/rc.conf settings.
gateway_enable="YES"
defaultrouter="192.168.1.1"

If your routes get screwed up while experimenting you can route flush.

Also /etc/resolv.conf points to the nameserver.(This should work automatically)

I use pf for NAT.(This needs settings in /etc/pf.conf)

The range of IP addresses used are set in the /usr/local/etc/dnsmasq/dnsmasq.conf
For example:
dhcp-range=set:wlan0,192.168.2.10,192.168.2.25,255.255.255.0,24h
This uses a range of 192.168.2.10 to address 192.168.2.25 for assignment to clients of Wlan0.
The lease will expire in 24h and renew.
dhcp-option=wlan0,option:router,192.168.2.1
This line is important because it defines the IP of your wlan0 and its function as a router interface.
 
Thanks for the help, but I haven't managed to set things up properly yet. My phone connects to the server but does not gain internet access, so I guess that's a routing problem.

One thing I see in the boot log is:-

wlan0: ieee80211_new_state_locked: pending INIT -> SCAN transition lost

Don't know if that is significant.

I don't see any logs for dnsmasq or hostapd, although an IP assignment is made to wlan0 on another laptop so it's partly working.
 
Logging for dnsmasq: /usr/local/etc/dnsmasq/dnsmasq.conf
log-queries
log-facility=/var/log/dnsmasq.log

Logging as described in /etc/hostapd.conf
# hostapd event logger configuration
#
# Two output method: syslog and stdout (only usable if not forking to
# background).
#
# Module bitfield (ORed bitfield of modules that will be logged; -1 = all
# modules):
# bit 0 (1) = IEEE 802.11
# bit 1 (2) = IEEE 802.1X
# bit 2 (4) = RADIUS
# bit 3 (8) = WPA
# bit 4 (16) = driver interface
# bit 5 (32) = IAPP
# bit 6 (64) = MLME
#
# Levels (minimum value for logged events):
# 0 = verbose debugging
# 1 = debugging
# 2 = informational messages
# 3 = notification
# 4 = warning
#
logger_syslog=-1
logger_syslog_level=2
logger_stdout=-1
logger_stdout_level=2
 
It still isn't working. AFAICT both hostapd and dnsmasq are performing their functions correctly, ie hostapd establishes a wifi connection, and dnsmasq assigns as IP address, but I can't tell what takes care of the routing between the two interface or how to monitor what takes place.

I did notice in https://www.iceflatline.com/2010/02/how-to-install-and-configure-dnsmasq/ that it mentions
Code:
By default dnsmasq assumes that host running dnsmasq is your gateway/router. That wasn’t the case in my network so I needed to specify the IP address of my Cisco gateway/router in the following line:

dhcp-option=3,192.168.10.1

so I addedd
dhcp-option=3,192.168.1.1

to /usr/local/etc/dnsmasq.conf but that still didn't work.

root@Server:/var/log# netstat -4nr shows:-
Routing tables Internet: Destination Gateway Flags Netif Expire default 192.168.1.1 UGS re0 127.0.0.1 lo0 UHS lo0 192.168.1.0/24 link#1 U re0 192.168.1.20 link#1 UHS lo0 192.168.2.0/24 link#3 U wlan0 192.168.2.1 link#3 UHS lo0

Any further advice would be appreciated.
 
What exactly happens when you try and connect to your AP from a client? Does it connect and get an IP?

I am on unavailable most of this week. Hang in there.

ps: Make sure you do not have /etc/wpasupplicant.conf on the AP. It is only used on clients
 
so I addedd dhcp-option=3,192.168.1.1

Since your DHCP server is used for the wireless network and your default gateway should be a part of that network, the option should specify the IP address of your server, i.e. 192.168.2.1. But since your DHCP server and router (server) are both the same machine, this does not apply to your setup.
 
The situation is:-

192.168.1.1 Internet Gateway/DHCP server

192.168.1.20 FreeBSD server eth0 - IP via DHCP
192.168.2.1 FreeBSD server wlan0 IP static

192.168.1.94 client eth0 IP via DHCP from gateway
192.168.2.62 cllient wlan0 IP via DNSMASQ on FreeBSD server

What I can't figure out is how to route between 192.168.2.1 and 192.168.1.1 . I presume the routing is configured in /usr/local/etc/dnsmasq.conf via one or both of:

Code:
# Override the default route supplied by dnsmasq, which assumes the
# router is the same machine as the one running dnsmasq.
#dhcp-option=3,1.2.3.4

# Do the same thing, but using the option name
#dhcp-option=option:router,1.2.3.4

but not sure how they should be setup.
 
Routing is done by the host. Just enabling gateway_enable is enough for packets to travel from one interface to another. The rest is just a matter of having the correct routes everywhere.

Your internet router at 192.168.1.1 will need a static route for 192.168.2.0/24, it has to be told it can find that network behind your FreeBSD router. Your client at 192.168.1.94 will need the same static route.
 
If I understand things right, 192.168.1.1 is your pfSense box. Your wireless AP box gets an ip of 192.168.1.20 from pfSense.
You are running a subnet'ed range of 192.168.2.1 on your wifi interface.

So your dhcp option setting is wrong as tommiie mentioned.
That is your upstream pfSense IP correct?.
You need your AP interface IP there, just like I wrote above:
dhcp-option=wlan0,option:router,192.168.2.1
Not 192.168.1.1. That is assigned to an interface on another machine, Right?
 
192.168.2.62 cllient wlan0 IP via DNSMASQ on FreeBSD server
OK so the client is picking up an IP from your AP. That eliminates some problems.

Does the client seem to be showing a constant wireless channel is or is swapping around?
You need to run ifconfig wlan0 repeatedly over and over to notice this.
What channel is it using?

Why not post ifconfig wlan0 from both AP and a Client.
 
Back
Top