Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Raspberry Pi 2/3B/B+/4B Wireless Bridge using Ubuntu Server 18.04 ARM Image and Netplan

Raspberry Pi 2/3B/B+/4B Wireless Bridge using Ubuntu Server 18.04 ARM Image and Netplan

The initial goal of this project is to use the raspberry pi in place of my Wireless Range Extender and then going from 3 wireless networks (2.4ghz, 2.4ghz extended, 5ghz) at home to only one (5ghz). This way I'm reducing the exposition to radio waves for the whole familly at home.

Let's go technical

Ok, enough drama for now, let's go technical. 😁

Setup

To make your Wireless Bridge, you'll need to have few hours as free time and the following hardware:

For the Raspberry Pi 3B/3B+/4B you can even use 64Bit images instead of Hard-Float images (ARMHF) but during my testing the performances appeared to be less better than the Hard-Float images and the device temperature was higher.

Also found that there are less packages built for 64Bit ARM images / platforms so you should take this into account before these images but if you still want to give them a try, here are the links:

The images above has not been tested yet.

OS Install

Just write the downloaded image on the SD card and follow this procedure.

  1. Power your screen on
  2. Plug the HDMI cable
  3. Plug the network cable
  4. Put the Micro SD card
  5. Plug the power cable
  6. Wait the initial boot to finish
  7. Define your password (you will asked to change the default credentials)
    • Default credentials:
      • user: ubuntu
      • pass: ubuntu

One important thing you might notice is that sudo is not asking for password, you can change this behavior by changing the value in /etc/sudoers file.

Partition resize

This should not be required as the main partition will be resized on the first boot with all the remaining size on your SD card.

In case the auto-resize has failed, you can follow the procedure explained here: https://raspberrypi.stackexchange.com/questions/499/how-can-i-resize-my-root-partition

Using netplan to setup the network interfaces

Now check your interfaces names with ip link show or iwconfig. You'll need them to create the configuration required by netplan.

So, edit the file /etc/netplan/your-config-file.yaml and add or change the following:

# This file is generated from information provided by
# the datasource.  Changes to it will not persist across an instance.
# To disable cloud-init's network configuration capabilities, write a file
# /etc/cloud/cloud.cfg.d/99-disable-network-config.cfg with the following:
# network: {config: disabled}
network:
    version: 2
    renderer: networkd
    # Renderer can be 'networkd' or 'NetworkManager'
    ethernets:
        eth0:
            optional: true
            dhcp4: false
    wifis:
        wlan0:
            optional: true
            dhcp4: true
            access-points:
                "YOUR-SSID-NAME":
                    password: "YOUR-PASSWORD"
            # uncomment the line below if you're using a Microsoft DHCP Server
            #dhcp-identifier: mac

Try to run the test again while commenting out the lines

Once done, test, generate and apply the config that way:

  • Testing: sudo netplan --debug try (continue even if successful)
  • Generate: sudo netplan --debug generate (will give you more details in case of issues with the previous command)
  • Apply: sudo netplan --debug apply (if no issues during the previous commands, you can start to enjoy 😁)

Define the wireless country code!!

Note that it is only required when using NetworkManager as renderer in the netplan config file.

I've forgotten to do that at first try and trust me I wasted around 5 hours before thinking about that...

Edit the file /etc/default/crda and change it that way:

# Define your country code here as explained above or in this format if not explained:
# ISO/IEC 3166-1 alpha2 country code
REGDOMAIN=CH

Then save the file.

OS Update

Now that your network config is done, the first thing to do is to update the whole system. Nothing really difficult, just run these commands:

sudo apt update && sudo apt dist-upgrade

If case of outdated package definitions, replace the command by this one:

sudo apt update --fix-missing -y && sudo apt dist-upgrade

If you prefer a more automated way, here is the one-liner I'm using:

sudo apt update --fix-missing -y && sudo apt dist-upgrade -y && sudo apt autoremove --purge -y

Install required packages

You will need to install some packages which are not included by default in Ubuntu Server 18.04.

sudo apt install wireless-tools wpasupplicant openssh-server

Note that wpasupplicant and openssh-server might be already installed.

Now install the required bridging packages:

sudo apt install parprouted dhcp-helper

If you want to relay the mDNS protocol, add the avahi-daemon package to the chain.

Enable DHCP relay: /etc/default/dhcp-helper

# relay dhcp requests as broadcast to wlan0
DHCPHELPER_OPTS="-b wlan0"

If you have installed the avahi-daemon paackage, you will have to edit the /etc/avahi/avahi-daemon.conf file to enable mDNS relaying:

[reflector]
enable-reflector=yes

Now... The nasty stuffs... πŸ˜…

You'll have to create an extra systemd service file and place it in /lib/systemd/system/.

ARP Bridge service files

Create the service file and name it /lib/systemd/system/arp-bridge.service then put this content:

[Unit]
Description=ARP Bridge over Wireless Interface
Wants=network-online.target
After=network-online.target

[Service]
Type=oneshot
RemainAfterExit=yes
ExecStart=/lib/systemd/system/set-arp-routing start
ExecStop=/lib/systemd/system/set-arp-routing stop
ExecReload=/lib/systemd/system/set-arp-routing restart

[Install]
WantedBy=multi-user.target

Create the starting script and name it /lib/systemd/system/set-arp-routing then put this content:

#!/bin/bash

## ARP Routing Management Script
## Made by Jiab77 <jonathan.barda@gmail.com>

## Config
ETHERNET_IFACE=eth0
WIRELESS_IFACE=wlan0
KEYBOARD_LAYOUT=ch
DISABLE_POWER_MGMT=true

## Help
if [ $# -eq 0 ]; then
	echo -e "\nUsage: $0 action [start|stop|restart|status]\n"
	exit
fi

## Functions
function start_service {
	## Setup system forwarding
	echo -e "\nEnable IP forwarding..."
	echo 1 > /proc/sys/net/ipv4/ip_forward
	## Uncomment lines below if you don't want to use parprouted.
	#echo "Enable ARP forwarding"
	# Comment for all interfaces
	#echo 1 > /proc/sys/net/ipv4/conf/${WIRELESS_IFACE}/proxy_arp
	# Uncomment for all interfaces
	#echo 1 > /proc/sys/net/ipv4/conf/all/proxy_arp

	## Fix the 'eth0' interface that don't want to mount at boot on 3b+
	## Uncomment this part if the 'eth0' interface is not mounted at boot
	#/usr/sbin/netplan apply

	## A little sleep
	sleep 2

	## Assign address
	echo "Cloning IP from ${WIRELESS_IFACE} to ${ETHERNET_IFACE}..."
	/sbin/ip addr add $(/sbin/ip addr show $WIRELESS_IFACE | perl -wne 'm|^\s+inet (.*)/| && print $1')/32 dev $ETHERNET_IFACE

	## Uncomment lines below in case you're encountering the same issues
	#echo "Removing bad APIPA IP from ${ETHERNET_IFACE}"
	#/sbin/ip addr del $(/sbin/ip addr show $ETHERNET_IFACE | perl -wne 'm|^\s+inet (169.254.*)/| && print $1')/16 dev $ETHERNET_IFACE
	#echo "Removing bad APIPA route from ${ETHERNET_IFACE}"
	#/sbin/ip route del 169.254.0.0/16 dev $ETHERNET_IFACE

	## Make sure that the eth0 interface is up
	echo "Setting up lan interface..."
	/sbin/ip link set $ETHERNET_IFACE up

	## Setup ARP forwarding
	echo "Starting paraprouted..."
	/usr/bin/killall -KILL parprouted 2> /dev/null
	/usr/sbin/parprouted $ETHERNET_IFACE $WIRELESS_IFACE

	## Reloading DHCP Relay
	echo "Start / Reload DHCP Relay..."
	/bin/systemctl restart dhcp-helper

	## A little sleep
	sleep 2

	## Refresh local ARP cache
	echo "Refresh local ARP cache..."
	/sbin/ip -s -s neigh flush all
}

function stop_service {
	## Stop ARP forwarding
	echo -e "\nKilling paraprouted..."
	/usr/bin/killall -KILL parprouted 2> /dev/null

	## Stop DHCP Relay
	echo "Stoping DHCP Relay..."
	/bin/systemctl stop dhcp-helper

	## Remove assigned address
	echo "Removing attached IP to ${ETHERNET_IFACE}..."
	/sbin/ip addr del $(/sbin/ip addr show $WIRELESS_IFACE | perl -wne 'm|^\s+inet (.*)/| && print $1')/32 dev $ETHERNET_IFACE

	## Stop ethernet interface
	echo "Setting lan interface down..."
	/sbin/ip link set $ETHERNET_IFACE down

	## Disable system forwarding
	echo "Disable IP forwarding..."
	echo 0 > /proc/sys/net/ipv4/ip_forward

	## Refresh local ARP cache
	echo "Refresh local ARP cache..."
	/sbin/ip -s -s neigh flush all
}

function service_status {
	IP_FORWARDING_STATUS=$(cat /proc/sys/net/ipv4/ip_forward)
	ARP_ROUTING_PROC=$(ps aux | grep -v grep | grep -i parprouted)

	## Display network interfaces config
	echo -e "\nNetwork interfaces:\n"
	/sbin/ip -c a

	## Display IP forwarding status
	if [[ $IP_FORWARDING_STATUS == '0' ]]; then
		echo -e "\nIP forwarding: disabled"
	else
		echo -e "\nIP forwarding: enabled"
	fi

	## Display ARP routing process
	echo -e "\nARP Routing process:\n$ARP_ROUTING_PROC"

	## Display ARP table
	echo -e "\nARP table:\n"
	/usr/sbin/arp -vn

	## Display DHCP Helper status
	echo -e "\nDHCP Relay status:\n"
	/bin/systemctl status dhcp-helper
}

function generic_actions {
	## Disable wireless power management
	## Set the variable to true if your wireless speed is too low
	if [[ $DISABLE_POWER_MGMT == true ]]; then
		/sbin/iwconfig $WIRELESS_IFACE power off
	fi

	## Not related to network at all but useful for me,
	## as my keyboard does not have an English layout.
	## Set the variable KEYBOARD_LAYOUT to your layout is not in English too.
	if [[ $KEYBOARD_LAYOUT != '' ]]; then
		/usr/bin/loadkeys $KEYBOARD_LAYOUT
	fi
}

## Actions (Generic)
generic_actions

## Actions (Service)
case "$1" in
	'start')
		start_service
	;;

	'stop')
		stop_service
	;;

	'restart')
		stop_service
		sleep 5
		start_service
	;;

	'status')
		service_status
	;;

	*)
		echo -e "\nInvalid argument.\n"
	;;
esac

## End Process

set starting script as executable:

sudo chmod -v u+x /lib/systemd/system/set-arp-routing

Now save everything and check if everything is correctly setup:

# Reload systemd config
sudo systemctl daemon-reload

# Enable and start the service
sudo systemctl enable --now arp-bridge.service

# Display systemd service status
systemctl wpa_supplicant.service status arp-bridge.service

# Display custom service status
sudo /lib/systemd/system/set-arp-routing status

Try to ping any host you know and if that works then you can reboot to verify if all the proces is mounted correctly at boot time.

sudo reboot

Watch the boot process to check if you got some issues...

If you don't and everything is working for you, trust me, you're ... lucky πŸ‘.

Now log into the bridge using SSH if you're working remotely now or normally from screen. 😁

Bonus: Add a TFT screen

Before to follow the next intructions, be aware that this procedure won't work on the latest Ubuntu Server images for Raspberry Pi. I've test with models 3B/3B+/4B, all failed to load the driver with the latest image.

The only solution was to use the image Ubuntu Server 18.04.3.

Copy overlay files

Copy the DTBO and/or DTB files from your TFT screen driver in the /boot/overlay folder of the micro sd card.

Add required config

Edit the file /boot/config.txt and add this content:

# uncomment this if your display has a black border of unused pixels visible
# and your display can output without overscan
disable_overscan=1

# uncomment if hdmi display is not detected and composite is being output
hdmi_force_hotplug=1

# Enable required hardware interfaces
dtparam=spi=on
dtparam=i2c_arm=on

# Enable audio (loads snd_bcm2835)
dtparam=audio=on

# Enable serial console
enable_uart=1

# Load the TFT screen driver
dtoverlay=tft35a:rotate=90

These settings might differ depending on your TFT screen model.

The given settings are for the model tft35a.

Then change the boot command line file /boot/cmdline.txt with this content:

snd_bcm2835.enable_headphones=1 snd_bcm2835.enable_hdmi=1 snd_bcm2835.enable_compat_alsa=0 net.ifnames=0 dwc_otg.lpm_enable=0 console=serial0,115200 console=tty1 fsck.repair=yes fsck.mode=auto root=LABEL="writable" rootfstype=ext4 elevator=deadline rootwait fbcon=map:10 fbcon=font:ProFont6x11 logo.nologo

Now you can reboot and normally the TFT screen should light up during the boot and the HDMI display will not be used anymore.

Disable the TFT screen

If you need to go back on the HDMI display without having to remove everything, just comment the line loading your driver in the file /boot/config.txt that way:

# Load the TFT screen driver
#dtoverlay=tft35a:rotate=90

On the next reboot, the TFT screen will not be used and everything will going through the HDMI display.

Beware to upgrades!

After upgrading the whole system, the boot files has been upgraded too and most of them will be renamed. The correspondance with the modified files are the following:

  • /boot/config.txt -> /boot/usercfg.txt
  • /boot/cmdline.txt -> /boot/nobtcmd.txt

Note that when the system is running the /boot folder is mapped to /boot/firmware.

Bonus: Autologin + Screen + Wavemon

In this section, I'll explain how to setup the autologin + screen + wavemon.

image

The output has been truncated for privacy reasons.

Autologin

It's very simple to setup the autologin:

# Check the getty path
which getty

# Edit the getty service
sudo systemctl edit getty@tty1

Add the following content:

[Service]
ExecStart=
ExecStart=-/sbin/agetty --autologin [username] --noclear %I $TERM

Do the following changes:

  1. Replace /sbin/getty by the path given with the which command
  2. Replace [username] by the username you want to autologin

You can find more details here: https://wiki.archlinux.org/index.php/Getty#Automatic_login_to_virtual_console

Screen

Normally screen should be already installed on your systemd but if not, just run the following command:

sudo apt install screen

Wavemon

To display the wireless network activity on the TFT screen, I'm using wavemon. You can install it that way:

sudo apt install wavemon

Launch script

Now that all dependencies are installed, you can create a small launch script that will called when the session will automatically open:

#!/bin/bash

# Create an attached Screen session usable from SSH
screen -S physical bash -c '/usr/bin/wavemon'

Save the script as wireless-mon.sh and make it executable: chmod -v +x wireless-mon.sh.

Once done, add the following content in the .bashrc file to call it when the session is started:

# Load screen + wavemon
if [ $(tty) == /dev/tty1 ]; then
  sleep 2
  ~/wireless-mon.sh
fi

Now you can reboot to see the result 😁

Connect to the screen session

If everything has worked correctly, you should have a running screen session created that display the wavemon output with some nice wireless network info 🀘

To connect on that session, run the following commands:

# Connect via SSH on the remote host
ssh user@host

# List existing screen sessions
screen -ls

# Connect on the existing session
screen -x

# To disconnect without killing the screen session
[Ctrl+a] d

You can find more details here: https://linoxide.com/linux-how-to/screen-remote-ssh/

Bonus: Add some debug stuff into the wireless network service

To make sure that everything is running correctly and having more info in case of issues, create a log file for the WPA process.

Open the file /lib/systemd/system/wpa_supplicant.service and this -dd -f /tmp/wpa.log to the end of the ExecStart line:

# ExecStart=/sbin/wpa_supplicant -u -s -O /run/wpa_supplicant
ExecStart=/sbin/wpa_supplicant -u -s -O /run/wpa_supplicant -dd -f /tmp/wpa.log

This does not seems to work with netplan, you might need to kill the existing process and reload it with the given parameters above.

Do this only in case you have wireless network issues or for debugging purpose.

I've set to /tmp/wpa.log to avoid useless storage space consumption.

Bonus: Speedtest!

If you want to test the speed of your wireless bridge, you can use the script speedtest-cli that way:

python3 <(curl -Ss https://raw.githubusercontent.com/sivel/speedtest-cli/master/speedtest.py) --secure

The --secure argument is to use HTTPS instead HTTP during the test, feel free to remove it.

I've made a small script that you can use:

#!/bin/bash
python3 <(curl -Ss https://raw.githubusercontent.com/sivel/speedtest-cli/master/speedtest.py) --secure $*

Save it as speedtest.sh and make it executable with chmod -v u+x speedtest.sh.

Then you can run it that way:

# Get help
./speedtest.sh --help

# Get server list
./speedtest.sh --list

# Use a specific server
./speedtest.sh --server <server-id>

Main issue: ethernet not up

Sometimes the LAN interface is not started, the following might solve this issue:

# Re-Apply networking configuration
sudo netplan --debug apply

# Or manually set the network interface up
sudo ip link set eth0 up

Change eth0 by your interface name

Really useful commands for debugging

During my debugging process I used these commands to help me to solve all encountered issues:

sudo loadkeys keyboard_country_code
sudo lshw
ifconfig
iwconfig
iw list
iw dev
iw phy
sudo iw dev wlan0 scan sched_stop
sudo iw dev wlan0 scan
ip link show
ip a
ip route
sudo rfkill list
sudo rfkill unblock wifi
networkctl
journalctl -b
journalctl -f
dmesg
dmesg -w
sudo wpa_cli status
sudo wpa_cli interface_list
sudo netstat -s | egrep -i 'loss|retran'
host -a google.com
host -a ubuntu.com
iwlist 
iwlist wlan0
sudo iwlist wlan0 scan
sudo iwlist wlan0 scan | grep ESSID
locate wpa
sudo ip link set wlan0 down
sudo ip link set wlan0 up
sudo iw reg get
sudo iw reg set CH
sudo nmcli radio wifi on
sudo nmtui
nmcli dev show wlan0
nmcli device wifi
nmcli device wifi rescan
sudo iwlist wlan0 scan
arp -avn
sudo su -c 'echo 1 > /proc/sys/net/ipv4/conf/all/proxy_arp'
sudo su -c 'echo 1 > /proc/sys/net/ipv4/ip_forward'
sudo sysctl -a | grep forward
sudo sysctl -a | grep proxy
sudo sysctl -w net.ipv4.ip_forward=1
sudo sysctl -w net.ipv4.conf.all.proxy_arp=1

Used debug script

During my research, I've found this debugging script: https://github.com/UbuntuForums/wireless-info/raw/master/wireless-info

Use it as follow:

wget https://github.com/UbuntuForums/wireless-info/raw/master/wireless-info && chmod +x wireless-info && ./wireless-info

Reply 'no' to not upload results outside

Show the report:

less wireless-info.txt

You should not plug 2 wireless bridges on the same switch, Never!

It was another hard lesson that I've learned during this project / gist, never plug several bridges on the same switch, it will just create massive TPC/UDP retransmission and ARP flood... πŸ˜“

Story

Well... I must tell you that I've passed around 3 days in reading, testing, debugging and getting crazy then finaly make it working πŸ˜….

And even more to understand why my not all of my DHCP requests were not relayed to the my main DHCP Server on the router... But after many days of testing and research I was finally able to find why. More details here https://twitter.com/Jiab77/status/1107535593741922304

I really hope that you'll be able to make the whole process working on your side.

Contribute

Feel free to comment this gist for improvements or if you're having troubles πŸ‘.

Big thanks

I'd like to give a big thanks to someone who helped me to solve the screen issues I got, Klimi from the Hack+ Telegram group.

Contact

You can reach me on Twitter by using @Jiab77.

References

During my research it was really difficult to find up-to-date, clean and working documentation so I had to grab and mix many of them to write this gist. (no specific order)

  1. https://wiki.ubuntu.com/ARM/RaspberryPi
  2. http://cdimage.ubuntu.com/ubuntu/releases/18.04.3/release/
  3. https://ubuntuforums.org/showthread.php?t=2274207
  4. https://wiki.debian.org/BridgeNetworkConnectionsProxyArp
  5. https://github.com/balena-io-playground/balena-bridge/blob/master/start.sh
  6. https://www.freedesktop.org/software/systemd/man/systemd.exec.html
  7. https://www.freedesktop.org/software/systemd/man/systemd.service.html
  8. https://unix.stackexchange.com/questions/348450confused-by-execstartpre-entries-in-systemd-unit-file
  9. https://netplan.io/faq#use-pre-up-post-up-etc-hook-scripts
  10. https://hk.saowen.com/a873f9d84ef3c295c9ea73174de8758f972d73e32434d6c332ddd72bd2a4e4441
  11. https://unix.stackexchange.com/questions/126009cause-a-script-to-execute-after-networking-has-started
  12. https://websiteforstudents.com/configure-static-ip-addresses-on-ubuntu-18-04-beta/
  13. https://medium.com/@benmorel/creating-a-linux-service-with-systemd-611b5c8b91d6
  14. https://bbs.archlinux.org/viewtopic.php?id=230785
  15. https://www.tecmint.com/create-new-service-units-in-systemd/
  16. https://unix.stackexchange.com/questions/319267systemd-how-to-make-a-systemd-service-start-after-network-fully-connected/319330
  17. https://superuser.com/questions/544399how-do-you-make-a-systemd-service-as-the-last-service-on-boot
  18. https://www.cyberciti.biz/faq/howto-set-sysctl-variables/
  19. https://access.redhat.com/documentation/en-US/Red_Hat_Enterprise_MRG/1.3/htmlRealtime_Tuning_Guidesect-Realtime_Tuning_Guide-General_System_Tuning-Setting_persistent_tuning_parametershtml
  20. https://linuxize.com/post/how-to-change-hostname-on-ubuntu-18-04/
  21. https://cloudinit.readthedocs.io/en/latest/topics/network-config.html
  22. https://pimylifeup.com/raspberry-pi-wifi-bridge/
  23. https://medium.com/a-swift-misadventurehow-to-setup-your-raspberry-pi-2-3-with-ubuntu-16-04-without-cables-headlessly-9e3eaad2c01
  24. https://askubuntu.com/questions/1045389ubuntu-18-on-raspberry-pi-3b-stuck-on-networking-service-after-converting-the-o
  25. https://askubuntu.com/questions/1071517trying-to-install-18-04-classic-on-pi-3-b-close-but-not-quite-there?rq=1
  26. https://raspberrypi.stackexchange.com/questions/499how-can-i-resize-my-root-partition
  27. https://community.arubanetworks.com/t5/Controller-Based-WLANsDHCP-packet-flow-with-bootp-flag-set-to-broadcast-vs-unicast/ta-p/425012
  28. https://superuser.com/questions/472594/dhcp-broadcast-flag/472607#472607
  29. https://www.ietf.org/rfc/rfc2131.txt
  30. https://wiki.archlinux.org/index.php/Getty#Automatic_login_to_virtual_console
  31. https://linoxide.com/linux-how-to/screen-remote-ssh/

Made with ❀️ and A LOT of β˜•!! by @jiab77

#!/bin/bash
## ARP Routing Management Script
## Made by Jiab77 <jonathan.barda@gmail.com>
## Config
ETHERNET_IFACE=eth0
WIRELESS_IFACE=wlan0
KEYBOARD_LAYOUT=ch
DISABLE_POWER_MGMT=true
## Help
if [ $# -eq 0 ]; then
echo -e "\nUsage: $0 action [start|stop|restart|status]\n"
exit
fi
## Functions
function start_service {
## Setup system forwarding
echo -e "\nEnable IP forwarding..."
echo 1 > /proc/sys/net/ipv4/ip_forward
## Uncomment lines below if you don't want to use parprouted.
#echo "Enable ARP forwarding"
# Comment for all interfaces
#echo 1 > /proc/sys/net/ipv4/conf/${WIRELESS_IFACE}/proxy_arp
# Uncomment for all interfaces
#echo 1 > /proc/sys/net/ipv4/conf/all/proxy_arp
## Fix the 'eth0' interface that don't want to mount at boot on 3b+
## Uncomment this part if the 'eth0' interface is not mounted at boot
#/usr/sbin/netplan apply
## A little sleep
sleep 2
## Assign address
echo "Cloning IP from ${WIRELESS_IFACE} to ${ETHERNET_IFACE}..."
/sbin/ip addr add $(/sbin/ip addr show $WIRELESS_IFACE | perl -wne 'm|^\s+inet (.*)/| && print $1')/32 dev $ETHERNET_IFACE
## Uncomment lines below in case you're encountering the same issues
#echo "Removing bad APIPA IP from ${ETHERNET_IFACE}"
#/sbin/ip addr del $(/sbin/ip addr show $ETHERNET_IFACE | perl -wne 'm|^\s+inet (169.254.*)/| && print $1')/16 dev $ETHERNET_IFACE
#echo "Removing bad APIPA route from ${ETHERNET_IFACE}"
#/sbin/ip route del 169.254.0.0/16 dev $ETHERNET_IFACE
## Make sure that the eth0 interface is up
echo "Setting up lan interface..."
/sbin/ip link set $ETHERNET_IFACE up
## Setup ARP forwarding
echo "Starting paraprouted..."
/usr/bin/killall -KILL parprouted 2> /dev/null
/usr/sbin/parprouted $ETHERNET_IFACE $WIRELESS_IFACE
## Reloading DHCP Relay
echo "Start / Reload DHCP Relay..."
/bin/systemctl restart dhcp-helper
## A little sleep
sleep 2
## Refresh local ARP cache
echo "Refresh local ARP cache..."
/sbin/ip -s -s neigh flush all
}
function stop_service {
## Stop ARP forwarding
echo -e "\nKilling paraprouted..."
/usr/bin/killall -KILL parprouted 2> /dev/null
## Stop DHCP Relay
echo "Stoping DHCP Relay..."
/bin/systemctl stop dhcp-helper
## Remove assigned address
echo "Removing attached IP to ${ETHERNET_IFACE}..."
/sbin/ip addr del $(/sbin/ip addr show $WIRELESS_IFACE | perl -wne 'm|^\s+inet (.*)/| && print $1')/32 dev $ETHERNET_IFACE
## Stop ethernet interface
echo "Setting lan interface down..."
/sbin/ip link set $ETHERNET_IFACE down
## Disable system forwarding
echo "Disable IP forwarding..."
echo 0 > /proc/sys/net/ipv4/ip_forward
## Refresh local ARP cache
echo "Refresh local ARP cache..."
/sbin/ip -s -s neigh flush all
}
function service_status {
IP_FORWARDING_STATUS=$(cat /proc/sys/net/ipv4/ip_forward)
ARP_ROUTING_PROC=$(ps aux | grep -v grep | grep -i parprouted)
## Display network interfaces config
echo -e "\nNetwork interfaces:\n"
/sbin/ip -c a
## Display IP forwarding status
if [[ $IP_FORWARDING_STATUS == '0' ]]; then
echo -e "\nIP forwarding: disabled"
else
echo -e "\nIP forwarding: enabled"
fi
## Display ARP routing process
echo -e "\nARP Routing process:\n$ARP_ROUTING_PROC"
## Display ARP table
echo -e "\nARP table:\n"
/usr/sbin/arp -vn
## Display DHCP Helper status
echo -e "\nDHCP Relay status:\n"
/bin/systemctl status dhcp-helper
}
function generic_actions {
## Disable wireless power management
## Set the variable to true if your wireless speed is too low
if [[ $DISABLE_POWER_MGMT == true ]]; then
/sbin/iwconfig $WIRELESS_IFACE power off
fi
## Not related to network at all but useful for me,
## as my keyboard does not have an English layout.
## Set the variable KEYBOARD_LAYOUT to your layout is not in English too.
if [[ $KEYBOARD_LAYOUT != '' ]]; then
/usr/bin/loadkeys $KEYBOARD_LAYOUT
fi
}
## Actions (Generic)
generic_actions
## Actions (Service)
case "$1" in
'start')
start_service
;;
'stop')
stop_service
;;
'restart')
stop_service
sleep 5
start_service
;;
'status')
service_status
;;
*)
echo -e "\nInvalid argument.\n"
;;
esac
## End Process
@Jiab77

This comment has been minimized.

Copy link
Owner Author

@Jiab77 Jiab77 commented Nov 4, 2018

In case you wanted used files directly, check the revisions. I just removed them for better indexing... πŸ™„

@Jiab77

This comment has been minimized.

Copy link
Owner Author

@Jiab77 Jiab77 commented Jul 2, 2019

The routing script has been updated and now use interfaces as variables to it will ease the further changes.

@fahadsiddiqui

This comment has been minimized.

Copy link

@fahadsiddiqui fahadsiddiqui commented Jul 27, 2019

Wow, perfect!

@Jiab77

This comment has been minimized.

Copy link
Owner Author

@Jiab77 Jiab77 commented Aug 8, 2019

@fahadsiddiqui glad you liked it!

@Jiab77

This comment has been minimized.

Copy link
Owner Author

@Jiab77 Jiab77 commented Aug 25, 2019

I've update the used sd-card images and cleaned the whole gist.

@Jiab77

This comment has been minimized.

Copy link
Owner Author

@Jiab77 Jiab77 commented Apr 15, 2020

New update!

  • Added new launch script
  • Added bonus sections
  • Updated instructions
@egll-tech

This comment has been minimized.

Copy link

@egll-tech egll-tech commented Aug 13, 2020

I hope that you don't mind, but I made a script to install everything in a simple command (except for the netplan config). Is it ok with you if I publish it? I'm giving you credits for the tutorial and the script is really similar, excluding the keyboard part
Here is the link https://gist.github.com/egll-tech/00a097355aac03d05a5a2a023ae48873 so you can use it executing

curl -sL https://gist.githubusercontent.com/egll-tech/00a097355aac03d05a5a2a023ae48873/raw/ | sudo -E bash -
@Jiab77

This comment has been minimized.

Copy link
Owner Author

@Jiab77 Jiab77 commented Aug 13, 2020

Of course not, I don't mind at all! And you credited me very well 🀩
So, thanks a lot! I'm very honored and the code in your script is pretty nice!
I'm very happy to see that my work is becoming useful for others πŸ‘

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.