Now must set some settings, let make raspberry pi can be a wifi route which the flow can pass by eth0.
Set
Way 1
sudo echo 1 > /proc/sys/net/ipv4/ip_forward
Way 2
sudo vim /etc/sysctl.conf
# Uncomment the next line to enable packet forwarding for IPv4
net.ipv4.ip_forward=1
#Start command at the reboot
crontab -e
@reboot /home/pi/start.sh
create a file was called start.sh which under /home/pi
sudo iptables -t nat -A POSTROUTING -o eth0 -j MASQUERADE
sleep 5
sudo /etc/init.d/isc-dhcp-server restart
sleep 5
sudo /etc/init.d/isc-dhcp-server restart
sleep 5
sudo /etc/init.d/isc-dhcp-server restart
Why 「sudo /etc/init.d/isc-dhcp-server restart」do three time, because I must make sure the server start up after reboot.After above procedure, then raspberry pi be a wifi router now.
Reference:
1. [Raspberry Pi] Install DHCP Server into Raspberry Pi
2. [Raspberry Pi] WiFi-AP by using Edimax(EW-7811UN)
3. Raspberry Pi as a Router
4. Run script on a startup
0 意見:
張貼留言