Difference between revisions of "Linode"
From Organic Design wiki
(example in perl) |
m (→Gotchas) |
||
(5 intermediate revisions by the same user not shown) | |||
Line 1: | Line 1: | ||
{{stub}} | {{stub}} | ||
+ | == Linode CLI == | ||
Installing the linode CLI: | Installing the linode CLI: | ||
<source lang="bash"> | <source lang="bash"> | ||
Line 8: | Line 9: | ||
</source> | </source> | ||
+ | == Linode DNS servers == | ||
+ | As of mid 2023, we're using Linode as our DNS server rather than using the one provided by the name's registrar. The move was made because we wanted to be able to manage domain records via API so that we could take use the DNS-01 validation method for our SSL certs. But it also means we can mane them all from one place, interact with them programmatically and later AI will be able to interact with them much more naturally. They can also be moved to other DNS providers like digital ocean using automated procedures too. | ||
− | + | === Using the API to manage your domains === | |
+ | Here's an example Perl code using LWP to update an A record $HOST.$DOMAIN to $IP: | ||
<source lang="perl"> | <source lang="perl"> | ||
# Set up a user agent with our token as default header | # Set up a user agent with our token as default header | ||
Line 15: | Line 19: | ||
$ua->default_header( | $ua->default_header( | ||
'Content-Type' => "application/json", | 'Content-Type' => "application/json", | ||
− | 'Authorization' => "Bearer $ | + | 'Authorization' => "Bearer $API_KEY" |
); | ); | ||
− | # Find the ID | + | # Find the ID for $DOMAIN |
− | $ | + | $domains = $ua->get( 'https://api.linode.com/v4/domains' )->content; |
− | for ( @{ decode_json( $ | + | for ( @{ decode_json( $domains )->{data} } ) { |
− | $domain_id = $_->{id} if $_->{domain} eq $ | + | $domain_id = $_->{id} if $_->{domain} eq $DOMAIN; |
} | } | ||
− | |||
− | # Find the ID of the A record having the | + | # Find the ID of the A record having the name $HOST |
− | $ | + | $records = $ua->get( "https://api.linode.com/v4/domains/$domain_id/records" )->content; |
− | for ( @{ decode_json( $ | + | for ( @{ decode_json( $records )->{data} } ) { |
− | $record_id = $_->{id} if $_->{name} eq $ | + | $record_id = $_->{id} if $_->{name} eq $HOST; |
} | } | ||
− | |||
− | # Update the A record | + | # Update the A record to $IP |
$ua->put( | $ua->put( | ||
"https://api.linode.com/v4/domains/$domain_id/records/$record_id", | "https://api.linode.com/v4/domains/$domain_id/records/$record_id", | ||
− | 'Content' => encode_json({ 'target' => $ | + | 'Content' => encode_json({ 'target' => $IP }) |
); | ); | ||
</source> | </source> | ||
+ | |||
+ | === Useful DNS patterns === | ||
+ | *Dynamic DNS (done) | ||
+ | *Replace IPs across all domains/records | ||
+ | *Delete records matching a pattern | ||
+ | *Add (if not exists) a group of records (e.g. mail and SPF records) across a set of domains | ||
+ | |||
+ | === Gotchas === | ||
+ | *You must have at least one active compute instance on your account for domain records to be served | ||
+ | *For some reason the "@" host is not allowed in the TXT record form, you have to use the naked domain in the host field which ends up as "@" in the zone file | ||
+ | |||
+ | == See also == | ||
+ | *[[SSL]] |
Latest revision as of 23:12, 30 July 2023
Contents
Linode CLI
Installing the linode CLI:
pip3 install linode-cli
linode-cli configure --token
linode-cli --json --pretty domains list
Linode DNS servers
As of mid 2023, we're using Linode as our DNS server rather than using the one provided by the name's registrar. The move was made because we wanted to be able to manage domain records via API so that we could take use the DNS-01 validation method for our SSL certs. But it also means we can mane them all from one place, interact with them programmatically and later AI will be able to interact with them much more naturally. They can also be moved to other DNS providers like digital ocean using automated procedures too.
Using the API to manage your domains
Here's an example Perl code using LWP to update an A record $HOST.$DOMAIN to $IP:
# Set up a user agent with our token as default header
$ua = LWP::UserAgent->new();
$ua->default_header(
'Content-Type' => "application/json",
'Authorization' => "Bearer $API_KEY"
);
# Find the ID for $DOMAIN
$domains = $ua->get( 'https://api.linode.com/v4/domains' )->content;
for ( @{ decode_json( $domains )->{data} } ) {
$domain_id = $_->{id} if $_->{domain} eq $DOMAIN;
}
# Find the ID of the A record having the name $HOST
$records = $ua->get( "https://api.linode.com/v4/domains/$domain_id/records" )->content;
for ( @{ decode_json( $records )->{data} } ) {
$record_id = $_->{id} if $_->{name} eq $HOST;
}
# Update the A record to $IP
$ua->put(
"https://api.linode.com/v4/domains/$domain_id/records/$record_id",
'Content' => encode_json({ 'target' => $IP })
);
Useful DNS patterns
- Dynamic DNS (done)
- Replace IPs across all domains/records
- Delete records matching a pattern
- Add (if not exists) a group of records (e.g. mail and SPF records) across a set of domains
Gotchas
- You must have at least one active compute instance on your account for domain records to be served
- For some reason the "@" host is not allowed in the TXT record form, you have to use the naked domain in the host field which ends up as "@" in the zone file