Thanks for Jaromanda X's comment.
So first I reference to Setting up a Raspberry Pi as a bridged wireless access point bridging eth0 & wlan1 as br0.
Then setup wlan0 connection by edit /etc/wpa_supplicant/wpa_supplicant.conf
and install dnsmasq
by using sudo apt install dnsmasq
. Modify /etc/dhcpcd.conf
add following line below interface br0
:
static ip_address=192.168.220.1/24
After setting up dhcpcd.conf
, we are now modifying /etc/dnsmasq.conf
it's better to make a backup of the dnsmasq.conf
. Now open up /etc/dnsmasq.conf
add following lines:
interface=br0
dhcp-range=192.168.220.50,192.168.220.150,12h
Then enable ip_forwarding in /etc/sysctl.conf
, find #net.ipv4.ip_forward=1
and remove # beginning of it.
To make ip_forward enable immediately run:
sudo sh -c "echo 1 > /proc/sys/net/ipv4/ip_forward"
Adding iptable rules:
sudo iptables -t nat -A POSTROUTING -o wlan0 -j MASQUERADE
sudo iptables -A FORWARD -i wlan0 -o br0 -m state --state RELATED,ESTABLISHED -j ACCEPT
sudo iptables -A FORWARD -i br0 -o wlan0 -j ACCEPT
Then save rules:
sudo sh -c "iptables-save > /etc/iptables.ipv4.nat"
Appending new iptables rules in /etc/rc.local
, so Pi will run it automatic every reboot. Open up /etc/rc.local
appand iptables-restore < /etc/iptables.ipv4.nat
above exit0
.
Finally start dnsmasq service and reboot system by following commands:
sudo systemctl start dnsmasq.service
sudo reboot