mattlongman / Hassio-Access-Point

Hass.io addon to let you create a WiFi access point, perfect for using WiFi devices on off-grid installations.
MIT License
91 stars 64 forks source link

[Feature Request] Route traffic from wlan0 to eth0 #5

Closed luispedro18 closed 2 years ago

luispedro18 commented 3 years ago

It would be cool if the traffic coming in from wlan could go out through eth0 so the devices connected could have internet

alameda3piso03 commented 3 years ago

It would be cool if the traffic coming in from wlan could go out through eth0 so the devices connected could have internet

I have the same problem too. Is it possible to route the Wi-Fi network traffic to the ethernet network gateway? In other words, the devices connected to the access point have access to the internet through the ethernet. Thanks in advance

mattlongman commented 3 years ago

Hi @luispedro18 - apologies for not looking at this sooner (thanks to @alameda3piso03 for bumping it).

I think I've got this working, but could do with help in properly testing it to make sure it's stable.

I've just pushed a version to the dev branch (https://github.com/mattlongman/Hassio-Access-Point/tree/dev/hassio-access-point). Please download and test it out.

New config options:

Internet access for clients can be enabled with client_internet_access: '1'. If DHCP is also enabled, Hassio-Access-Point will try to get the parent host's DNS servers (not just container DNS servers), and serve to clients as part of the DHCP config. This can be overridden with e.g. client_dns_override: ['1.1.1.1', '8.8.8.8']. If DHCP is not enabled, client_internet_access: '1' will still work, but DNS server(s) will need to be set manually as with the rest of the IP config.

Please update this issue either way, and if it's good, I'll move it to the main branch.

luispedro18 commented 3 years ago

Hi @mattlongman !! First of all, thank you for making the time to address this.. Unfortunately I've changed my setup and I no longer need this... Best to be @alameda3piso03 testing this one...

Again, thank you for doing this 🙌

mattlongman commented 3 years ago

Hi @mattlongman !! First of all, thank you for making the time to address this.. Unfortunately I've changed my setup and I no longer need this... Best to be @alameda3piso03 testing this one...

Again, thank you for doing this 🙌

It's a feature that you might assume it could do by default, so thanks for the raising the issue in the first place.

Do you mind explaining what your use-case was? I'm curious to find out how this gets used as it's obviously a fairly niche add-on!

luispedro18 commented 3 years ago

My use case was: I wanted to route the traffic from a Roku player through a VPN but since it can't be configured on the device I was trying to get it set up in the Pi (where i have HA installed) and then create a new network to have the Roku connected there.. that way the traffic from Roku would be routed through the VPN 😁

pubutil commented 3 years ago

Thank you for working on adding internet access to your add-on!

I tried the dev branch of hassio-access-point and the local network function definitely works as intended. However, with client_internet_access='1' I can't get the AP to provide internet access. DHCP is disabled, but devices are assigned IPs on the 169.254.x.x subnet, instead of grabbing an IP from my router (which is upstream of my Pi, on 192.168.3.x).

I actually had the same thing happen on Raspberry Pi OS, which is why I tried moving to Hass.io: hostapd worked as intended, until I installed the Home Assistant Docker container. After adding the Docker container the client IPs didn't match with my local network and clients all lost internet access.

It's possible I'm doing something wrong, though! Here's my config if it helps (SSID/passphrase removed):

ssid: ssid
wpa_passphrase: passphrase
channel: '11'
address: 192.168.3.139
netmask: 255.255.255.0
broadcast: 192.168.3.254
interface: wlan0
hide_ssid: '0'
dhcp: '0'
dhcp_start_addr: ''
dhcp_end_addr: ''
allow_mac_addresses: []
deny_mac_addresses: []
debug: 0
hostapd_config_override: []
client_internet_access: '1'
client_dns_override:
  - 9.9.9.9
  - 149.112.112.112

Here's the initial part of my log as well (SSID/MAC address removed). I'm not experienced enough to know whether the rfkill and wlan0 errors are significant, seeing as local network access still works as intended:

Starting Hass.io Access Point Addon Configuration file: /hostapd.conf rfkill: Cannot open RFKILL control device wlan0: Could not connect to kernel driver Using interface wlan0 with hwaddr 00:00:00:00:00:00 and ssid "ssid" wlan0: interface state UNINITIALIZED->ENABLED wlan0: AP-ENABLED

Following this were a few associations/disassociations/handshakes that I didn't include.

I hope this helps! Let me know if you need more info/testing from me.

Edit to add: I'm running Home Assistant OS 6.1, supervisor-2021.06.8, and core-2021.7.2 on a Raspberry Pi 4 Model B

mattlongman commented 3 years ago

Hi @pubutil - thanks for testing!

The host network doesn't see each individual device connecting to the Pi, it just sees all requests as coming from the Pi, so responds accordingly, then the Pi sends responses out to the appropriate client.

For your example:

address: 192.168.3.139 netmask: 255.255.255.0 broadcast: 192.168.3.254 dhcp: '0'

You would manually need to set the IP on the client device as DHCP is off, and the client can't request an IP from the parent network/DHCP server (because the parent network just sees the Pi).

Similarly, you would also need to manually set the DNS servers when manually IPing the device.

client_dns_override:

  • 9.9.9.9
  • 149.112.112.112

The client_dns_override option can be used where the Pi is unable to determine DNS servers from the parent network, or you just wanted to use different DNS for clients connected to Hass.io Access Point, but there's no way of setting DNS on a client without DHCP.

Do you need clients to be accessible/visible from the parent network? Could you explain what your use-case is?

One thing I'm going to explore is what's required to configure this as a bridged access point (where clients are visible to the host network, which I think is what you were expecting with this current version) and see if it can be added as an option.

mattlongman commented 3 years ago

Related issue: bridged ap

shageman commented 3 years ago

My use-case is this. This is for a mobile use case (think RV, van, or boat) I intend to have two pis connected via ethernet:

shageman commented 3 years ago

BTW, this config works for me

ssid: SSID
wpa_passphrase: PW
channel: '6'
address: 192.168.99.1
netmask: 255.255.255.0
broadcast: 192.168.99.255
interface: wlan0
hide_ssid: '0'
dhcp: '1'
dhcp_start_addr: 192.168.99.10
dhcp_end_addr: 192.168.99.20
allow_mac_addresses: []
deny_mac_addresses: []
debug: 0
hostapd_config_override: []
client_internet_access: '1'
client_dns_override:
  - 1.1.1.1
teranus commented 2 years ago

Is it still necesary to use the dev branch for internet routing from wlan0 to eth0 or is it now enough tested and in the main branch? I need exactly that function and am just about to implement this addon. As here was no further discussion since over a year, maybe it is implemented already?

mattlongman commented 2 years ago

Is it still necesary to use the dev branch for internet routing from wlan0 to eth0 or is it now enough tested and in the main branch? I need exactly that function and am just about to implement this addon. As here was no further discussion since over a year, maybe it is implemented already?

Not necessary to use dev branch. It was merged here

I'm planning to go through and clear some of these issues soon, but if you have an interest in this addon and could help with maintaining it, please let me know (I don't use it myself at the moment, and don't have the capability to test it currently).

stegno commented 2 years ago

I am also looking for way to do a bridged dumb AP, since its done, AP could be a part of wifi coverage within home (if same SSID and security) with normal roaming between other APs. Now clients have and reinit wifi connection to change IPs and gateways, so data transmitting stops for a much more time..

dingausmwald commented 1 year ago

Sorry to bump this, and thanks for this awesome addon. Little question: All are talking about linking wlan0 to eth0. Is it possible to share the internet connection from a usb wifi dongle to wlan0?

In addition, dont know if related, i get this in logs now and cant set my network config anymore (connection still works)

/network/info return code 500

and

Failed to to call /network/info -

*this messages disappeared again with some restarts and network config is back

** I just saw eth0 is hardcoded, so it seems there is no possibility yet. Would be great if this would be possible.

*** Aaaand we have a winner. One of this forks (from https://github.com/ShoukaSeikyo/Hassio-Access-Point) got this function implemented. Looks pretty simple, maybe you want to add this function too. Works like a charm.

walle2603 commented 1 year ago

Hi, i am really happy about the AP function, it works fine using wlan0 to eth0. Currently I am looking for a solution routing the traffic from wlan0 to wlan1 (external USB Wifi Adapter). Unfortunately it doesen't work. I thing its the same topic like @dingausmwald. Any options to make it work or to add that feature?

Thanks in advanced

dingausmwald commented 1 year ago

This feature request is closed. Anyway, you can use my fork, i implemented the feature there. https://github.com/dingausmwald/Hassio-Access-Point be aware that i had to change ht_capab=[HT40][SHORT-GI-20][DSSS_CCK-40] to ht_capab=[HT40][SHORT-GI-20] in hostapd.conf since my additional wifi usb stick does not support [DSSS_CCK-40] and "hostapd_config_override" option does not seem to work

you can add this by going to your home assistant / addons / add-on store / 3 dots / repositories / and add the github link of my fork there.

My interface (the wifi stick my 20+ tasmota plugs are connected to) is wlp1s0u1u4u3 and my client_internet_access_interface is wlan0, since the wifi from raspi4 cant handle more than 8? connections.

walle2603 commented 1 year ago

@dingausmwald: great that was the feature i was looking for. Thanks a lot!!!