4

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.

Txugo
  • 241
  • 1
  • 4
  • 14

4 Answers4

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

lwr20
  • 312
  • 2
  • 10
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

Mia19
  • 41
  • 1
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.

Greenonline
  • 2,969
  • 5
  • 27
  • 38
dube
  • 149
  • 3
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.

Erikas
  • 101
  • 3