Share internet over Stratux WiFi - cyoung/stratux GitHub Wiki

When using a WiFi only iPad model, or having an iPad without mobile subscription, it can be useful to share your phone's internet connection over the Stratux WiFi network. This can be done by enabling NAT routing between network adapters.

The below guide is tested and works with iOS devices like iPhone and USB tethering to create another ethernet adapter on the PI. Feel free to use other network adapters. In that case, you will have to provide an alternative network adapter in step 2. This can eg. be another wifi dongle, or you could use the default eth0 adapter, but you would then need to provide internet access to your PI over ethernet.

1 Preparations

To setup the basic packages, your PI needs to have an active internet connection. I suggest to use an ethernet cable to connect to your PI ethernet port.

You can then either SSH into the the PI over ethernet or connect a keyboard and screen. If you use a keyboard and screen, try to ping google.com to check internet access.

When you are logged into the PI and have setup internet access for it, update the core system to the latest versions. This is necessary due to recently solved compatibility bugs and will improve overall performance and security.

This can be done using the normal linux commands

sudo apt-get update

sudo apt-get upgrade

2 Install USB internet adapter

sudo apt-get install usbmuxd

sudo apt-get install gvfs ipheth-utils libimobiledevice-utils gvfs-backends gvfs-bin gvfs-fuse ifuse -y

This will create a new network adapter eth1 on the system. You can check your network adapters (and their assigned IP addresses) with the ifconfig command.

3 Configure network settings

sudo nano /etc/network/interfaces

Add the following code to the file (below the similar entry for eth0

allow-hotplug eth1

iface eth1 inet dhcp

Reboot your PI afterwards for the settings to take effect.

After this step I prefer to disconnect Ethernet and use internet tethering from your phone. Enable your personal hotspot and connect your iPhone afterwards with an USB cable to the PI.

A message on your iPhone should pop-up with the request to 'trust' this computer. Click 'Allow'. On the top of your iPhone a blue indicator conforms your PI has been assigned an IP address by your phone.

To continue your configuration, connect another computer to your phone's wireless hotspot.

Open a terminal window and determine the ip address of the PI (using ifconfig | grep broadcast ) or a networking scan tool on your iPhone and SSH back into your PI. (Your phone is now acting as router and providing network connection)

4 Enable NAT routing

In the following step you need to edit system configuration to allow for NAT routing

sudo nano /etc/sysctl.conf

Find and uncomment the line

net.ipv4.ip_forward=1

Exit and save the document

Start NAT with the following command

sudo sh -c "echo 1 > /proc/sys/net/ipv4/ip_forward"

5 Add routing rules

After NAT is enabled you need to add the following routing rules to your iptable Enter the following commands.

sudo iptables -t nat -A POSTROUTING -o eth1 -j MASQUERADE

sudo iptables -A FORWARD -i eth1 -o wlan0 -m state --state RELATED,ESTABLISHED -j ACCEPT

sudo iptables -A FORWARD -i wlan0 -o eth1 -j ACCEPT

6 Edit Stratux startup script

Tell the PI to load the custom iptables settings upon startup. Therefore you need to edit the stratux-wifi.sh post-up script. This will make sure the next time you boot the PI, the settings are going to be applied automatically.

sudo nano /usr/sbin/stratux-wifi.sh

Find the following line, somewhere near the end of the file

/bin/systemct1 restart disc-dhcp-server

Add this line immediate after this line

iptables-restore < /etc/iptables.ipv4.nat

7 Check your DNS settings

Your Stratux wifi and your iPhone reside in different subnets. By default a connected DHCP device will use it's router address as DNS resolver.

As you are using your Stratux wifi, and there is no connection there, using it (by default) as your DNS provider will not allow you to browse on your Stratux connected devicves.

To fix this, add the IP of your iPhone (which serves as internet access point) as a manual DNS server in your Stratux WiFi connected device. Your connected device will now use your phone's internet connection over your PI.