Milk-V Duo. USB Internet configuration without RJ45

Hi everyone! I just finished commiting my first open source code for Milk-V Duo
Recently I bought Milkv-V Duo 64M board without Ethernet adapter with RJ45. And installed official OS image

Than I connected my MilkV to the Raspberry Pi 4 (RPi4).

The issue what I got - that I can communicate with board by ssh connection throw USB Type-C, but without Internet on this board, that was challange for me.
So how I’ve solve this issue. On the board we have just pure Linux - Linux Core, without any additional packages. But really this is not full Linux Core - many of standard applications is absent.

So I decided to write two shell scripts that will help me, and I hope also many peoples.

You have to run two scripts, for one script by each machine: on MilkV
– and on the host)

  • The file MilkV-Duo-internet-throw-USB– contains next instrusctions

### Add rc.local file
echo -e “#!/bin/sh
echo Adding route for
sleep 2
route add default gw
echo Add default finished
exit 0” >> /etc/rc.local
chmod +x /etc/rc.local

echo -e "

### Run user scripts
::sysinit:/etc/rc.local" >> /etc/inittab

## Instead above movigs with /etc/rc.local and /etc/inittab you can call below script, but it works juft until you not reboot the board
#route add default gw

### Add nameservers
echo -e “nameserver” >> /etc/resolv.conf.head

### Reboot

  • The file MilkV-Duo-internet-throw-USB– contains next instrusctions

### Network interfaces Forwarding btw eth0->usb0

sudo sysctl net.ipv4.ip_forward
sudo sysctl -w net.ipv4.ip_forward=1


grep -q sysctl_conf_row_commented sysctl_conf && (sed -i ‘s/sysctl_conf_row_commented/sysctl_conf_row_uncommented/’ sysctl_conf || echo “sysctl_conf_row_uncommented” >> sysctl_conf)

sudo iptables -t nat -A POSTROUTING -o eth0 -j MASQUERADE
sudo iptables -A FORWARD -i eth0 -o usb0 -m state --state RELATED,ESTABLISHED -j ACCEPT
sudo iptables -A FORWARD -i usb0 -o eth0 -j ACCEPT

sudo apt-get update && sudo apt-get -y upgrade
sudo apt-get -y install iptables-persistent
sudo netfilter-persistent save

### Make static IP for Rpi4 with address
echo -e "
interface usb0
static ip_address=
static routers=
static domain_name_servers=" >> /etc/dhcpcd.conf

sudo systemctl restart dhcpcd

# Enable IP forwarding
sudo sysctl -w net.ipv4.ip_forward=1

# Set up port forwarding
sudo iptables -t nat -A PREROUTING -i eth0 -p tcp --dport 2222 -j DNAT --to-destination
sudo iptables -A FORWARD -i eth0 -o usb0 -p tcp --dport 22 -d -j ACCEPT
sudo iptables -A FORWARD -i usb0 -o eth0 -p tcp --sport 22 -s -j ACCEPT

You dont need to copy-past above code, just copy one file to the Milkv and run it
scp root@
also run MilkV-Duo-internet-throw-USB– on host machine

All detail description you can find in README file

Screenshot 2024-01-11 053712