I am trying to add an external alias for my site and, because of silly NAT, the IPv4 interface doesn't match what DNS (as opposed to /etc/hosts) returns. IPv6 works fine though, but since ikiwiki-hosting first looks for IPv4 records, it fails to pick that up. I have a crude hack to fix this, but it doesn't seem like the good approach. "Worked for me" though.
Example, without the patch:
root@marcos:/home/a-wiki# ikisite domains wiki.anarcat.ath.cx --external=anarcat.ath.cx --alias=wiki.anarcat.ath.cx
DNS not configured correctly for anarcat.ath.cx - 72.0.72.144
Note that I had to patch to even get that debugging information:
diff --git a/ikisite b/ikisite
index adc5df3..82a29cb 100755
--- a/ikisite
+++ b/ikisite
@@ -1193,7 +1193,7 @@ sub domains {
}
if ($address ne $hostname) {
if (! grep { defined $_ && $_ eq $address } site_addresses()) {
- print STDERR "DNS not configured correctly for $options{external}\n";
+ print STDERR "DNS not configured correctly for $options{external} - got $address\n";
exit 3; # special code
}
else {
With the following patch, the thing actually works:
diff --git a/IkiWiki/Hosting.pm b/IkiWiki/Hosting.pm
index b802f21..08365d2 100644
--- a/IkiWiki/Hosting.pm
+++ b/IkiWiki/Hosting.pm
@@ -128,7 +128,7 @@ sub host_address_or_cname {
# cached NXDOMAIN from earlier tests. We want to see the current
# state of the DNS.
# dig has to be run a second time to check for ipv6 AAAA addresses.
- foreach my $atype (qw{A AAAA}) {
+ foreach my $atype (qw{AAAA A}) {
open(DIG, "-|", "dig", "-t$atype", "+nofail", "+trace", "$host.") || error "dig: $!";
while (<DIG>) {
next if /^;/;
root@marcos:/home/a-wiki# ikisite domains wiki.anarcat.ath.cx --external=anarcat.ath.cx --alias=wiki.anarcat.ath.cx
warning: DNS for anarcat.ath.cx hardcodes IP 2001:1928:1:9:beae:c5ff:fe89:e238
[...]
As I said, this is a rather naive patch. Maybe this kind of overall prioritisation should be a config option? Or should we have a way to override the IP detection? Not sure how to handle this, really... Maybe the simplest fix is to have a --force argument... -- anarcat
The following patch allows overriding the IP detection mechanism:
From: =?UTF-8?q?Antoine=20Beaupr=C3=A9?= <anarcat@koumbit.org>
Date: Sat, 17 Dec 2011 14:13:29 -0500
Subject: [PATCH] allow hardcoding the IPs
---
IkiWiki/Hosting.pm | 9 +++++++++
ikiwiki-hosting.conf | 6 ++++++
2 files changed, 15 insertions(+), 0 deletions(-)
diff --git a/IkiWiki/Hosting.pm b/IkiWiki/Hosting.pm
index b802f21..f09dd3b 100644
--- a/IkiWiki/Hosting.pm
+++ b/IkiWiki/Hosting.pm
@@ -104,6 +104,9 @@ sub outtemplate {
sub site_addresses {
# Looks up the site's main addresses; those that have a default
# route.
+ if ($config{hardcode_ipv4} && $config{hardcode_ipv6}) {
+ return ($config{hardcode_ipv4}, $config{hardcode_ipv6});
+ }
my ($defiface) = `ip route` =~ m/^default via .* dev ([a-zA-Z0-9]+)/m;
if (! $defiface) {
# Maybe ipv6 only.
@@ -115,6 +118,12 @@ sub site_addresses {
my $show=`ip addr show $defiface`;
my ($ipv4) = $show =~ m/inet (\d+\.\d+\.\d+\.\d+).*scope global/m;
my ($ipv6) = $show =~ m/inet6 ([a-zA-Z0-9:]+).*scope global/m;
+ if ($config{hardcode_ipv4}) {
+ $ipv4 = $config{hardcode_ipv4};
+ }
+ if ($config{hardcode_ipv6}) {
+ $ipv6 = $config{hardcode_ipv6};
+ }
return ($ipv4, $ipv6);
}
diff --git a/ikiwiki-hosting.conf b/ikiwiki-hosting.conf
index f0f124f..ad8e14c 100644
--- a/ikiwiki-hosting.conf
+++ b/ikiwiki-hosting.conf
@@ -24,6 +24,12 @@ allow_ipv4=0
allow_ipv6=0
# (Disable all of the above to disable auto-assignment of DNS addresses.)
+# by default, ikiwiki-hosting looks at the first IP on the interface
+# that has the default gateway, but this may fail if you're behind NAT
+# or else. those allow you to hardcode the IPs
+# hardcode_ipv4=10.0.0.1
+# hardcode_ipv6=fr00::0
+
# This is the DNS TTL to use when adding a hostname for a site.
ttl=28800
--
1.7.7.3
]
I am running with this patch in production now, seems to work okay. --anarcat