LoginSignup
1
0

Ubuntu22.04 で Could not resolve host

Posted at

経緯

朝起きたらこうなっていた(何もしてないのに壊れたが、昨日の僕が多分なんかしたんだと思う)

git push
fatal: unable to access 'https://gitlab.com/hogehoge1234/fugafuga.git/': Could not resolve host: gitlab.com

DNSの解決ができてなさそうなので、確認のためにgoogleにcurl

curl https://www.google.co.jp/
curl: (6) Could not resolve host: www.google.co.jp

当たりっぽい

解決策

パッとググると/etc/resolv.conf を書き換えるという記事が出てくるが、Ubuntu22.04ではNetplanを利用すると良いらしい

すでに /etc/netplan/01-netcfg.yaml が存在しているので、01より大きい数字のファイルを作成する。
ドキュメントでは99-netcfg.yamlを作ったりしているが、大きければいいので02でも可能なはず

sudo cp /etc/netplan/01-netcfg.yaml /etc/netplan/02-netcfg.yaml
sudo vim /etc/netplan/02-netcfg.yaml

nameserversの記述を追加する。パブリックDNSとしてよく使われているのはGoogleさんの8.8.8.8だと思う。

個人的にはCloudflareさんの1.1.1.1及びフィルタリング有りの1.1.1.3をよく使っている。

      nameservers:
        addresses:
          - x.x.x.x
02-netcfg.yaml
# This file describes the network interfaces available on your system
# For more information, see netplan(5).
network:
  ethernets:
    ens192:
      dhcp4: true
      dhcp6: true
      dhcp-identifier: mac
      nameservers:
        addresses:
          - 1.1.1.3
    ens224:
      dhcp4: true
      dhcp6: true
      dhcp-identifier: mac
      nameservers:
        addresses:
          - 1.1.1.3
  version: 2

書き換えたらnetplan apply で設定を適用する

sudo netplan apply

pushできるようになった

git push
Enumerating objects: 11, done.
Counting objects: 100% (11/11), done.
Delta compression using up to 2 threads
Compressing objects: 100% (6/6), done.
Writing objects: 100% (6/6), 1.30 KiB | 667.00 KiB/s, done.
Total 6 (delta 4), reused 0 (delta 0), pack-reused 0

その他メモ

今回は直接の原因ではなかったっが、systemd-resolveが起動して設定が書き換わっていることもあるらしい

1
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
0