# Voxl 2 Mini Static IP

Source: https://forum.modalai.com/topic/2854/voxl-2-mini-static-ip
Category: General Questions (https://forum.modalai.com/category/2/general-questions)
Posted: 2023-11-13 19:20:39 UTC by bendraper
Replies: 10 · Views: 2791

## bendraper · 2023-11-13 19:20:39 UTC

https://docs.modalai.com/voxl2-mini-shell-access/

The bottom of this doc says "If using wired ethernet, set up a static IP address." but I've tried doing ifconfig eth0 ~ip address~ netmask ~subnet~ to no avail. I've also tried ip addr add xxx.xxx.xxx.xxx/yy dev eth0 to no avail (always sets ip to 169.254.4.1). I know the Voxl 2 wasn't able to have a static ip set so if it is the same for the mini then so be it, the doc just made it seem like it may be possible so I was just curious

## Reply by wilkinsaf · 2023-11-15 04:08:30 UTC

@bendraper It is possible to set a static ip on both the voxl2 and voxl2 mini. 

It is just ubuntu OS. What modem/router are you connecting to?

## Reply by bendraper · 2023-11-15 16:41:26 UTC (in reply to wilkinsaf)

@wilkinsaf I was just connecting to my laptop for now. Laptop set with a static IP

## Reply by wilkinsaf · 2023-11-15 18:22:36 UTC (in reply to bendraper)

@bendraper 

Here is what one of my guys uses

```
ip addr flush dev eth0
ip link set dev eth0 up
ip addr add 192.168.1.100/255.255.255.0 dev eth0
```

## Reply by wilkinsaf · 2023-11-15 18:24:17 UTC (in reply to wilkinsaf)

i would make sure that the ethernet is the only thing connected that is supplying network connectivity. (no modem, 4g/5g hat, etc...)
otherwise you willl need to do some extra configuration with voxl-modem

## Reply by bendraper · 2023-11-15 21:25:05 UTC (in reply to wilkinsaf)

@wilkinsaf This worked! Thank you

## Reply by bendraper · 2023-11-15 21:42:49 UTC (in reply to wilkinsaf)

@wilkinsaf Actually it seems these settings don't stick after rebooting the voxl... Any ideas?

## Reply by bendraper · 2023-11-15 21:45:14 UTC (in reply to wilkinsaf)

@wilkinsaf google seems to suggest changing a /etc/network/interfaces file may do the trick but this file does not exist in the voxl filesystem

## Reply by wilkinsaf · 2023-11-16 15:59:25 UTC (in reply to bendraper)

@bendraper 

If you make a script to do this, you might want to make it monitor eth0 state so if eth0 goes down and back up, the IP doesn't get removed.
Here's a bash example of what I do to check the IP address of ethernet and put it back if it goes down and back up

```
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
```
Of course, this is in my modified voxl-modem with custom variables for the interface (eth0 or eth1) and variables for the IP address. You might just want to hard code those when testing.

## Reply by blue · 2024-05-29 17:00:56 UTC (in reply to bendraper)

@tom @wilkinsaf @Moderator I am hoping you can help shed some light on an issue with setting up the VOXL2 Mini with a static IP. I have seen mention of utilizing a customized version of voxl-modem for a static IP so perhaps I am missing something but I have tried every approach to setting a static IP and more than I have ever used with no avail. It seems there is a service that is enabled by default to clear the IP address of the VOXL2 Mini and messes with the routing of the eth0 interface because anything I implement does not function properly. I must be missing something here if you would please enlighten me :)

Goal: 
Set a persistent static IP on VOXL2 Mini that is maintained after reboots and during operation, then access the VOXL2 Mini with an ssh connection via a Ethernet to USB adapter. 

Overview of Approaches:
-Approach #1: **Does NOT Work-** *Use commands to flush and wipe the eth0 interface and set a new IP* as shown below. This works temporarily but is overwritten typically within 30 seconds while running. After a reboot, the IP address defaults back to 169.254.4.1 and VOXL2 Mini cannot be accessed via ssh on eth0.

-Approach #2: **Does NOT Work-** *Use system.d file to set eth0 interface* with a new IP as shown below. This works temporarily but is overwritten typically within 30 seconds while running. After a reboot, the IP address defaults back to 169.254.4.1 and VOXL2 Mini cannot be accessed via ssh on eth0.

-Approach #3: **Does NOT Work-** Use bash script to constantly check and set the IP. This works to set the IP but the VOXL2 Mini cannot be accessed via ssh on eth0.

---------------------------------------------
**Approach #1**
Steps to Reproduce:
1. adb into VOXL2 Mini
2. Run: 
```
ip addr flush dev eth0
ip link set dev eth0 up
ip addr add 192.168.1.100/255.255.255.0 dev eth0 
ifconfig
```
3. Wait 2 minutes and run:
```
ifconfig
```
Actual Result:
-IP address changes back to 169.254.4.1.
-Device no longer available via ssh on eth0 at 169.254.4.1.

Expected Result:
-IP should not change after being set.

---------------------------------------------
**Approach #2**
Steps to Reproduce:
1. adb into VOXL2 Mini
2. Run: ```sudo mkdir -p /etc/systemd/network```
3. Run: ```sudo vi /etc/systemd/network/10-eth0-static.network```
4. Add the following to the file created above:
``` 
[Match]
Name=eth0

[Network]
Address=192.169.144.15/24
Gateway=192.169.144.1
DNS=8.8.8.8
```

5. Run: 
```
sudo systemctl restart systemd-networkd
sudo systemctl enable systemd-networkd
ip addr show eth0
sudo systemctl status systemd-networkd
```

6. Wait 2 minutes and run:
```
ifconfig
```
Actual Result:
-IP address changes back to 169.254.4.1.
-Device no longer available via ssh on eth0 at 169.254.4.1.

Expected Result:
-IP should not change from 192.169.144.15 after being set.

-----------------------------------------------

**Approach #3**
Steps to Reproduce:
1. adb into VOXL2 Mini
2. Run:
	```vi /usr/local/bin/set-eth-dongle-ip.sh```
3. Add the following to the file created above:
```
#!/bin/bash

eth_dongle_interface="eth0" # Replace with your dongle interface name
ETHERNET_IP="192.168.144.15" # Replace with your desired IP address
BROADCAST_IP="192.168.144.255" # Replace with the correct broadcast address

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/24 broadcast $BROADCAST_IP dev $eth_dongle_interface
    fi
    sleep 1
done
```
4. make service file executeable, run:
```sudo chmod +x /usr/local/bin/set-eth-dongle-ip.sh```
5. create systemd service file, run:
```vi etc/systemd/system/set-eth-dongle-ip.service ```
6. Add the following to the file created above:
```
[Unit]
Description=Set Ethernet Dongle IP Address
After=network.target

[Service]
ExecStart=/usr/local/bin/set-eth-dongle-ip.sh
Restart=always
User=root

[Install]
WantedBy=multi-user.target
```
7. Run:
```
#reload the systemd daemon to recognize the new service 
sudo systemctl daemon-reload

# enable the service so that it runs on boot
sudo systemctl enable set-eth-dongle-ip.service

# start service immediately
sudo systemctl start set-eth-dongle-ip.service

# verify service has started properly
sudo systemctl status set-eth-dongle-ip.service
```
8. Wait 2 minutes and run:
```
ifconfig
```
Actual Result:
-IP address changes back to 169.254.4.1.
-Device no longer available via ssh on eth0 at 169.254.4.1.

Expected Result:
IP should not change from 192.169.144.15 after being set.

## Reply by blue · 2024-05-29 20:36:28 UTC (in reply to blue)

After having some issues with a static IP on the VOXL2 Mini above it ended up being an issue with being on the wrong subnet for the host computer to communicate.

We ended up fixing the issue by changing the subnet for the host computer once we changed the IP on the VOXL2 Mini. 

e.g VOXL2 Mini IP of 192.168.144.15 will require a host computer on the same subnet e.g. 192.168.144.98.
