Network login

  • Static IP script presented in Wiki has two flaws:
    1. It requires presence of DHCP server to work. It will not assign static IP without first going through DHCP.
    2. If the module is powered on without Eth connection it will not activate eth0 device at all. It will stay down without any IP address.

    How to reliably assign static IP regardless of network status during boot up?
  • pstaw wrote: 2024-03-01 8:20 Static IP script presented in Wiki has two flaws:
    1. It requires presence of DHCP server to work. It will not assign static IP without first going through DHCP.
    2. If the module is powered on without Eth connection it will not activate eth0 device at all. It will stay down without any IP address.

    How to reliably assign static IP regardless of network status during boot up?


    Hello, due to an issue with the rk_gmac-dwmac driver, the network connection is reset when the Ethernet cable is unplugged or plugged in. This results in the loss of the assigned inet address that was set temporarily using ifconfig.

    One workaround for this is to create a script that runs in the background to monitor the network status of eth0. If the IP address is lost (e.g., due to unplugging or plugging in the Ethernet cable), the script will use ifconfig to set the IP address again.

    This approach provides a reliable way to set a static IP address when the network connection is stable.

    Code: Select all

    #! /bin/sh
    
    check_ip_address(){
            if ifconfig eth0 | grep -q "inet "; then
                    return 1
            else
                    return 0
            fi
    }
    
    static_ip()
    {
            while true; do
                    if check_ip_address; then
                            ifconfig eth0 169.254.128.100 netmask 255.255.0.0
                            route add default gw 169.254.128.123
                            echo "nameserver 8.8.8.8" > /etc/resolv.conf
    
                    fi
                    sleep 5
            done
    }
    
    
    case $1 in
            start)
                    echo "start"
    		ifconfig eth0 169.254.128.100 netmask 255.255.0.0
    		route add default gw 169.254.128.123
    		echo "nameserver 8.8.8.8" > /etc/resolv.conf
                    static_ip &
                    ;;
            stop)
                    echo "stop"
                    ;;
            *)
    		exit 1
                    ;;
    esac
    
    You could try to comment out the sections related to udhcpc in /oem/usr/bin/RkLunch.sh to ensure that the first assigned IP for luckfox-pico upon boot-up is the configured static IP.

    Hope this helps, and I'm looking forward to your suggestions if there's a better way to achieve this.
  • Thank you for the explanation.
    Is there a chance that the driver issue will be fixed?
  • pstaw wrote: 2024-03-07 11:06 Thank you for the explanation.
    Is there a chance that the driver issue will be fixed?
    I have made a new discovery!

    Through the compatible property in the device tree, I found the corresponding driver source code. I realized that my previous assumption was incorrect. The driver handles the network cable insertion/removal by clearing some register flags and printing information. It does not affect the settings made by ifconfig.
    So, I suspected that there might be a script running in the background that detects network cable insertion/removal events and sets the IP address using ifconfig. Finally, I discovered that in the rkipc application source code, a thread is created to detect network changes and call udhcpc to set the IP address. This caused our script settings to be ineffective.

    The method to disable the rkipc startup is to comment out the content related to rkipc in /oem/usr/bin/RkLunch.sh under luckfox-pico.

    Code: Select all

            #if [ -d "/oem/usr/share/iqfiles" ];then
            #       rkipc -a /oem/usr/share/iqfiles &
            #else
            #       rkipc &
            #fi