Pi-hole で "DNS resolution is currently unavailable" のエラーが出るときの対処法
家中丸ごと広告ブロックしてくれる Pi-holeを、自宅のRaspberry Pi 3 に docker コンテナとして運用しています。
広告リストを更新しようとすると、あるときこのようなエラーが出ました。
[✗] DNS resolution is currently unavailable [✗] DNS resolution is not available
DNS解決が出来ないとのエラー。 最初は、何か設定を間違えのだと思って再インストールしてみたものの、解決せず。
解決策
結論からいうと、このときの原因は、/etc/resolv.conf
に書いてある内容が間違っていたことでした。
これは、ネットワークの名前解決に使われるファイルです。中には、ホスト名 (google.com yahoo.co.jp のようなもの) と、IPアドレスとの対応が書かれています。
問題のあった環境では、その中身を見てみると、以下のようになっていました。
nameserver 127.0.0.11 options ndots:0
nameserver 127.0.0.11
の部分のせいで、外部との通信ができなくなっているようです。そこで、
nameserver 127.0.0.1 options ndots:0
に書き換えて、docker-compose.yml
のあるフォルダーに resolv.conf
という名前で保存します。
docker-compose.yml
に以下の一行を追記します。
services:
pihole:
container_name: pihole
image: pihole/pihole:latest
ports:
- 53:53/tcp
- 53:53/udp
- 67:67/udp
- 8100:80/tcp
environment:
TZ: Asia/Tokyo
PIHOLE_DNS_: 1.1.1.1;1.0.0.1
FTLCONF_REPLY_ADDR4: 192.168.0.82
volumes:
- ./etc-pihole:/etc/pihole
- ./etc-dnsmasq.d:/etc/dnsmasq.d
+ - ./resolv.conf:/etc/resolv.conf
cap_add:
- NET_ADMIN # Recommended but not required (DHCP needs NET_ADMIN)
restart: unless-stopped
その後 docker コンテナを再起動します。
docker compose -f ~/docker/pihole/docker-compose.yml down docker compose -f ~/docker/pihole/docker-compose.yml up -d
これで、広告リストの更新ができるようになっているはずです。
resolv.conf の中身を確認する方法
"pihole" の部分には、docker-compose.yml の container に指定したコンテナの名前を入れます。お使いの環境に合わせてください。
# コンテナの中に入る。 sudo docker exec -it pihole /bin/bash # resolv.conf の中身を表示する cat /etc/resolv.conf
参考にしたページ:
https://discourse.pi-hole.net/t/solved-dns-resolution-is-currently-unavailable/33725/7
自動で Node.js のバージョンを切り替えてくれる fnm を使ってみた
Node.js のバージョン管理といえば nodenv
とか nvm
があるけど、その新しい仲間がまた出てきたみたい。
それが fnm
くん。Rust製で、マルチプラットフォームかつ高速に動くのが売りらしい。
Node.js のバージョンを指定してインストールできる
fnm install --latest # 最新版をインストールする fnm install --lts # 最新のLTS版をインストールする fnm install 18 # v18系の最新版をインストールする fnm install 19.5.0 # 見たまま
特定のバージョンを使用する
fnm use 18 # 上でインストールした v18系を使う
自動バージョン切り替え
面白いのは、ディレクトリに応じて自動的にNode.jsのバージョンを切り替えてくれること。
ファイル名 .node-version
というテキストファイルに、バージョン番号を入れておくだけ。
ちなみに .nvmrc
ファイルにも対応している。
> node --version v19.5.0
という状況だとして、
node --version > .node-version
とすれば、次にこのディレクトリに入る時には自動でバージョンを切り替えてくれる。
fnm自体のインストール
brew install fnm
Windows の方は scoop
もしくは chocolatey
を使ってこのように
scoop install fnm # もしくは choco install fnm
Rust製なのでパッケージマネージャー cargo
を使ってもインストールできる
cargo install fnm
そのほか、ビルド済みバイナリーもあるとのこと。
使う準備
動かすためには、シェルに環境変数を読み込ませる必要があるみたい。
以下の一行を、プロファイル(.bashrc
や .zshrc
、Powershell のプロファイル)に含めておくこと。
eval "$(fnm env --use-on-cd)" # bash もしくは zsh の場合 fnm env --use-on-cd | Out-String | Invoke-Expression # Powershell の場合
そのほかのコマンド
# インストールされているバージョンの一覧を取得 (systemはfnmで入れたものではなく、最初からリストにあった。fnm外でインストールしたものを使うときに使うのかな?) > fnm list * v16.19.0 * v18.13.0 lts-latest * v19.5.0 default * system # 現在使用中のバージョンを表示 > fnm current v19.5.0 # インストール可能なバージョンの一覧を表示 > fnm list-remote (長いので省略) # 特定のバージョンに別名を付けられる > fnm alias 19 hogehoge # とすると、 > fnm list * v16.19.0 * v18.13.0 lts-latest * v19.5.0 default, hogehoge # ←名前が追加されて、 * system > fnm use hogehoge Using Node for alias hogehoge # その名前で呼び出せる。 > fnm unalias hogehoge # 別名を消すときはこうする
今日はここまで。
ChatGPT で、無害そうなプロンプトが「ポリシー違反」とされた
次に作る自作アプリのアイデアをもらおうと思ってChatGPTに質問してみたら、以下のようにポリシー違反として怒られてしまった。
大丈夫なパターン↓
how to use google spreadsheets as a database
Google Sheets can be used as a database by using the Google Sheets API, which allows you to read and write data to a sheet. You can use the API to create web applications that can read and write data to a sheet, which can then be used as a database. To use the API, you will need to create a project in the Google Developers Console and enable the Sheets API. Then you can use a programming language such as Python or JavaScript to interact with the API and read and write data to the sheet.
怒られたパターン↓
how to fetch video info from Youtube without scraping
This content may violate our content policy. If you believe this to be in error, please submit your feedback — your input will aid our research in this area.
You can fetch information about a video on YouTube without scraping by using the YouTube Data API. The API allows you to retrieve information about videos, channels, and playlists on YouTube. To use the API, you will need to create a project in the Google Developers Console, enable the YouTube Data API, and generate an API key. Once you have the API key, you can use it to make requests to the API and retrieve information about a specific video by sending a GET request to the video resource and passing in the video's ID. Additionally, you can also use the YouTube API client libraries which make it easy to call the API in various programming languages.
This content may violate our content policy. If you believe this to be in error, please submit your feedback — your input will aid our research in this area.
なぜ?Content policy とやらには以下のような内容が禁止されているとあるが、どれにも当てはまらないように思える。
- Hate (ヘイト)
- Harassment (嫌がらせ)
- Violence (暴力)
- Self-harm (自傷行為)
- Sexual (性的)
- Political (政治的)
- Spam (スパム)
- Deception (詐欺)
- Malware (マルウェア)
別に無視しても良かったんだろうが、一応フィードバック送っておいた。
安全装置的なフィルターが掛かってることに、とりあえず安心した。
An (in)complete list of "navigator.languages" in browsers (a.k.a IETF Language Tag or BCP47)
How to reproduce this list:
- Open Chrome's settings page (
chrome://settings/languages
). - Add all language.
- Open console and enter
navigator.languages
and voila! You see the result.
But this is incomplete. Why?
I usually use Chrome in Japanese language. Before starting to make this list, I tried to run
console.log(navigator.languages)
, then I got ["ja-JP", "ja"]
. After testing, I removed all languages except English and re-added Japanese. Then ja-JP
never appeared again on the list.
What this tells us is that the list is a lower limit, therefore you should not reject any language tags that are not on the list.
tag | Language |
---|---|
af | Afrikaans |
am | Amharic |
an | Aragonese |
ar | Arabic |
ast | Asturian |
az | Azerbaijani |
be | Belarusian |
bg | Bulgarian |
bn | Bangla |
br | Breton |
bs | Bosnian |
ca | Catalan |
ceb | Cebuano |
chr | Cherokee |
ckb | Central Kurdish |
co | Corsican |
cs | Czech |
cy | Welsh |
da | Danish |
de | German |
de-AT | German (Austria) |
de-CH | German (Switzerland) |
de-DE | German (Germany) |
de-LI | German (Liechtenstein) |
el | Greek |
en | English |
en-AU | English (Australia) |
en-CA | English (Canada) |
en-GB | English (United Kingdom) |
en-GB-oxendict | English (United Kingdom, Oxford English Dictionary spelling) |
en-IN | English (India) |
en-NZ | English (New Zealand) |
en-US | English (United States) |
en-ZA | English (South Africa) |
eo | Esperanto |
es | Spanish |
es-419 | Spanish (Latin America) |
es-AR | Spanish (Argentina) |
es-CL | Spanish (Chile) |
es-CO | Spanish (Colombia) |
es-CR | Spanish (Costa Rica) |
es-ES | Spanish (Spain) |
es-HN | Spanish (Honduras) |
es-MX | Spanish (Mexico) |
es-PE | Spanish (Peru) |
es-US | Spanish (United States) |
es-UY | Spanish (Uruguay) |
es-VE | Spanish (Venezuela) |
et | Estonian |
eu | Basque |
fa | Persian |
fi | Finnish |
fil | Filipino |
fo | Faroese |
fr | French |
fr-CA | French (Canada) |
fr-CH | French (Switzerland) |
fr-FR | French (France) |
fy | Western Frisian |
ga | Irish |
gd | Scottish Gaelic |
gl | Galician |
gn | Guarani |
gu | Gujarati |
ha | Hausa |
haw | Hawaiian |
he | Hebrew |
hi | Hindi |
hmn | Hmong |
hr | Croatian |
ht | Haitian Creole |
hu | Hungarian |
hy | Armenian |
ia | Interlingua |
id | Indonesian |
ig | Igbo |
is | Icelandic |
it | Italian |
it-CH | Italian (Switzerland) |
it-IT | Italian (Italy) |
ja | Japanese |
jv | Javanese |
ka | Georgian |
kk | Kazakh |
km | Khmer |
kn | Kannada |
ko | Korean |
ku | Kurdish |
ky | Kyrgyz |
la | Latin |
lb | Luxembourgish |
ln | Lingala |
lo | Lao |
lt | Lithuanian |
lv | Latvian |
mg | Malagasy |
mi | Māori |
mk | Macedonian |
ml | Malayalam |
mn | Mongolian |
mo | Romanian (Moldova) |
mr | Marathi |
ms | Malay |
mt | Maltese |
my | Burmese |
nb | Norwegian Bokmål |
ne | Nepali |
nl | Dutch |
nn | Norwegian Nynorsk |
no | Norwegian |
ny | Nyanja |
oc | Occitan |
om | Oromo |
or | Odia |
pa | Punjabi |
pl | Polish |
ps | Pashto |
pt | Portuguese |
pt-BR | Portuguese (Brazil) |
pt-PT | Portuguese (Portugal) |
qu | Quechua |
rm | Romansh |
ro | Romanian |
ru | Russian |
rw | Kinyarwanda |
sd | Sindhi |
sh | Serbo-Croatian |
si | Sinhala |
sk | Slovak |
sl | Slovenian |
sm | Samoan |
sn | Shona |
so | Somali |
sq | Albanian |
sr | Serbian |
st | Southern Sotho |
su | Sundanese |
sv | Swedish |
sw | Swahili |
ta | Tamil |
te | Telugu |
tg | Tajik |
th | Thai |
ti | Tigrinya |
tk | Turkmen |
tn | Tswana |
to | Tongan |
tr | Turkish |
tt | Tatar |
tw | Twi |
ug | Uyghur |
uk | Ukrainian |
ur | Urdu |
uz | Uzbek |
vi | Vietnamese |
wa | Walloon |
wo | Wolof |
xh | Xhosa |
yi | Yiddish |
yo | Yoruba |
zh | Chinese |
zh-CN | Chinese (Simplified) |
zh-HK | Chinese (Hong Kong) |
zh-TW | Chinese (Traditional) |
zu | Zulu |
ターミナルコマンドの fzf でいちいち `'` (引用符) をつけなくてもいいようにする。
fzf でいちいち '
(引用符) をつけなくてもいいようにする。
オプションに --exact
を渡す。
例:
export FZF_DEFAULT_OPTS="--height 40% --multi --exact --reverse --ansi --cycle --prompt='▶' --bind '?:toggle-preview'"
ちなみに Windows でも、 PsFzf
というラッパーから fzf が使える。
PSFzf: A thin wrapper around Fzf. If PSReadline is loaded, this wrapper registers Fzf with the keyboard chord Ctrl+t.
その場合、こんな感じ。
Set-PsFzfOption -PSReadlineChordProvider 'Ctrl+t' -PSReadlineChordReverseHistory 'Ctrl+r' $env:_PSFZF_FZF_DEFAULT_OPTS = "--height 40% --multi --exact --reverse --ansi --cycle --prompt='▶'"