I've found two possible solutions for the intermittent problems I've had with IPv6 networking running on Ubuntu 16.04 LTS, even though I have a correct static configuration in /etc/network/interfaces. The symptom is the IPv6 gateway disappearing after a while when viewed in Webmin > Networking > Network Configuration> Routing and Gateways > Active Configuration. (I raised an earlier ticket about this which was closed because the problem couldn't be reproduced.) The solutions below seem to be effective but I can't be sure until some time has elapsed.
A blog post here http://commandline.ninja/2014/06/06/ipv6-router-solicitation-link-local-gateway-ubuntu-and-a-bit-of-wtf/ led me to both solutions.
The first solution, (also corroborated here https://serverfault.com/questions/629190/ubuntu-14-04-dropping-ipv6-route-and-ifstate) is to disable RAs (router advertisements) and autoconfiguration by editing /etc/sysctl.conf to add
net.ipv6.conf.eth0.autoconf=0
net.ipv6.conf.eth0.accept_ra=0
This obviously won't work if a static configuration is not present, and the root cause may be a problem elsewhere in the network. But for a static configuration it's preferable.
The second solution is to edit /etc/network/interfaces to put the IPv6 section before the IPv4 section. This should have no ill effects, but it does confuse Webmin a bit. If I put the "post-up iptables-restore" statement in the second IPv4 block, Webmin doesn't see it. Similarly if I put the IPv4 "dns-nameservers" values in the second IPv4 block they don't show up in Webmin either.
By the way, I noticed that the generated /etc/resolv.conf file is missing the last DNS nameserver entry - i.e. if you enter four values in Webmin only three show up in resolv.conf. This seems to be an Ubuntu bug.
Update: I'm still seeing failures in Webmin > Networking > Network Configuration> Routing and Gateways > Active Configuration so the changes haven't solved it. However, connectivity seems OK and "ip -6 route" shows a default gateway route. So I think it may be just the webmin reporting that's faulty, not the actual network configuration.
If I click the "Apply Configuration" button in Network Configuration the reported Active Configuration in Webmin changes (for a while) but the output of "ip -6 route" does NOT change. Here it is:
$ ip -6 route
2a01:7c8:aab0::/48 dev ens3 proto kernel metric 256 pref medium
fe80::/64 dev ens3 proto kernel metric 256 pref medium
default via 2a01:7c8:aab0::1 dev ens3 metric 1024 pref medium
There may be some default IPv6 routes that are always created regardless of the addresses on your interfaces.
After further investigation (don't believe anything you read on the internet!) it appears that everything is working as it should when I manually edit /etc/network/interfaces, but the webmin menus are misleading. The RAs and interface order are irrelevant and the limit of three DNS servers in /etc/resolv.conf is deliberate (in Ubuntu).
So, the remaining misleading things are:
Webmin doesn't correctly parse /etc/network/interfaces if both IPv4 and IPv6 entries are present, causing it to falsely indicate that gateway or DNS settings are missing, that firewalls will not be enabled at startup and so on. If new values are saved in webmin, they don't appear in the right sections in /etc/network/interfaces (in practice this usually doesn't matter much).
The Routing and Gateways > Active Configuration display is wrong, not sure why. For example, my current configuration as displayed by netstat is attached and correctly shows an IPv6 gateway route but webmin shows it as missing. Note that in earlier versions of webmin the IPv6 gateway really wasn't configured but that no longer seems to be the case, it just looks that way.
The webmin "Hostname and DNS client" setting allows multiple DNS servers to be configured but only three will actually have effect in /etc/resolv.conf.
I confirm a problem with ip6tables startup, which is not automaticly enabled in webmin.
in fact the user has to setup this manually with an additional entry in:
/etc/network/interfaces
post-up ip6tables-restore < /etc/ip6tables.up.rules
Cheers mike