1

I am using my Raspberry Pi for configuring both as an wifi hostpot and wired router not at same time. I have written separate bash script file (.sh file) for creating configuration files for wifi and wired router. I am using udhcp and dnsmasq for configuring Rpi as wifi hotspot. Tutorial on elinux.

When i run wifi.sh file with sudo ./wifi.sh following files are written successfully

hostapd
hostapd.conf
udhcpd
udhcpd.conf
sysctl.conf
interfaces

and the following command will execute

iptables -F
iptables -t nat -F

iptables -t nat -A POSTROUTING -o eth0 -j MASQUERADE
iptables -A FORWARD -i eth0 -o wlan0 -m state --state RELATED,ESTABLISHED -j ACCEPT
iptables -A FORWARD -i wlan0 -o eth0 -j ACCEPT

sh -c "iptables-save > /etc/iptables.ipv4.nat"

service hostapd start
service udhcpd start

update-rc.d hostapd enable
update-rc.d udhcpd enable

Similarly for sudo ethernet.sh following files and command will execute. I am using dnsmasq for this. tutorial

dnsmasq.conf
sysctl.conf
interfaces


iptables -F
iptables -t nat -F

iptables -t nat -A POSTROUTING -o eth0 -j MASQUERADE  

iptables -A FORWARD -i eth0 -o eth1 -m state --state RELATED,ESTABLISHED -j ACCEPT  
iptables -A FORWARD -i eth1 -o eth0 -j ACCEPT  

sh -c "iptables-save > /etc/iptables.ipv4.nat"

But when i first switch from wifi to ethernet it works. But when again switch from ethernet to wifi, hotspot generating but i can't connect my device.

When i searched about it, some are saying it is because of udhcpd server.

But both script work standalone.

What will be the reason?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.