3

I've got several devices connected to a Sky router (Sky Hub SR101) via Wi-Fi and Ethernet.

I have a USB Wi-Fi dongle connected to my Raspberry Pi, and I use it to connect to a 4G smartphone. That works fine - I have access to the internet from the Raspberry Pi.

What I wanted to know is if it is possible to keep all the devices connected to the Sky router and share the 4G coming from the smartphone... through the Raspberry Pi, that acts like the gateway to the internet?

If I get another device, can I easily connect it to the 4G network just by connecting it to the Sky router (instead of the smartphone directly)?

[Note that the Sky router has no connection with the internet.]

Diagram of connected devices

UPDATE: it turns out it was a problem with my dhcp server config. I was setting the wrong Ip to the router (on /etc/dhcp/dhcpd.conf).

subnet 192.168.10.0 netmask 255.255.255.0 {
 range 192.168.10.10 192.168.10.20;
 option broadcast-address 192.168.10.255;
 option routers 192.168.10.1; <-- HERE !!!
 default-lease-time 600;
 max-lease-time 7200;
 option domain-name "local-network";
 option domain-name-servers 8.8.8.8, 8.8.4.4;
}

I followed this tutorial.

  • In that scenario, will the sky router have a connection to the internet? If so, you will be setting up a network with 2 routes to the outside world - how do you want the machines to decide which connection to use? It can be made to work either way, but we need to know to answer properly :) And clearly the 2 route scenario is more complicated. – lwr20 Feb 6 '16 at 21:22
  • yes, the problem is that the router has no connection with the internet. it's offline. – Txugo Feb 6 '16 at 22:26
  • 1
    Unless there is an option in the sky router to use an ethernet port for WAN or an option to disable DHCP and let the Pi do that, it won't work. – John Keates Feb 7 '16 at 3:14
  • @John Keates - I disagree. If the clients can be configured with their default route via the Pi, it will just work. – lwr20 Feb 8 '16 at 10:44
  • I've followed this tutorial://raspberrypihq.com/how-to-turn-a-raspberry-pi-into-a-wifi-router/ but inverted (eth0 as wlan0 and vice versa). installed and configured the ISC-DHCP-Server. disabled my sky router's dhcp server. but I have no internet connectivity now. I can connect to my sky router and get an IP given to me by the pi. I can ping my pi. I can ping google (and have connection to the internet) from within the pi. There must be something wrong with my routing tables. Any ideas? I've tried to setup my routing tables using that tutorial and set a static IP to the eth0 of the pi. – Txugo Feb 20 '16 at 1:37
2

I think you want to follow: http://www.skyuser.co.uk/forum/asking-help/41883-how-connect-two-routers-together.html

The only difference is that your Raspberry Pi and 4G combo is the gateway router (i.e. the one with the WAN connection).

You'll also want to set up your Pi to forward packets from the wired interface to the wireless interface. This tutorial does exactly that, but in reverse, so wherever it refers to eth0, you should substitute wlan0 and vice versa: http://qcktech.blogspot.co.uk/2012/08/raspberry-pi-as-router . You might also look at RPi as Internet Gateway/Bridge

  • I've followed this tutorial://raspberrypihq.com/how-to-turn-a-raspberry-pi-into-a-wifi-router/ but inverted (eth0 as wlan0 and vice versa). installed and configured the ISC-DHCP-Server. disabled my sky router's dhcp server. but I have no internet connectivity now. I can connect to my sky router and get an IP given to me by the pi. I can ping my pi. I can ping google (and have connection to the internet) from within the pi. There must be something wrong with my routing tables. Any ideas? I've tried to setup my routing tables using that tutorial and set a static IP to the eth0 of the pi. – Txugo Feb 21 '16 at 20:03
1

I found exactly what you need: https://www.diyhobi.com/share-raspberry-pi-wifi-internet-ethernet/

Raspberry Pi shares the internet it gets from a wifi and forward it to ethernet connected to a router.

Raspi becomes a DHCP server instead of the router so internet is distributed from Raspberry Pi Wifi to any devices connected to the router via cable or via wifi.

enter image description here

0

This can work if the RasPi and the phone are in a second Wi-Fi network (so other devices cannot circumvent the RasPi). The RasPi can be configured as a gateway, there are tons of tutorials on how to do this.

However, you either have to connect the RasPi to the WAN port of the router, or you need to manually configure the IP settings of all devices, because the router would set itself as the gateway when handing out IP configurations over DHCP.

  • 1
    there are tons of tutorials on how to do this - could you provide a link to one or two of the easiest to follow, and/or summarize the process? – Greenonline Feb 7 '16 at 14:11
  • 1
    well I could, but I'm not gonna google "raspberry as router" and pick "the best suited one" out. The question was "is it possible", not "give me a detailed walkthrough". – dube Feb 7 '16 at 16:20
  • This is the first result when you google "raspberry pi as gateway" – whoKnows Mar 26 at 17:39
0

Let me describe what was my needs and how I achieved what I needed.


Need

Connect RPI to WiFi using WiFi USB adapter and share internet connection to Ethernet cable, connected to actual router. RPI configuration done via SSH.


Steps

  1. Insert WiFi USB adapter and internet cable to RPI. In the following steps - WiFi adapter will be called wlan0 and Ethernet interface will be called eth0.

  2. Connect RPI to WiFi using your preferred method (nmtui or netctl). Ensure it connects automatically after boot.

  3. Execute this script on boot (as root):

#!/bin/bash

# Enable IPv4 and IPv6 forwarding (feature):
sysctl net.ipv4.ip_forward=1
sysctl net.ipv6.conf.default.forwarding=1
sysctl net.ipv6.conf.all.forwarding=1

# Assign IP address to eth0:
ip link set up dev eth0
ip addr add 10.42.0.1/24 dev eth0

# Set up NAT:
iptables -t nat -A POSTROUTING -o wlan0 -j MASQUERADE
iptables -A FORWARD -m conntrack --ctstate RELATED,ESTABLISHED -j ACCEPT
iptables -A FORWARD -i eth0 -o wlan0 -j ACCEPT
  1. Connect Ethernet cable to Router (so it's RPI <--> Router) and use the following WAN settings in router configuration page. Note that RPI does not have DHCP server, so you need to use static IP:

IP address: 10.42.0.100

Subnet mask: 255.255.255.0

Gateway: 10.42.0.1


Additional suggestions

Computer instead of Router

Yes, you can do it. Since I will not cover DHCP server configuration on RPI, you are on your own, otherwise use static IP address as I've described for router.

DNS

In router WAN settings, do not forget to set your preferred DNS settings as well. I would suggest using pi-hole (or any other) DNS server on RPI, so in WAN settings you would set DNS IP the same as gateway IP. Same DNS server could be used in RPI network settings.

Firewall

If this is the case that you do not want WiFi owner to be able to connect to your RPI via SSH or see any service, append the following lines at the end of script file, which you execute on boot:

# Firewall stuff:
iptables -A INPUT -s 192.168.0.1 -j ACCEPT
iptables -A INPUT -s 192.168.0.0/24 -j DROP
iptables -A OUTPUT -d 192.168.0.1 -j ACCEPT
iptables -A OUTPUT -d 192.168.0.0/24 -j DROP

Explanation: first 2 lines blocks all incoming traffic from 192.168.0.* except 192.168.0.1 (router). last 2 lines does the same, but for outgoing traffic.

Share internet from eth0 to wlan0

Just use create_ap script. Search in official repositories - it should be in there. There is no easier way that this - no additional configuration or scripting required - just single command line to start WiFi AP.

  • I am using RPI1 and due to hardware limitations and low performance, the 100MBPS WiFi speed is limited to 30 MBPS~ for RPI and 7-25 MBPS~ for the Ethernet cable. – Erikas Jun 16 '18 at 13:20
  • Had WiFi stability issues when using networkmanager (nmtui) and when switched to netctl - issues are gone. – Erikas Jun 19 '18 at 10:10

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.