Use Raspberry Pi as a 3G wireless router

Source: Internet
Author: User

The first blog gave me a long course design, that is, the topic "3G wireless router. The development platform used in this development project is the Raspberry Pi Development Board. The following is the question .....

Objective: To set Raspberry Pi as a 3G wireless router and access the Internet through Huawei's e261.

Tools: Raspberry Pi Development Board, 3G wireless network adapter E261, wireless network adapter RT5370,

 

Steps:

1. Convert E261 Mode

1. View connected USB devices

pi@raspberrypi ~ $ lsusbBus 001 Device 002: ID 0424:9514 Standard Microsystems Corp.Bus 001 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hubBus 001 Device 003: ID 0424:ec00 Standard Microsystems Corp.Bus 001 Device 004: ID 148f:5370 Ralink Technology, Corp. RT5370 Wireless AdapterBus 001 Device 005: ID 1a40:0101 Terminus Technology Inc. 4-Port HUBBus 001 Device 006: ID 058f:6387 Alcor Micro Corp. Flash DriveBus 001 Device 007: ID 12d1:1446 Huawei Technologies Co., Ltd.

 

The ID of the last line is the vendor ID and device ID of E261. In this case, E261 is equivalent to a storage device and must be converted to a Modem device.

 

2. Install usb_modeswitch

pi@raspberrypi ~ $ sudo aptitude install usb-modeswitch

 

3. modify the configuration file

pi@raspberrypi ~ $ sudo nano /etc/usb_modeswitch.conf

 

Add the following content at the end of the file:

######################################################### Huawei, newer modemsDefaultVendor= 0x12d1DefaultProduct=0x1446TargetVendor= 0x12d1TargetProductList="1001,1406,140b,140c,1412,141b,1436,14ac"CheckSuccess=20MessageContent="55534243123456780000000000000011062000000100000000000000000000"

 

4. Re-unplug E261 and execute lsusb again

pi@raspberrypi ~ $ lsusbBus 001 Device 002: ID 0424:9514 Standard Microsystems Corp.Bus 001 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hubBus 001 Device 003: ID 0424:ec00 Standard Microsystems Corp.Bus 001 Device 004: ID 148f:5370 Ralink Technology, Corp. RT5370 Wireless AdapterBus 001 Device 005: ID 1a40:0101 Terminus Technology Inc. 4-Port HUBBus 001 Device 006: ID 058f:6387 Alcor Micro Corp. Flash DriveBus 001 Device 007: ID 12d1:1436 Huawei Technologies Co., Ltd.

 

The device number has changed to 1436, indicating that the conversion is successful.

 

Note that if you use another 3G network card, the configuration file is different.

 

Ii. Download and install ppp, sakis3g, and umtskeeper to implement dial-up Internet access

 

The ppp package establishes a Point-to-Point Protocol-based daemon for managing communications between you and network operators. Sakis3g is a script used to dial up the Internet. It has an interactive dialing interface, which is very convenient. Umtskeeper uses sakis3g to automatically reconnect to the 3G network. You can also use wvdial to dial up the Internet,

Run the aptitude install wvdial command to install the ppp package. The following describes the previous method.

1. Install ppp

pi@raspberrypi ~ $sudo apt-get install ppp

 

2. For ease of management, create the folder umtskeeper/put umtskeeper and sakis3g in this folder.

Create the umtskeeper folder and download umtskeeper

sudo mkdir umtskeepercd umtskeepersudo wget "http://zool33.uni-graz.at/petz/umtskeeper/src/umtskeeper.tar.gz"sudo tar -xzvf umtskeeper.gzsudo chmod +x umtskeeper

 

The official Sakis3g website has been suspended, but other images can be used.

sudo wget "http://downloads.sourceforge.net/project/vim-n4n0/sakis3g.tar.gz?r=http%3A%2F%2Fsourceforge.net%2Fprojects%2Fvim-n4n0%2Ffiles%2F&ts=1363537696&use_mirror=tene~t" -O sakis3g.tar.gzsudo tar -xzvf sakis36.tar.gzsudo chmod +x sakis3g

 

3. dial-up Internet access

sudo ./sakis3g --interactive "connect"  

 

Enter the interaction interface as follows:

 

(If an error occurs during dialing, restart Raspberry Pi)

 

Enter the information of the APN.

 

China Unicom's APN is 3 gnet, and the user name and password seem to be optional. I fill in user and pass

 

View connection information

./sakis3g connect info

 

Disconnect

sudo ./sakis3g --interactive "disconnect" 

 

4. Set automatic dial-up for Internet access at startup

You have downloaded umtskeeper in step 2. You can also use it to call sakis3g for networking. The command is as follows:

sudo ./umtskeeper --sakisoperators "USBINTERFACE='0' OTHER='USBMODEM' USBMODEM='12d1:1436' APN='CUSTOM_APN' CUSTOM_APN='3gnet' APN_USER='user' APN_PASS='pass'" --sakisswitches "--sudo --console" --devicename 'Huawei' --log --silent --monthstart 8 --nat 'no'

 

Write the preceding command to rc. local.

Edit rc. local

pi@raspberrypi ~ $sudo nano /etc/rc.local

 

Insert the following content before the exit0 line

/home/pi/umtskeeper --sakisoperators "USBINTERFACE='0' OTHER='USBMODEM' USBMODEM='12d1:1436' APN='CUSTOM_APN' CUSTOM_APN='3gnet' APN_USER='user' APN_PASS='pass'" --sakisswitches "--sudo --console" --devicename 'Huawei' --log --silent --monthstart 8 --nat 'no'

 

Save and exit. Next time, you can start dial-up Internet access.

 

 

3. Create a Wireless AP

1. Configure the wireless network card as a fixed IP Address

Enter the command

sudo nano /etc/network/interfaces

 

Edit the network configuration file

Comment out the following lines:

#allow-hotplug wlan0#iface wlan0 inet manual#wpa-roam /etc/wpa_supplicant/wpa_supplicant.conf#iface default inet dhcp

 

Add the following lines

iface wlan0 inet static address 192.168.10.1netmask 255.255.255.0

 

Here we need to note that 192.168.10.1 is the gateway ip address allocated to the router of the raspberry pi. This cannot be the same as the ip addresses of other routing gateways in the LAN.

 

2 install hostapd

Use hostapd in Linux to establish a Wireless AP Service
Run the following command to install hostapd:

sudo apt-get install hostapd

 

Edit the default hostapd configuration file

sudo nano /etc/default/hostapd


Find

# DAEMON_CONF = ""
Modify as follows:

DAEMON_CONF = "/etc/hostapd. conf"
Edit the hostapd configuration file

sudo nano /etc/hostapd/hostapd.conf

 

Add the following content

# Use the wireless network adapter wlan0 as the Access Point interface = wlan0 # Use the nl80211 driver = nl80211 # The SSID of the shared network is RaspberryPissid = RaspberryPi # The network adapter works in the 802.11G mode hw_mode = g #11 channel = 11 # WPA2 configuration wpa = 2 # wpa password is encrypt = raspberry # Authentication Mode for WPA-PSK encryption mode = WPA-PSKwpa_pairwise = CCMP rsn_pairwise = CCMPbeacon_int = 100 auth_algs = 3wmm_enabled = 1

 

Save and exit
Enter the command

sudo service hostapd restart


Restart the hostapd service.

 

3. Install the dhcp service

DHCP service is used to assign Dynamic IP addresses to clients.

Enter the command to install the dhcp service

sudo apt-get install isc-dhcp-server

 

Backup configuration file

sudo mv /etc/dhcp/dhcpd.conf  /etc/dhcp/dhcpd.conf.bak

 

Edit a new configuration file

sudo nano /etc/dhcp/dhcpd.conf

 

Copy and paste the following content

default-lease-time 600;max-lease-time 7200;log-facility local7;subnet 192.168.10.0 netmask 255.255.255.0 {  range 192.168.10.10 192.168.10.100;  option routers 192.168.10.1;  option broadcast-address 192.168.10.127;  option domain-name-servers 8.8.8.8,8.8.4.4;  default-lease-time 600;  max-lease-time 7200;}

 

Save and exit
 

Modify the isc-dhcp-server File

sudo nano /etc/default/isc-dhcp-server

 

The configuration file path added to DHCP and the parameters used as the AP Interface

DHCPD_CONF = "/etc/dhcp/dhcpd. conf"

INTERFACES = "wlan0"

Restart the service

sudo service  isc-dhcp-server restart

 

 

4. Configure route forwarding

So far, we have already established a wireless hotspot. The mobile phone's WiFi function can be connected to the RaspberryPi hotspot, but it cannot access the Internet. The reason is that the Wireless AP is not responsible for data exchange, that is, the data packets sent to the Wireless AP through the client cannot be sent to the target host, and naturally no response is required.
In Linux, iptables is used to complete packet forwarding. It is the core of the routing function.

Before adding iptables forwarding rules, you must enable the kernel's IP forwarding function:

echo "1" > /proc/sys/net/ipv4/ip_forward

 

The above command only temporarily enables the IP forwarding function. It will expire after the next restart. If it is not invalid, you can directly modify the system configuration file/etc/sysctl. conf.

sudo nano /etc/sysctl.conf

 

Find here

#net.ipv4.ip_forward=1

 

Remove the preceding annotator #

Save and exit
Enter the command

sudo sysctl -p

 

Make this setting effective immediately

 

The following is the key part. set IP Forwarding rules,

sudo iptables -t nat -A POSTROUTING -o ppp0 -j MASQUERADEsudo iptables -A FORWARD -i ppp0 -o wlan0 -j ACCEPTsudo iptables -A FORWARD -i wlan0 -o ppp0 -j ACCEPT

 

 

Ppp0 is a 3G Nic interface, and MASQUERADE indicates data packet disguise. Internal data of the router is sent out or external data is imported through this interface. If there is an Ethernet port, you can change ppp0 to eth0 to implement forwarding on this Ethernet port, that is, to implement the function of a common wireless router.

 

Save IP Forwarding rules

sudo bashiptables-save > /etc/iptables.up.rulesExit

 

Enter the command

sudo nano /etc/network/if-pre-up.d/iptables


Copy and paste the following two lines to the editing window.

#!/bin/bash/sbin/iptables-restore < /etc/iptables.up.rules


Save and exit

 

At this point, the configuration of the 3G router has been completed. Enter

sudo reboot

 

Restart Raspberry Pi to search for the wireless signal of RaspberryPi. After the connection, you can access the Internet.

 

--------------------------------

Reprinted, please indicate the source (after all, google has read a lot of information and many posts in English)

Related Article

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.