编辑 /etc/hosts
cd /etc
sudo vi hosts
进去以后 输入 字母 i
进入编辑模式
输入对应的ip:host
输入完成以后,按Esc,输入:wq
修改域名IP对应关系:参考如下
##
# Host Database
#
# localhost is used to configure the loopback interface
# when the system is booting. Do not change this entry.
##
127.0.0.1 localhost
255.255.255.255 broadcasthost
185.199.108.153 documentcloud.github.com
192.30.253.112 github.com
192.30.253.118 gist.github.com
185.199.108.154 help.github.com
140.82.113.9 nodeload.github.com
199.232.28.133 raw.github.com
52.87.114.63 status.github.com
140.82.114.17 training.github.com
140.82.113.3 www.github.com
::1 localhost
查询域名对应IP的方法
写了个脚本:
githubhosts.py
import os
import sys
import re
githubhosts = [
"documentcloud.github.com",
"github.com",
"desktop.github.com",
"github.global.ssl.fastly.net",
"codeload.github.com",
"assets-cdn.github.com",
"github.global.ssl.fastly.net",
"gist.github.com",
"help.github.com",
"nodeload.github.com",
"raw.github.com",
"status.github.com",
"training.github.com",
"www.github.com"
]
resultList = list()
for host in githubhosts:
cmd = 'ping -c 1 %s' % host
print(cmd)
content = os.popen(cmd).read()
result = content.split("\n")
firstLine = result[0]
reg = re.compile('PING\s(.*)\s\((.*)\):\s56\sdata\sbytes')
regMatch = reg.search(firstLine)
ip = regMatch.groups()[1]
print("%s -> %s" % (host,ip))
resultList.append("%s %s" % (ip,host))
pass
finalResult = '\n'.join(resultList)
print('=====================================================================================')
print(finalResult)
print('=====================================================================================')
print('Copy the ip-host map and replace in /etc/hosts')
print('Run dscacheutil -flushcache')
网友评论