Internet <--> USB 3G modem <-->powered USB hub <--> Raspberry Pi <--> Ethernet <--> user machine (PC/Laptop)-->-->-->-->-->
The purpose of this kind of router varied, depending on your needs. However, I have a very specific need in one of my setup where providing Internet connection directly from the 3G modem is not possible and only Ethernet interface can be used by the user (physical/virtual) machine.
These are what you need:
- A Raspberry Pi (I'm using the B revision), with Raspbian distro.
- A powered USB hub. This is required because most USB 3G modems are power hungry and cannot be operated reliably only via the USB connector on the Pi.
- A USB 3G modem. Use whatever you have, hopefully Raspbian kernel already support it. I'm using Huawei E153 USB modem which is rather not so friendly in terms of operation in Raspbian, but it works reliably nonetheless, once you know how to "switch" it into modem "mode".
- Ethernet cable.
- A user machine to test the interconnection.
- Internet/data plan subscription to your mobile operator or whatever works for you.
- Update your Raspbian with "sudo apt-get update"
- Install the needed packages with "sudo apt-get install ppp usb-modeswitch"
- Configure the pppd configuration file according to your needs.
pre-up iptables-restore < /etc/iptables.ipv4.nat
instead of the one explained by Adafruit to make the NAT work permanently across reboots and shutdowns.
The next step is to connect to the Internet. These are my steps:
- Power on the Raspberry Pi.
- Unplug the 3G USB modem from the USB hub, and then plug it back again if it's previously plugged in before Raspberry Pi finished booting. This is a compatibility hack because sometimes it is required, and sometimes not.
- Wait until the 3G USB modem is recognized (watch syslog, i.e. tail -f /var/log/messages)
- Run usb_modeswitch on the modem
- Run pppd
- Watch syslog to find out whether the data connection succeeded or not, i.e. tail -f /var/log/messages
- Test the connection with your user machine connected through Raspberry Pi Ethernet.
I also run a DHCP server in my Raspberry Pi, the isc-dhcp server. The configuration files for isc-dhcp are /etc/init.d/isc-dhcp-server, /etc/default/isc-dhcp-server and /etc/dhcp/dhcpd.conf. You only need to deal with the last two config files. /etc/default/isc-dhcp-server determines which network interface(s) used to listen for DHCP client requests. /etc/dhcp/dhcpd.conf determines the network configuration, such as the IP addresses to assign to the client, DNS servers, gateway, etc. Let's have a look at my configuration files.
This is how my /etc/default/isc-dhcp-server looks like.
# Defaults for isc-dhcp-server initscript # sourced by /etc/init.d/isc-dhcp-server # installed at /etc/default/isc-dhcp-server by the maintainer scripts # # This is a POSIX shell fragment # # Path to dhcpd's config file (default: /etc/dhcp/dhcpd.conf). DHCPD_CONF=/etc/dhcp/dhcpd.conf # Path to dhcpd's PID file (default: /var/run/dhcpd.pid). #DHCPD_PID=/var/run/dhcpd.pid # Additional options to start dhcpd with. # Don't use options -cf or -pf here; use DHCPD_CONF/ DHCPD_PID instead #OPTIONS="" # On what interfaces should the DHCP server (dhcpd) serve DHCP requests? # Separate multiple interfaces with spaces, e.g. "eth0 eth1". INTERFACES="eth0"As you can see, isc-dhcp listens to client on the ethernet interface and the dhcpd configuration file to use is set to /etc/dhcp/dhcpd.conf. Now, let's have a look at /etc/dhcp/dhcpd.conf.
# # Sample configuration file for ISC dhcpd for Debian # # # The ddns-updates-style parameter controls whether or not the server will # attempt to do a DNS update when a lease is confirmed. We default to the # behavior of the version 2 packages ('none', since DHCP v2 didn't # have support for DDNS.) ddns-update-style none; # option definitions common to all supported networks... #option domain-name "example.org"; #option domain-name-servers ns1.example.org, ns2.example.org; default-lease-time 7200; max-lease-time 86400; # If this DHCP server is the official DHCP server for the local # network, the authoritative directive should be uncommented. authoritative; # Use this to send dhcp log messages to a different log file (you also # have to hack syslog.conf to complete the redirection). log-facility local7; # .. irrelevant commented config omitted for brevity .. # Raspberry Pi subnet - note: this is the subnet of M$ Internet Connection Sharing # TODO: Make sure the router configuration is correct subnet 192.168.137.0 netmask 255.255.255.0 { range 192.168.137.3 192.168.137.21; option broadcast-address 192.168.137.255; option routers 192.168.137.2; default-lease-time 7200; max-lease-time 86400; option domain-name "local"; option domain-name-servers 8.8.8.8, 8.8.4.4; }As you can see, the lease time and maximum lease time configuration are consistent. I found that inconsistencies in these parameters sometimes causes isc-dhcp fails to provide valid IP addresses to the DHCP clients. So, watch-out to those parameters values.
Well, there are some more details regarding pppd, usb_modeswitch and iptables which are missing. This post is still considered beta and I'm going to update it in the not so distant future..
Post a Comment
No comments:
Post a Comment