Raspberry Pi made into router

Source: Internet
Author: User

I have seen a lot of articles to make Raspberry Pi into a wireless AP, but what I want to do today is to make Raspberry Pi into a NAT-enabled router, I did this because I was on a business trip to Holland and found my bambook unable to access the dorm WiFi, Perhaps because the dorm wireless router is the way to authenticate WEP, in short, not even. Later decided to use Raspberry pi+ Arctic Starlight Wireless router to solve the problem.


Ideas:

"Wireless Router"-----"wireless network card--raspberry pi--wired RJ45 port"------"wired RJ45 Port--Arctic star wireless router-Wireless"----bambook


Step One:

Configuring the Raspberry Pi Wireless card and the wired network card


The wireless network card is connected to the dorm wireless router via WEP, and a fixed IP is configured, and the wired network card is also configured with a fixed IP


[Email protected]:~$ cat/etc/network/interfacesauto loiface lo inet loopbackiface eth0 inet static address 172.16.1.100ne Tmask 255.255.255.0gateway 172.16.1.1######################################## #allow-hotplug wlan0iface wlan0 inet  Static#wpa-roam/etc/wpa_supplicant/wpa_supplicant.conf#iface default inet DHCP Wireless-essid adsl-wifi-c91f44 Wireless-key 1234567890address 192.168.1.100netmask 255.255.255.0gateway 192.168.1.254


Step Two:

Erecting a DHCP server on the Raspberry Pi

[Email protected]:~$ sudo apt-get install Isc-dhcp-server

Edit dhcp.conf File

[Email protected]:~$ sudo vi/etc/dhcp/dhcpd.conf

Add the following lines at the end of the dhcp.conf file

Subnet 172.16.1.0 netmask 255.255.255.0 {range 172.16.1.1 172.16.1.99;option routers 172.16.1.100;option Domain-name-servers 8.8.8.8,8.8.4.4;}

Test whether an IP address can be assigned after connecting to a notebook on the RJ45 port of the Raspberry Pi

[Email protected]:~$ sudo service isc-dhcp-server restartstopping ISC DHCP SERVER:DHCPD. Starting ISC DHCP SERVER:DHCPD.

Step Three:

Enable the Raspberry Pi Routing and forwarding feature and turn on NAT


Turn on the Routing and forwarding function

[Email protected]:~$ sudo vi/etc/sysctl.conf

Remove the "#" in front of the net.ipv4.ip_forward=1 in the sysctl.conf and save it.


Turn on the NAT feature

Make a NAT-enabled script that is saved as a NAT

#!/bin/shsudo iptables-t nat-a postrouting-o wlan0-j masqueradesudo iptables-a forward-i wlan0-o eth0-m State--st Ate related,established-j acceptsudo iptables-a forward-i eth0-o wlan0-j ACCEPT

Run this script

[email protected]:~$ ls | grep natnat[email  protected]:~$ sh ./nat 
[email protected]:~$ sudo iptables -lchain input  (Policy ACCEPT) target      prot opt source                destination         chain  FORWARD  (policy accept) target     prot opt source                destination          ACCEPT     all  --   anywhere             anywhere              state RELATED,ESTABLISHEDACCEPT      all  --  anywhere              anywhere            chain output  (policy  ACCEPT) target     prot opt source                destination          [email protected]:~$ sudo iptables -t nat -LChain PREROUTING  ( policy accept) target     prot opt source                destination          Chain INPUT  (policy accept) target     prot opt  source                destination         chain output  (Policy ACCEPT) target     prot opt source                destination         Chain POSTROUTING  ( policy accept) target     prot opt source                destination          MASQUERADE  all  --  anywhere              anywhere             [email protected]:~$

Create a iptables file in the/etc/network/directory

[Email protected]:~$ sudo touch/etc/network/iptables

Save Iptables content to/etc/network/iptables

[Email protected]:~$ sudo sh-c "Iptables-save >/etc/network/iptables"
[Email protected]:~$ cat /etc/network/iptables # generated by iptables-save  v1.4.14 on sun jun 15 05:45:28 2014*filter:input accept [ 22972:1979567]:forward accept [0:0]:output accept [2421:275063]-a forward -i  wlan0 -o eth0 -m state --state related,established -j accept-a  forward -i eth0 -o wlan0 -j acceptcommit# completed on sun  jun 15 05:45:28 2014# generated by iptables-save v1.4.14 on  Sun Jun 15 05:45:28 2014*nat:PREROUTING ACCEPT [9719:1105033]:INPUT  ACCEPT [1273:238753]:OUTPUT ACCEPT [675:88515]:P ostrouting accept [219:34192]-a  Postrouting -o wlan0 -j masqueradecommit# completed on sun jun 15  05:45:28 2014[email protected]:~$ 

Add an up Iptables-restore </etc/network/iptables on/etc/network/interfaces to automatically take effect every time you start

[Email protected]:~$ cat/etc/network/interfacesauto loiface lo inet loopbackiface eth0 inet static address 172.16.1.100ne Tmask 255.255.255.0gateway 172.16.1.1######################################## #allow-hotplug wlan0iface wlan0 inet  Static#wpa-roam/etc/wpa_supplicant/wpa_supplicant.conf#iface default inet DHCP Wireless-essid adsl-wifi-c91f44 Wireless-key 1234567890address 192.168.1.100netmask 255.255.255.0gateway 192.168.1.254up Iptables-restore </etc/ Network/iptables

Save restart Find the portable function of the RJ45 port of the Raspberry Pi to get the IP address automatically, and can ping the extranet.

This article is from the "Rookie Geek" blog, make sure to keep this source http://raspjason.blog.51cto.com/8565009/1426561

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.