mac命令行方式操作DNS

查看網絡連接方式

networksetup -listallnetworkservices
An asterisk (*) denotes that a network service is disabled.
USB Ethernet
Wi-Fi
Bluetooth PAN
Thunderbolt Bridge

修改對應連接方式的DNS,多個DNS,空格隔開

sudo networksetup -setdnsservers “USB Ethernet” 8.8.8.8 8.8.4.4

查看USB網卡的DNS

networksetup -getdnsservers “USB Ethernet”
8.8.8.8

清空USB網卡的DNS

sudo networksetup -setdnsservers “USB Ethernet” empty

清空DNS緩存

dscacheutil -flushcache

通過文件查看DNS

cat /etc/resolv.conf
#
# Mac OS X Notice
#
# This file is not used by the host name and address resolution
# or the DNS query routing mechanisms used by most processes on
# this Mac OS X system.
#
# This file is automatically generated.
#
nameserver 8.8.8.8

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章