Ubuntu(四)[网络管理-hosts绑定]

以 git clone github上的项目为例

对比

git clone配置的获取的IP是会变动的,需要及时的获取更新。
hosts绑定前:
在这里插入图片描述
hosts绑定后:
在这里插入图片描述

1.nslookup方式【不建议】

1.获取信息

dnsutils中的nslookup工具获得github.com和github.global.ssl.fastly.net域名的ip地址

nslookup github.com
nslookup github.global.ssl.fastly.net
Name:   github.com
Address: 192.30.253.112
Name:   github.global.ssl.fastly.net
Address: 151.101.44.249

在这里插入图片描述
2.追加内容到/etc/hosts

sudo cp /etc/hosts /etc/hosts.backup 
sudo tee -a /etc/hosts <<-'EOF'
192.30.253.112 github.com
151.101.44.249 github.global.ssl.fastly.net
EOF
cat /etc/hosts
sudo /etc/init.d/networking restart

在这里插入图片描述

2.命令方式【推荐】

1.获取信息
github.com

Linux上grep执行不生效,和bsd和GUN协议有关,bsd用grep -oE GUN用grep -oP

curl -skX GET 'https://github.com.ipaddress.com/' | grep -oP '<th>IPv4 Addresses</th><td><ul class="comma-separated"><li>.*?</li>'| grep -oP '[0-9]+\.[0-9]+\.[0-9]+\.[0-9]+'

在这里插入图片描述
github.global.ssl.fastly.net

Linux上grep执行不生效,和bsd和GUN协议有关,bsd用grep -oE GUN用grep -oP

curl -skX GET 'https://fastly.net.ipaddress.com/github.global.ssl.fastly.net' | grep -oP '<th>IPv4 Addresses</th><td><ul class="comma-separated"><li>.*?</li>'| grep -oP '[0-9]+\.[0-9]+\.[0-9]+\.[0-9]+' 

在这里插入图片描述
2.追加内容到/etc/hosts

sudo cp /etc/hosts /etc/hosts.backup 
sudo tee -a /etc/hosts <<-'EOF'
140.82.112.3 github.com
199.232.69.194 github.global.ssl.fastly.net
EOF
cat /etc/hosts
sudo /etc/init.d/networking restart 

在这里插入图片描述

3.浏览器方式【推荐】

1.获取信息
浏览器打开

https://github.com.ipaddress.com/

在这里插入图片描述
浏览器打开:

https://fastly.net.ipaddress.com/github.global.ssl.fastly.net

在这里插入图片描述
2.追加内容到/etc/hosts

sudo cp /etc/hosts /etc/hosts.backup 
sudo tee -a /etc/hosts <<-'EOF'
140.82.112.3 github.com
199.232.69.194 github.global.ssl.fastly.net
EOF
cat /etc/hosts
sudo /etc/init.d/networking restart

在这里插入图片描述

4.浏览器搜索【推荐】

Windows操作系统的建议使用此方式!
浏览器访问:

https://www.ipaddress.com/

在这里插入图片描述

注意:
Windows x64,则hosts修改的是在:

C:\Windows\System32\drivers\etc\hosts

CentOS-7,则hosts修改的是在:

/etc/hosts

修改完成后一定要重启网络服务!

操作完成后建议还原hosts的原配置!

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值