0

I have a hostapd running on my raspberry pi 4b on wlan0. I also have installed succesfully a usb wifi adapter. I can have wifi on the pi and send a wifi connection to a laptop or other device. My question is how can i send the wifi from my adapter to my hostapd so i can be on the internet on a other device thru my rpi? If i connect a ethernet cable i can use wifi on other devices, only not with the wifi adapter.

sudo iwconfig:

lo        no wireless extensions.

eth0      no wireless extensions.

wlan0     IEEE 802.11  Mode:Master  Tx-Power=31 dBm   
          Retry short limit:7   RTS thr:off   Fragment thr:off
          Power Management:on
          
wlx3460f902843e  IEEE 802.11AC  ESSID:"bawi_ziggo_5g"  Nickname:"WIFI@RTL88X2BU"
          Mode:Managed  Frequency:5.22 GHz  Access Point: 6C:5A:B0:BF:92:1F   
          Bit Rate:867 Mb/s   Sensitivity:0/0  
          Retry:off   RTS thr:off   Fragment thr:off
          Encryption key:****-****-****-****-****-****-****-****   Security mode:open
          Power Management:off
          Link Quality=70/100  Signal level=46/100  Noise level=0/100
          Rx invalid nwid:0  Rx invalid crypt:0  Rx invalid frag:0
          Tx excessive retries:0  Invalid misc:0   Missed beacon:0

2 Answers 2

0

Try:

sudo sysctl -w net.ipv4.ip_forward=1
sudo iptables -t nat -I POSTROUTING -o wlan0  -j MASQUERADE
sudo iptables -I FORWARD -i wlx3460f902843e -o wlan0 -j ACCEPT
suco iptables -I FORWARD -i wlan0 -o wlx3460f902843e -j ACCEPT  

This presumes that the internet uplink is wlan0. Otherwise switch the interface name in the -t nat -I POSTROUTING command. This will take place immediately but will not persist across a reboot.

You may have to apt install iptables if that is not found.

If this does not work, edit into your question the output from:

sudo iptables --line-numbers -n -v -L 

as it was before you did the above (so you will have to reboot, or else just do it and save it first).

0

Thanks for the answer. It actually already worked when i did this:

sudo sysctl -w net.ipv4.ip_forward=1
sudo iptables -t nat -I POSTROUTING -o wlx3460f902843e -j MASQUERADE

Is there any way to permanently change these setting, so a reboot will not change it?

1
  • Create a script and define a systemd service file for it. Or add those two lines to /etc/rc.local
    – Dougie
    Sep 15, 2022 at 21:08

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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