Category: Linux

ZTE MF79N on OpenWRT ( Wifi PineApple )

With these simple configurations, you can perform the network setup on OpenWrt for the ZTE MF79N. Configuring DHCP for eth2 ensures the automatic assignment of IP addresses, while USB mode switching enables the modem’s network functionality.

Install USB Modeswitch

root@Pineapple:~# opkg update
Downloading https://downloads.hak5.org/packages/mk6/190702/Packages.gz
Updated list of available packages in /var/opkg-lists/190702_pineapple
Downloading https://downloads.openwrt.org/releases/packages-19.07/mips_24kc/base/Packages.gz
Updated list of available packages in /var/opkg-lists/1907_base
Downloading https://downloads.openwrt.org/releases/packages-19.07/mips_24kc/packages/Packages.gz
Updated list of available packages in /var/opkg-lists/1907_packages
Downloading https://downloads.openwrt.org/releases/packages-19.07/mips_24kc/routing/Packages.gz
Updated list of available packages in /var/opkg-lists/1907_routing
Bash
root@Pineapple:~# opkg install usb-modeswitch
Package usb-modeswitch (2017-12-19-f40f84c2-2) installed in root is up to date.
Bash

Edit the USB Modeswitch Configuration File

Navigate to the /etc/usb-mode.json file and add the following entry for the ZTE MF79N at the end of the file

"19d2:1225": {
    "*": {
        "t_vendor": 6610,
        "t_product": [ 5125 ],
        "mode": "StandardEject",
        "msg": [ 34 ]
    }
}
/etc/usb-mode.json

This configuration specifies the necessary parameters for modeswitching, allowing the ZTE MF79N to transition to the desired network mode.

it should look like this

check interface status

now you can check if the interface works correctly, probably its currently DOWN

which is ok for now

root@Pineapple:~# ip a
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN qlen 1000
    link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
    inet 127.0.0.1/8 scope host lo
       valid_lft forever preferred_lft forever
    inet6 ::1/128 scope host
       valid_lft forever preferred_lft forever
--- snip ---

--- snap ---
13: eth2: <BROADCAST,MULTICAST> mtu 1500 qdisc noop state DOWN qlen 1000
    link/ether 5f:3b:60:00:00:00 brd ff:ff:ff:ff:ff:ff
Bash

Assign an IP address over DHCP

to it with the OpenWRT dhcp client

root@Pineapple:~# udhcpc -i eth2
udhcpc: started, v1.30.1
udhcpc: sending discover
udhcpc: sending select for 192.168.0.101
udhcpc: lease of 192.168.0.101 obtained, lease time 86400
udhcpc: ifconfig eth2 192.168.0.101 netmask 255.255.255.0 broadcast 192.168.0.255
udhcpc: setting default routers: 192.168.0.1
Bash

add permanent network config for eth2

add eth2 interface to /etc/config/network ( the interface can be different )
check with dmesg which interface you get

config interface 'eth2'
        option ifname 'eth2'
        option proto 'dhcp'
        option dns '8.8.8.8, 8.8.4.4'
/etc/config/network

Plug in the ZTE USB Router

output of dmesg

root@Pineapple:~# dmesg
---- snip ----

---- snap ----
[ 1638.852858] usb 1-1: USB disconnect, device number 19
[ 1638.860391] cdc_ether 1-1:1.0 eth2: unregister 'cdc_ether' usb-ehci-platform-1, ZTE CDC Ethernet Device
[ 1659.119471] usb 1-1: new high-speed USB device number 20 using ehci-platform
[ 1659.324332] usb-storage 1-1:1.0: USB Mass Storage device detected
[ 1659.340015] usb-storage 1-1:1.0: Quirks match for vid 19d2 pid 1225: 1
[ 1659.354214] scsi host0: usb-storage 1-1:1.0
[ 1662.998352] usb 1-1: USB disconnect, device number 20
[ 1664.669459] usb 1-1: new high-speed USB device number 21 using ehci-platform
[ 1664.879602] cdc_ether 1-1:1.0 eth2: register 'cdc_ether' at usb-ehci-platform-1, ZTE CDC Ethernet Device, 5f:3b:60:00:00:00
[ 1664.894248] cdc_ether 1-1:1.0 eth2: kevent 12 may have been dropped
[ 1664.904535] cdc_ether 1-1:1.0 eth2: kevent 11 may have been dropped
[ 1664.921138] usb-storage 1-1:1.2: USB Mass Storage device detected
[ 1664.938806] scsi host0: usb-storage 1-1:1.2
[ 1665.568740] usb 1-1: USB disconnect, device number 21
[ 1665.589516] cdc_ether 1-1:1.0 eth2: unregister 'cdc_ether' usb-ehci-platform-1, ZTE CDC Ethernet Device
[ 1666.399501] usb 1-1: new high-speed USB device number 22 using ehci-platform
[ 1666.634377] usb-storage 1-1:1.0: USB Mass Storage device detected
[ 1666.649404] usb-storage 1-1:1.0: Quirks match for vid 19d2 pid 1225: 1
[ 1666.661721] scsi host0: usb-storage 1-1:1.0
[ 1670.325566] usb 1-1: USB disconnect, device number 22
[ 1671.219562] usb 1-1: new high-speed USB device number 23 using ehci-platform
[ 1671.439610] cdc_ether 1-1:1.0 eth2: register 'cdc_ether' at usb-ehci-platform-1, ZTE CDC Ethernet Device, 5f:3b:60:00:00:00
[ 1671.454146] cdc_ether 1-1:1.0 eth2: kevent 12 may have been dropped
[ 1671.468024] cdc_ether 1-1:1.0 eth2: kevent 11 may have been dropped
[ 1671.500521] usb-storage 1-1:1.2: USB Mass Storage device detected
[ 1671.526190] scsi host0: usb-storage 1-1:1.2
[ 1672.581397] scsi 0:0:0:0: CD-ROM            ZTE USB  SCSI CD-ROM 2.31      PQ: 0 ANSI: 2
[ 1672.590456] scsi 0:0:0:0: Attached scsi generic sg0 type 5
[ 1672.650434] scsi 0:0:0:1: Direct-Access     ZTE MMC  Storage 2.31          PQ: 0 ANSI: 2
[ 1672.659765] sd 0:0:0:1: Attached scsi generic sg1 type 0
[ 1672.672069] sd 0:0:0:1: [sda] Attached SCSI removable disk
JSON

check internet connectivity

root@Pineapple:~# ping megadodo.org -c 4
PING megadodo.org (51.255.232.79): 56 data bytes
64 bytes from 51.255.232.79: seq=0 ttl=49 time=313.202 ms
64 bytes from 51.255.232.79: seq=1 ttl=49 time=59.762 ms
64 bytes from 51.255.232.79: seq=2 ttl=49 time=65.040 ms
64 bytes from 51.255.232.79: seq=3 ttl=49 time=61.236 ms

--- megadodo.org ping statistics ---
4 packets transmitted, 4 packets received, 0% packet loss
round-trip min/avg/max = 59.762/124.810/313.202 ms
root@Pineapple:~#
Java

Ensuring Internet Connectivity with Multiple Network Interfaces on Linux

In scenarios where a Linux system has multiple network interfaces, maintaining internet connectivity even if one interface goes down becomes crucial. This blog post will guide you through the process of setting up a routing table with multiple gateways and metrics to ensure a seamless switch between interfaces.

Identifying Gateways

Before configuring the routing table, identify the IP addresses of the gateways associated with each network interface. This information will be used to set up default routes with different metrics.

Setting Up the Routing Table

  1. Open the routing table configuration file, typically located at /etc/network/interfaces or /etc/sysconfig/network-scripts/route-interface.
  2. Add the default routes with distinct metrics for each interface. Here’s an example for eth0 and ppp0 in the /etc/network/interfaces file:
auto eth0
iface eth0 inet dhcp
    post-up route add default via <eth0_gateway> metric 100

auto ppp0
iface ppp0 inet ppp
    post-up route add default via <ppp0_gateway> metric 200
Bash

Replace <eth0_gateway> and <ppp0_gateway> with the actual gateway IP addresses for eth0 and ppp0.

Applying the Changes

After editing the configuration file, restart the networking service or the system for the changes to take effect:

sudo service networking restart
Bash

Alternatively, manually add the routes using the ip route command:

sudo ip route add default via <eth0_gateway> metric 100
sudo ip route add default via <ppp0_gateway> metric 200
Bash

Testing the Configuration

Disconnect one of the interfaces and verify that the system maintains internet connectivity. The configured routing table should automatically switch to the other route with a higher metric.

Conclusion

Configuring a robust routing table with multiple gateways and metrics on a Linux system is a valuable strategy to ensure continuous internet connectivity, even in the event of one interface going down. By following these steps, you can enhance the reliability of your network configuration and minimize downtime. Adjust the metric values according to your specific requirements and network conditions.

Achieving Redundant Internet Connectivity in Python: Handling Multiple Network Interfaces

In scenarios where a Linux system relies on Python for network management, ensuring uninterrupted internet connectivity, even when one network interface goes down, is crucial. This blog post will guide you through using Python and the subprocess module to set up a reliable system capable of seamlessly switching between interfaces.

Python Script for Interface Ping Tests:

import subprocess

def ping_interface(interface, destination_ip):
    try:
        command = f"ping -I {interface} -c 4 {destination_ip}"
        result = subprocess.run(command, shell=True, check=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE, text=True)
        print(f"Ping result for {interface}:")
        print(result.stdout)
    except subprocess.CalledProcessError as e:
        print(f"Error pinging {destination_ip} over {interface}: {e.stderr}")

# Replace 'eth0' and 'ppp0' with your actual interface names
ping_interface('eth0', '8.8.8.8')
ping_interface('ppp0', '8.8.8.8')
Python
  1. Import the subprocess module for executing shell commands.
  2. Define a function, ping_interface, that takes an interface name and a destination IP address as parameters.
  3. Construct the ping command using the specified interface and destination IP.
  4. Use subprocess.run to execute the command, capturing the result.
  5. Print the ping result or handle any exceptions that may occur.
  6. Replace ‘eth0’ and ‘ppp0’ with your actual interface names and ‘8.8.8.8’ with the IP address you want to ping.

Conclusion

By utilizing Python and the subprocess module, you can easily implement a script to test ping connectivity over different network interfaces. This approach allows you to monitor the status of each interface, facilitating proactive management and ensuring continuous internet connectivity. Incorporate this script into your network management toolkit to enhance the reliability of your Python-based network applications.