ModalAI Forum
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Register
    • Login

    Robust way of setting static IP

    Ask your questions right here!
    2
    2
    30
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • J
      jonathankampia
      last edited by

      Right now I'm using this bash script to set a static ip:

      ETHERNET_IP=192.168.1.100
      eth_dongle_interface=eth0
      
      while true
      do  
         if [[ -e "/sys/class/net/$eth_dongle_interface" ]]; then
               eth_dongle_ip=$(ip -4 addr show $eth_dongle_interface | grep -oP '(?<=inet\s)\d+(\.\d+){3}' | head -1)
         else
               eth_dongle_ip=""
         fi
      
         if [[ "$eth_dongle_ip" != *"$ETHERNET_IP"* &&  -e "/sys/class/net/$eth_dongle_interface" ]]; then
                      echo "setting IP address to: $ETHERNET_IP"
                      ip addr flush dev $eth_dongle_interface
                      sleep 1
                      ip link set dev $eth_dongle_interface up
                      sleep 1
                      ip addr add $ETHERNET_IP/255.255.255.0 dev $eth_dongle_interface
          fi
          sleep 1
      done
      

      It's pretty reliable, but we have seen it fail and the default 169.254.4.1 address takes over the eth0 interface. I believe this the Qualcomm DHCP manager? Is there any way to edit the network manager directly? We have tried deleting it but it seems to regenerate on boot.

      Alex KushleyevA 1 Reply Last reply Reply Quote 0
      • Alex KushleyevA
        Alex Kushleyev ModalAI Team @jonathankampia
        last edited by Alex Kushleyev

        @jonathankampia ,

        Here is something i tried, you can try as well. You are right, there is a background service that may be taking over, I think i found how to disable it:

        systemctl disable QCMAP_ConnectionManagerd
        systemctl disable qti_pppd
        systemctl disable qtid
        
        rm /lib/systemd/system/multi-user.target.wants/QCMAP_ConnectionManagerd.service
        rm /lib/systemd/system/multi-user.target.wants/qti_pppd.service
        rm /lib/systemd/system/multi-user.target.wants/qtid.service
        
        #edit: instead of disabling the above 3 services and removing the entries from `multi-user.target.wants`, it seems you can do the following:
        systemctl mask QCMAP_ConnectionManagerd
        systemctl mask qti_pppd
        systemctl mask qtid
        
        # you may want to disable dhcpcd as well, but i dont think that is strictly necessary:
        systemctl disable dhcpcd
        

        Now, set up static connection:

        #create a new network interface file
        vi /etc/systemd/network/10-eth0.network
        
        [Match]
        Name=eth0
        
        [Network]
        Address=192.168.xx.xx/24
        Gateway=192.168.xx.1
        DNS=8.8.8.8 1.1.1.1
        

        enable networkd

        systemctl enable systemd-networkd
        

        Then reboot voxl2...

        I think if dhcpcd is enabled, it may first take over the interface, but then networkd takes it back.. For example, here is the log from networkd when dhcpcd is enabled:

        ...
        Dec 10 06:01:00 m0054 systemd-networkd[1126]: dummy0: Gained carrier
        Dec 10 06:01:00 m0054 systemd-networkd[1126]: dummy0: Gained IPv6LL
        Dec 10 06:01:11 m0054 systemd-networkd[1126]: eth0: Gained carrier
        Dec 10 06:02:13 m0054 systemd-networkd[1126]: eth0: Gained IPv6LL
        Dec 10 06:02:13 m0054 systemd-networkd[1126]: eth0: Configured
        Dec 10 06:02:13 m0054 systemd-networkd[1126]: docker0: Link UP
        Dec 10 06:02:21 m0054 systemd-networkd[1126]: eth0: Lost carrier
        Dec 10 06:02:36 m0054 systemd-networkd[1126]: eth0: Gained carrier
        Dec 10 06:02:38 m0054 systemd-networkd[1126]: eth0: Gained IPv6LL
        Dec 10 06:02:38 m0054 systemd-networkd[1126]: eth0: Configured
        

        and the log with dhcpcd disabled:

        ...
        Dec 10 06:02:13 m0054 systemd-networkd[1126]: bond0: Link is not managed by us
        Dec 10 06:02:13 m0054 systemd-networkd[1126]: sit0: Link is not managed by us
        Dec 10 06:02:14 m0054 systemd-networkd[1126]: eth0: Link UP
        Dec 10 06:02:38 m0054 systemd-networkd[1126]: eth0: Gained carrier
        Dec 10 06:09:56 m0054 systemd-networkd[1126]: eth0: Gained IPv6LL
        Dec 10 06:09:56 m0054 systemd-networkd[1126]: eth0: Configured
        Dec 10 06:09:56 m0054 systemd-networkd[1126]: docker0: Link UP
        

        Can you try and see if that solves your issue?

        Alex

        1 Reply Last reply Reply Quote 0
        • First post
          Last post
        Powered by NodeBB | Contributors