修改host指定域名指向ip,Windows腳本與Linux腳本


修改host指定域名指向ip,Windows腳本與Linux腳本

一,Windows系統修改hosts文件

Windows系統下hosts文件位置:C:\Windows\System32\drivers\etc\hosts

找到后右鍵編輯(如果提示無法編輯、權限不夠、只讀模式等,需要將hosts文件復制粘貼到桌面或者其他盤修改完再挪回來)

在hosts文件末尾追加編輯即可。

修改格式是 ip    域名

示例:

10.13.83.43 yun.xiong.cn
10.13.83.43 web.xiong.cn
10.13.83.43 minio.xiong.cn
10.13.83.43 graph.xiong.cn

 

還可以直接寫BAT腳本,然后直接點擊執行:

@echo off
echo 請“以管理員身份運行”!
attrib -R C:\WINDOWS\system32\drivers\etc\hosts 
@echo 10.3.233.98 yun.test.cn >>C:\WINDOWS\system32\drivers\etc\hosts
@echo 10.3.233.98 web.test.cn >>C:\WINDOWS\system32\drivers\etc\hosts
@echo 10.3.233.98 minio.test.cn >>C:\WINDOWS\system32\drivers\etc\hosts
@echo 10.3.233.98 graph.test.cn >>C:\WINDOWS\system32\drivers\etc\hosts

::pause>nul

 將以上內容復制粘貼到記事本,保存成setHost.bat,文件格式是ANSI,以后就可以右鍵以管理員執行了。

 

二,Linux系統修改hosts文件

Linux系統下hosts文件位置:/etc/hosts

找到后用vi或者vim編輯(root或者普通用戶使用sudo權限)

在hosts文件末尾追加編輯即可。格式同上。

 

如果是單條可以直接執行命令行:

      echo "10.13.83.43 yun.xiong.cn">> /etc/hosts

還可以直接寫shell腳本,然后直接執行:

#!/bin/bash
#

#設置Host
sudo echo "10.13.83.43 yun.xiong.cn" >> /etc/hosts
sudo echo "10.13.83.43 web.xiong.cn" >> /etc/hosts
sudo echo "10.13.83.43 minio.xiong.cn" >> /etc/hosts
sudo echo "10.13.83.43 graph.xiong.cn" >> /etc/hosts

echo "設置host完成"

 將以上內容復制粘貼到記事本,保存成setHost.sh,以后就可以 bash setHost.sh 執行了。

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM