Netplan Recipe For Fixed IP address

Hi all,

For those of you who require a fixed IP address on your PYNQ. The example sets the IP address using new Ubuntu 18.04 bionic netplan utilities with the fixed IP set to 192.168.1.32, a net mask of 24 bits indicated by the /24 in the ip address and a gateway of 192.168.1.254. These need to be changed to values compatible with your specific network needs.

Note, as I am unable to upload a tar, yaml and sh files on this forum, I will just give you the content of the files in this post.

First create a netplan directory in the associated packages directory for your target board. For example, for the ZCU111 the netplan directory needs to located at (assuming the PYNQ source is located at ~/PYNQ).

~/PYNQ/boards/ZCU111/packages/netplan

Two files need to be added to the netplan directory. In this example the package contains two files, my-conf.yaml and pre.sh. my-conf.yaml is used by netplan and therefore requires changing to support your required IP address and network settings.

Content of my-conf.yaml is (Note, tabs are not rendering in the post, so I have used<\t> to indicate a tab.)
"
network:
<\t>ethernets:
<\t><\t> eth0:
<\t><\t><\t>addresses: [192.168.1.32/24]
<\t><\t><\t>gateway4: 192.168.1.254
<\t><\t><\t>nameservers:
<\t><\t><\t><\t>addresses: [8.8.8.8,8.8.4.4]
<\t><\t><\t> dhcp4: no

<\t>version: 2"

The content of the pre.sh is
"
#!/bin/bash

set -x
set -e

target=$1
script_dir=“$( cd “$( dirname “${BASH_SOURCE[0]}” )” && pwd )”

sudo cp $script_dir/my-conf.yaml $target/etc/netplan
"

The shell script pre.sh is used by the Qemu tools to add the my-conf.yaml to the target image.

The associated board spec file also needs to be altered to contain the netplan package.

Hope this Helps.

Regards

Walter

2 Likes