Milesight 4G Router configuration

From Sensors in Schools
Jump to navigation Jump to search

Introduction

  • The Milesight 4G router is being used to connect the Raspberry Pi (BirdNET-Pi) computer to the 4G network and hence the internet.
  • The Milesight 4G router behaves in a similar way to a home internet router.
  • The Milesight 4G router can also be used to access the Raspberry pi computer from the internet using SSH (Secure Shell).
  • These instructions will explain how to configure the Milesight router.

Milesight Menu Navigation

  • Status
    • Overview
    • Cellular
    • Network


Network > Interface > Bridge Setting

  • Initially there was a conflict between the Milesight local network and the WiFi local network sharing the same IP address range.
  • The Bridge Setting on the Milesight router was changed:
    • IP Address changed from 192.168.1.1 to 192.168.2.1
    • The Netmask was kept the same.

Raspberry Pi Network Configuration Changes

  • Click on the WiFi Network on the Raspberry Pi

  • Assign the priority number 2
  • Disable All users may connect to this network
  • Save settings

  • Edit the Wired Connection 1 for the Local Ethernet connection to the Milesight router
  • Assign a low priority setting of -999. This means that the primary connection will be the WiFi network - when available.
  • Enable All users may connect to this network
  • Save settings.


Status > Overview

Maintenance > Tools > Ping

Maintenance > Tools > Tracerouter

Maintenance > DHCP Server

  • In this case, the Raspberry Pi connected to the Milesight router was assigned a local IP address 192.168.2.50 using the Raspberry Pi MAC address assigned to the Ethernet network eth0.

  • Use ifconfig on the Raspberry Pi to find the MAC Address for the local ethernet connection eth0.

Network > Firewall > Security > Access Service Control

  • Open remote ports for:
  • HTTP
  • HTTPS
  • SSH - and assign a unique port number for SSH that is above 2000 (preferably 5 digit port number). Close this port is not using SSH.

Network > Firewall > Port Mapping

  • Assign port mapping on the Milesight router to support SSH access from a remote computer.
  • Note - that in this case the SIM card provider prevented SSH access.

Resolving Network Address Range Conflict

  • When the Milesight Router was initially connected to the Raspberry Pi (BirdNET-Pi) the Raspberry Pi was also connected using WiFi to my home router.
  • Unfortuately both networks shared the same address range which was 192.168.1.* and the same
  • To resolve this conflict the Home address was left as 192.168.1.* (255.255.255.0)
  • The Milestream address range was reconfigured to 192.168.2.* (255.255.255.0)

IP Address Conflict

When a computer is connected to two networks, and both of these networks share the same address range, such as both using the IP address range 192.168.1.*, it can lead to what is known as an "IP address conflict." An IP address conflict occurs when two devices on the same network segment (in this case, the computer connected to both networks) have been assigned the same IP address. This situation can result in various networking issues:

  • Communication Problems: The computer may experience communication problems because it doesn't know which network to send data to when trying to reach a device with the same IP address on both networks. This can lead to intermittent connectivity issues or complete loss of network connectivity.
  • Duplicate IP Detection: Modern network protocols have mechanisms to detect IP address conflicts. When a device detects that another device on the same network has the same IP address, it may trigger an error message or attempt to resolve the conflict by changing its IP address.
  • Unpredictable Behavior: The behavior of the computer in such a situation can be unpredictable. It might use one network for certain traffic and the other network for other traffic, leading to inconsistent results.

To resolve IP address conflicts when a computer is connected to multiple networks, you should:

Configure Unique IP Addresses: Ensure that each network assigns unique IP addresses to devices. This usually involves adjusting the DHCP (Dynamic Host Configuration Protocol) settings on one or both of the networks to use different address ranges.

  • Static IP Assignment: If you have control over the IP assignments, consider statically assigning IP addresses to devices on one or both networks to avoid conflicts.
  • Network Segmentation: In cases where you have multiple networks with overlapping address ranges, consider segmenting your networks using routers or VLANs (Virtual Local Area Networks). This way, you can control the routing between networks and avoid IP conflicts.
  • Subnetting: Implement subnetting to divide your networks into smaller subnetworks with distinct address ranges. This can help prevent address conflicts and manage IP address allocation more efficiently.

By ensuring that each device on your networks has a unique IP address within its respective network segment, you can prevent IP address conflicts and maintain stable and predictable network communication.


Subnet Mask

The term you're referring to, "net mask," is more commonly known as the "subnet mask" in networking. The subnet mask is a 32-bit number that is used to divide an IP address into network and host portions. It's a fundamental component of the IP addressing scheme and is used to determine which part of an IP address belongs to the network and which part belongs to the individual host within that network.

In the format you provided, 255.255.255.0, this subnet mask is expressed in dotted-decimal notation, where each of the four octets represents 8 bits. In this example:

  • The leftmost three octets (255.255.255) are set to all ones (binary 1s), indicating the network portion of the IP address.
  • The rightmost octet (0) is set to all zeros (binary 0s), indicating the host portion of the IP address.
  • This subnet mask corresponds to a Class C network and allows for up to 254 host addresses within that network. The first and last addresses (with all zeros and all ones in the host portion) are typically reserved for network address (identifying the network itself) and broadcast address (broadcasting messages to all hosts on the network), respectively, leaving 252 usable host addresses.

Here's a breakdown:

  • Network Portion: 255.255.255.0
  • Host Portion: 0.0.0.255 (the host portion, which allows 8 bits for hosts)

The subnet mask plays a crucial role in determining network boundaries, routing, and IP address allocation within a network. Different subnet masks can be used to create networks of varying sizes, from small local networks to large global networks, by dividing the available address space accordingly.

Connect to Remote Raspberry Pi computer that has no GUI Interface

To install TeamViewer on a Raspberry Pi without a GUI interface (headless installation), you can use the TeamViewer Host version. Here are the steps to install TeamViewer on a headless Raspberry Pi:

  • Access Your Raspberry Pi: You'll need to have SSH access to your Raspberry Pi. Connect to it using SSH from another computer. Alternatively, you can also configure the Raspberry Pi directly (prior to deployment into the field. This is easier and more secure because you don't need to enable SSH.
  • Download TeamViewer Host:
    • Visit the TeamViewer download page for Raspberry Pi using a web browser: TeamViewer Raspberry Pi Download.
    • Look for the TeamViewer Host for Raspberry Pi section.

    • Right-click on the appropriate download link (choose 64-bit version for BirdNET-Pi) based on your Raspberry Pi model (e.g., Raspberry Pi 3 or Raspberry Pi 4) and choose "Copy link address" from the context menu.

https://download.teamviewer.com/download/linux/teamviewer_arm64.deb
  • Download TeamViewer:
  • On your Raspberry Pi, use wget to download TeamViewer.
wget https://download.teamviewer.com/download/linux/teamviewer_arm64.deb
  • Install TeamViewer:- Install TeamViewer using dpkg. Replace <downloaded-package.deb> with the actual filename you downloaded. This will install TeamViewer without any GUI components.
sudo dpkg -i teamviewer_arm64.deb
sudo apt-get install -f
  • Set Up TeamViewer: Now, you can set up TeamViewer to work with your TeamViewer account by running the following command:
sudo teamviewer setup

Follow the on-screen instructions to set up TeamViewer, including signing in with your TeamViewer account or creating one if you don't have an account yet. You will be asked to sign in to your TeamViewer account. Once signed in, an email will be sent to your email address asking for the addition of the remote computer to be verified.

  • Click Add to Trusted Devices

  • Start TeamViewer: After setting up TeamViewer, you can start it by running:
sudo teamviewer daemon start

Access the Raspberry Pi: You can now access and control your headless Raspberry Pi using TeamViewer from another computer. Remember that you will need to have an active internet connection on both your Raspberry Pi and the computer you use to access it via TeamViewer.

SIM Card options

  • Telstra SIM cards block access via SSH
  • Optus SIM cards can allow for a static IP address that will then permit access via SSH

VNC option

  • Note that even thought you can enable VNC using sudo raspi-config - it will not work via a remote computer.
  • VNC requires a GUI interface. This is not available using CLI (Command Line Interface.

Testing 4G Connection - Turning local WiFi Off

To turn off the Wi-Fi on a Raspberry Pi using the command line, you can use the ifconfig or ip commands. Here are the steps for ifconfig:

  • Open a terminal window on your Raspberry Pi.
  • Check the name of your Wi-Fi interface.
  • This is typically named wlan0, but it may vary depending on your configuration. You can use the following command to list all network interfaces.
ifconfig -a
  • Look for the entry corresponding to your Wi-Fi interface.
  • To turn off the Wi-Fi interface, use the following command, replacing <interface_name> with the name of your Wi-Fi interface (e.g., wlan0).
  • This is useful during testing to force the Raspberry Pi to use the 4G Router connection to the internet.
sudo ifconfig wlan0 down
  • To turn the Wi-Fi interface back on, use the following command, replacing <interface_name> with the name of your Wi-Fi interface (e.g., wlan0):
sudo ifconfig wlan0 down

Disabling WiFi on Remote Device using rfkill

The rfkill command in Linux is used to manage wireless devices, specifically for blocking or unblocking them. It is a useful tool for controlling radio frequency (RF) devices, including Wi-Fi, Bluetooth, and other wireless interfaces. Here's how to use the rfkill command:

Usage: To view the status of all RF devices, open a terminal and simply type one of the following commands. This command will list all RF devices along with their status (blocked or unblocked).

rfkill list
rfkill list --output-all


Common Options:

  • rfkill block <device>: This command is used to block a specific device. Replace <device> with the device number or name (e.g., wlan, bluetooth, etc.).
  • rfkill unblock <device>: This command is used to unblock a specific device. Again, replace <device> with the device number or name.
  • Example: To block a Wi-Fi device (e.g., wlan0), you can use the following command:


sudo rfkill block wlan

This will disable Wi-Fi on your system. To unblock the same Wi-Fi device and re-enable it, you can use:

sudo rfkill unblock wlan

Why use rfkill: rfkill is particularly useful when you want to:

  • Temporarily disable Wi-Fi or other wireless devices to save power when not in use.
  • Troubleshoot Wi-Fi or Bluetooth connectivity issues by turning off and on the respective devices.
  • Manage wireless radios on systems with hardware Wi-Fi or Bluetooth switches that may not be easily accessible through software.
  • Script or automate the management of wireless devices on your Linux system.
  • Keep in mind that rfkill requires superuser (root) privileges to block or unblock devices, so you'll need to prefix the commands with sudo if you're not already logged in as the superuser.

Setting up SSH (Secure Shell) using the Terminal on Raspberry Pi

  • Assign a different SSH port number to the router.
  • The default port number for SSH is port 22.
  • In this case the SSH port number was set to 4323 - and both local and remote access was permitted.

  • Edit the file /etc/ssh/sshd_config with the command:
sudo nano /etc/ssh/sshd_config
  • Add the following line to the file Port 4323 as shown.
  • Save and exit nano. (Use the Ctrl+X command)

  • Restart the SSH server with the command sudo systemctl restart sshd
  • The command sudo systemctl restart sshd on a Raspberry Pi (or any Linux system that uses systemd) is used to restart the SSH (Secure Shell) server. Here's what each part of the command does:
    • sudo: It's a command that allows you to run other commands with superuser (administrator) privileges. This is often required for system-level operations.
    • systemctl: This is a command used to control the systemd system and service manager, which is responsible for managing various aspects of the Linux system, including services.
    • restart: This subcommand instructs systemctl to restart the specified service.
    • sshd: This is the name of the SSH server service. The "d" in "sshd" stands for "daemon," which is a type of background process that runs continuously.

So, when you run sudo systemctl restart sshd, you are telling the system to restart the SSH server. This can be useful if you've made changes to the SSH configuration and you want those changes to take effect without having to reboot the entire system.

  • To access the computer using SSH enter the following command.
ssh -p 4323 pi400ssd@192.168.1.152

The command will establish an SSH (Secure Shell) connection to a remote Raspberry Pi computer located at the IP address 192.168.1.152 on port 4323, using the username pi400ssd.

  • ssh: This is the command to start an SSH session.
  • -p 4323: This option specifies the port number to connect to. In this case, it's port 4323. By default, SSH uses port 22, but you can specify a different port if the SSH server on the remote Raspberry Pi is configured to listen on a different port.
  • pi400ssd: This is the username you are using to log in to the remote Raspberry Pi. You will need to provide the corresponding password or authentication method for this user.
  • @192.168.1.152: This is the IP address of the remote Raspberry Pi you want to connect to. You need to replace this with the actual IP address of your Raspberry Pi.

When you run this command, it will prompt you for the password or authentication method for the pi400ssd user, and if successful, it will establish an SSH session to the remote Raspberry Pi, allowing you to run commands on it remotely.