Last active
July 15, 2020 04:13
-
-
Save miladoll/13915a7134edf8f6688aa8c1cf446c40 to your computer and use it in GitHub Desktop.
resolv.conf searchの正しい変更お作法 (debian 10, buster / Ubuntu 20)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# local DNS stub listener を無効にする | |
if lsof -i:53 | grep -q systemd-resolve; then | |
sed -i \ | |
-e 's|^#\(DNSStubListener=\).*$|\1no|' \ | |
/etc/systemd/resolved.conf | |
resolve_conf_real_path=$(readlink /etc/resolv.conf) | |
# なおかつ /etc/resolv.conf を stub ではないものを参照させる | |
if [[ "$resolve_conf_real_path" =~ stub-resolv.conf$ ]]; then | |
( | |
cd /etc | |
ln -sf ../run/systemd/resolve/resolv.conf resolv.conf | |
) | |
fi | |
systemctl restart systemd-resolved.service | |
fi | |
# v これでは勝手に書き換わる | |
#sed -i \ | |
# -e 's|^\(nameserver\)\s.*$|\1 1.1.1.1|' \ | |
# /run/systemd/resolve/resolv.conf | |
# cf: https://thr3a.hatenablog.com/entry/20180711/1531285176 | |
# グローバル | |
sed -i \ | |
-e 's|^#\(DNS\)=.*$|\1=1.1.1.1|' \ | |
/etc/systemd/resolved.conf | |
systemctl restart systemd-resolved | |
# さくらでは ens3 が外部向けインターフェイスでこれにも設定追加 | |
sakura_eth=$( \ | |
ip link \ | |
| grep '^[0-9][0-9]*:' \ | |
| grep 'BROADCAST' \ | |
| grep -v -E '(veth|br-)' \ | |
| grep 'UP' \ | |
| grep -v ' docker' \ | |
| cut -d' ' -f2 \ | |
| tr -d : \ | |
) | |
if [[ $sakura_eth == 'ens3' ]]; then | |
resolvectl dns ens3 1.1.1.1 | |
fi | |
systemctl restart systemd-resolved |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment