Ubuntu Networking Stuff

Fixed IP addresses for servers is obviously a good idea. I have used DHCP assigned permanent reservations as the easiest and most manageable way to use fixed addresses. IP addresses were assigned from a single pool. For me this was usually 192.168.1.101 for 100 addresses. Any DHCP assigned address could simply be tagged as a permanent reservation.

Pfsense changed this. The Pfsense DHCP server can still assign all IP addresses. However, they are “static mappings” rather than “permanent reservations”. The kicker is that the static mappings cannot be in the regular DHCP address pool. Since all my permanent reservations were dispersed throughout the address pool before pfsense, I had to start from scratch with static mappings.

Static IP Addresses

I have a server within the pfsense DHCP pool that needs to have a fixed address. I will assign it on the server and hope that pfsense doesn’t assign it to another device. I will eventually need to correct this.

On my new Ubuntu 18.04 server, I edited /etc/network/interfaces to change the DHCP assigned address to a static IP address as in the past. However, interfaces was empty and I realized I needed to modify /etc/netplan/01-netcfg.yaml. I changed it from this:

network:
version: 2
renderer: networkd
ethernets:
ens3:
dhcp4: yes

to this:

network:
version: 2
renderer: networkd
ethernets:
ens3:
dhcp4: no
addresses:
192.168.1.199/24
gateway4: 192.168.1.1
nameservers:
addresses: [8.8.8.8, 1.1.1.1]

The indention is important. Using two spaces works fine. Unfortunately, WordPress removed the indentions from my examples.

Apply the changes with:

$ sudo netplan apply

Verify the changes with:

$ ip addr show dev ens3

To restart networking use:

sudo systemctl restart network-manager

OpenHab2 as Virtual Guest

OpenHAB is home automation software that connects to devices from different vendors. OpenHAB uses a Mosquitto (MQTT) server as a message broker so that clients and servers can post messages to each other. For example, OpenHAB posts a message for Light1 to turn on. Light1 is listening for Light1 messages and turns on.

I am using a couple of sources to install openHAB 2 as a virtual guest on my KVM server. I previously used Matt Kaczynski’s MK-SmartHouse excellent Video Guides for installing openHAB 2 on a Raspberry Pi using the openhabian image. I will use these guides in conjunction with openHAB’s installation guide for Linux. This works for apt based systemd systems. Note that Zulu 8 is a prerequisite.

$ sudo apt-key adv –keyserver hkp://keyserver.ubuntu.com:80 –recv-keys 0xB1998361219BD9C9
$ sudo apt-add-repository ‘deb http://repos.azulsystems.com/ubuntu stable main’
$ sudo apt-get install zulu-8
$ wget -qO – ‘https://bintray.com/user/downloadSubjectPublicKey?username=openhab’ | sudo apt-key add –
$ sudo apt-get install apt-transport-https
$ echo ‘deb https://dl.bintray.com/openhab/apt-repo2 stable main’ | sudo tee /etc/apt/sources.list.d/openhab2.list
$ sudo apt-get update
$ sudo apt-get install openhab2
$ sudo apt-get install openhab2-addons
$ sudo systemctl start openhab2.service
$ sudo systemctl status openhab2.service
$ sudo systemctl daemon-reload
$ sudo systemctl enable openhab2.service

Next is the MQTT server installation:

$ sudo apt update
$ sudo apt install mosquitto
$sudo apt install mosquitto-clients

Use MQTT.fx to test the installation.

At this point I am switching to MK-SmartHouse for configuration. The openhabian image for the Raspberry Pi has already done the work to this point.

I am migrating from the openhabian server on my Raspberry Pi. I plan to configure the server then copy the config files and hosts file from the old server.

Upgrading to OpenHAB 2.4

I broke OpenHAB after upgrading to OpenHAB 2.4 on my Raspberry Pi. You must also upgrade the mosquitto server. MK SmartHouse has a video to describe the process.

$ sudo apt-get remove mosquitto

From paper ui Addons /Bindings uninstall mqtt 1.0 binding.
From paper ui Addons / Bindings install mqtt 2.4 binding.
From paper ui Addons / Misc install Embedded MQTT Broker.
From paper ui Inbox select System MQTT Broker and add as thing.
Optionally from paper ui Configuration / Services, configure MQTT Embedded Broker.

Test MQTT with MQTT.fx.

From paper ui Inbox serch for things and select MQTT Binding then add manually then select Generic MQTT Thing (9:53)

Pickup with New Migration Tutorial

This is from OpenHAB.org.

From PaperUI inbox, add new thing and select MQTT Thing binding.
Add a new thing in PaperUI and select a Generic MQTT Thing and give it a name.
Edit the thing and add a new channel

Sharing Linux Files with NFS

Samba has been my go-to for file sharing on my network. However I want to use my ubuntu file server with my nextcloud server. I think it’s time for NFS. Digital Ocean comes through again with a good tutorial. The method is to “export” the directory on the server and “mount” the exported directory on the client. Export definitions are in /etc/export and mount definitions are in /etc/fstab.

server$  sudo apt install nfs-kernel-server

client$   sudo apt install nfs-common

server$  sudo nano /etc/exports

Enter export: /media/storage 192.168.1.0/24(rw,sync,no_root_squash,no_subtree_check)

Use systemctl to manage the server: sudo systemctl status nfs-kernel-server.

Create the client mount point: mkdir -p /nfs/storage

client$  sudo mount fileserver:/media/storage /nfs/storage (to test path)

client$  sudo nano /etc/fstab

Enter the mount:                                                                                                                        fileserver:/media/storage /nfs/storage nfs auto,nofail,noatime,nolock,intr,tcp,actimeo=1800 0 0 (You probably need a hosts entry for for the server named file.)

Refresh fstab: mount -a

Refresh exports: exportfs -ra

Update: LXC Containers

LXC containers are not priviliged to mount hard drives. The best practice is to mount the NFS share on the Proxmox host as above. Then use a bind-mount – edit /etc/pve/lxc/1xx.conf and add the line:

mp0: /mnt/storage,mp=/mnt/lxc_nfs_share

Mount Sequence with LXC Containers

For lack of a better place, it goes here. The Proxmox host cannot mount the file server NFS share until the file server starts. Jellyfin cannout mount the NFS the Proxmox host mounts the share.

Disable the fstab mount. Create a systemd mount unit. Here’s a sample /etc/systemd/storage.mount:

[Unit]
Description=Mount NFS share after LXC container 101 is ready
Requires=container@101.service
After=container@101.service

[Mount]
What=192.168.1.50:/export/storage
Where=/mnt/storage
Type=nfs
Options=_netdev,auto

[Install]
WantedBy=multi-user.target

Then enable it:

sudo systemctl daemon-reexec
sudo systemctl enable –now storage.mount

/et

Cloning KVM Guests and More

The umteenth time I created a KVM guest for ubuntu 18.04 LTS I decided to find a better method – cloning.

Clone the image

virt-clone – – original oldname – – name newname – – file newname.qcow2

Rename the image if necessary

  1. virsh domrename oldname newname (see this)
  2. virsh edit newname then change oldname to newname in the xml file
  3. mv oldname.qcow2 to newname.qcow2
  4. sudo nano /etc/hostname and change oldname to newname
  5. sudo nano /etc/hosts and change oldname to newname

Grow the image file

  1. qemu-img resize newname.qcow2 +3G (on kvm machine – newname must be shut down) (see this)
  2. virsh start newname
  3. virsh blockresize newname /var/lib/libvirt/images/newname.qcow2 15G
  4. fdisk -l newname.qcow2
  5. qemu-img info newname.qcow2
  6. lsblk
  7. apt install cloud-guest-utils (on guest machine)
  8. growpart /dev/sda 2 (see this)
  9. resize2fs /dev/sda2