0

I have a question: Is it possible to share the internet connection on WLAN0 (Integrated WiFi module) through a WLAN1 connection like AccessPoint with another adapter (TP-LINK usb) ?

If possible, how do I accomplish this?

In short, I want to connect many devices on WLAN1 connection AP shared like a Sub-Gateway, and then I want to connect only my raspberry on the WLAN0 interface that is connected to the real AP Gateway on internet

0

If your device supports access point mode, it is possible. Just modify the expressions written in ***capitals*** and run these commands:

Install hostapd and dnsmasq:

sudo apt install hostapd dnsmasq 

Setup hostapd:

cat <<EOF | sudo tee /etc/hostapd/hostapd.conf > /dev/null  
interface=wlan1
driver=nl80211
ssid=***YOUR AP'S NAME***
channel=1
hw_mode=g
ignore_broadcast_ssid=0
wpa=2
wpa_key_mgmt=WPA-PSK
rsn_pairwise=CCMP
wpa_passphrase=***AP'S PASSWORD***
auth_algs=3
wpa_group_rekey=600
wpa_ptk_rekey=600
wpa_gmk_rekey=86400
country_code=***YOUR COUNTRY CODE**
ieee80211d=1
macaddr_acl=0
EOF

sudo sed -i: 's|^#DAEMON_CONF=""|DAEMON_CONF="/etc/hostapd/hostapd.conf"|g' /etc/default/hostapd

Give your device a static ip:

cat <<EOF | sudo tee -a /etc/dhcpcd.conf > /dev/null
interface wlan1
static ip_address=192.168.42.1/24
nohook wpa_supplicant
EOF

Configure dhcp:

cat <<EOF | sudo tee -a /etc/dnsmasq.conf > /dev/null
interface=wlan1
dhcp-range=192.168.42.20,192.168.42.100,255.255.255.0,12h
EOF

Enable forwarding and configure iptables:

sudo sed -i: 's/^#net.ipv4.ip_forward=1/net.ipv4.ip_forward=1/g' /etc/sysctl.conf
sudo sh -c "echo 1 > /proc/sys/net/ipv4/ip_forward"
sudo iptables -t nat -A POSTROUTING -o wlan0 -j MASQUERADE
sudo iptables -A FORWARD -i wlan0 -o wlan1 -m state --state RELATED,ESTABLISHED -j ACCEPT
sudo iptables -A FORWARD -i wlan1 -o wlan0 -j ACCEPT
sudo sh -c "iptables-save > /etc/iptables.ipv4.nat"
sudo sed -i -e '$i \iptables-restore < /etc/iptables.ipv4.nat\n' /etc/rc.local

Reboot and let me know if it's not working.

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

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