修改host指定域名指向ip,Windows脚本与Linux脚本

修改host指定域名指向ip,Windows脚本与Linux脚本web

一,Windows系统修改hosts文件

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

找到后右键编辑(若是提示没法编辑、权限不够、只读模式等,须要将hosts文件复制粘贴到桌面或者其余盘修改完再挪回来)vim

在hosts文件末尾追加编辑便可。bash

修改格式是 ip    域名spa

示例:命令行

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.cncode

 

还能够直接写BAT脚本,而后直接点击执行:blog

@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,之后就能够右键以管理员执行了。ip

 

二,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 执行了。

相关文章
相关标签/搜索