在Windows系統中,有一個叫hosts的系統文件,可以用它進行本地IP地址映射,文件的原始內容如下:
# Copyright (c) 1993-2009 Microsoft Corp.
#
# This is a sample HOSTS file used by Microsoft TCP/IP for Windows.
#
# This file contains the mappings of IP addresses to host names. Each
# entry should be kept on an individual line. The IP address should
# be placed in the first column followed by the corresponding host name.
# The IP address and the host name should be separated by at least one
# space.
#
# Additionally, comments (such as these) may be inserted on individual
# lines or following the machine name denoted by a '#' symbol.
#
# For example:
#
# 102.54.94.97 rhino.acme.com # source server
# 38.25.63.10 x.acme.com # x client host
# localhost name resolution is handled within DNS itself.
# 127.0.0.1 localhost
# ::1 localhost
設置本地IP地址映射后,可以簡化一些操作,比如ping命令,ssh命令。這個特點對于做編程或網路的場景比較實用。比如,開發人員可能在自己的電腦上部署幾臺虛擬機作為測試環境,經常需要用ssh命令連接虛擬機或者使用ping命令測試網絡測試虛擬機的網絡情況。我的頻道會及時的整理出windows操作的技巧和實用方法,喜歡的朋友可以關注,點贊,收藏,分享給朋友。
在Win11系統中,映射文件的位置在C:\Windows\System32\drivers\etc目錄下,其它Windows系統的位置可能會略有不同。
1. 在文件的最后加入,每個映射關系占一行。
2. IP地址在前面,后面是機器名,IP地址和機器名之間最少要有一個空格。
3. `#` 號后面的內容是注釋,可以獨占一行,也可以跟在設置的后面。
4. hosts屬于系統文件,修改時,需要使用管理員權限才能保存。
5. 保存完成后即刻生效。
IP地址 映射字符串
例如,我給自己的電腦上加入一條設置`192.168.100.71 combo71`,就是將192.168.100.71這個地址與combo71這個字符串建立了對應關系,當然,為了實用考慮,這個字符串一般是局域網內某臺機器的機器名或是域名。修改后的hosts文件如下:
# Copyright (c) 1993-2009 Microsoft Corp.
#
# This is a sample HOSTS file used by Microsoft TCP/IP for Windows.
#
# This file contains the mappings of IP addresses to host names. Each
# entry should be kept on an individual line. The IP address should
# be placed in the first column followed by the corresponding host name.
# The IP address and the host name should be separated by at least one
# space.
#
# Additionally, comments (such as these) may be inserted on individual
# lines or following the machine name denoted by a '#' symbol.
#
# For example:
#
# 102.54.94.97 rhino.acme.com # source server
# 38.25.63.10 x.acme.com # x client host
# localhost name resolution is handled within DNS itself.
# 127.0.0.1 localhost
# ::1 localhost
# 虛擬機上的機器
192.168.100.71 combo71
設置成功后 ping 192.168.100.71的效果和ping combo71對 效果是一樣的。如下:
C:\Users\80771>ping 192.168.100.71
正在 Ping 192.168.100.71 具有 32 字節的數據:
來自 192.168.100.71 的回復: 字節=32 時間<1ms TTL=64
來自 192.168.100.71 的回復: 字節=32 時間<1ms TTL=64
來自 192.168.100.71 的回復: 字節=32 時間<1ms TTL=64
來自 192.168.100.71 的回復: 字節=32 時間<1ms TTL=64
192.168.100.71 的 Ping 統計信息:
數據包: 已發送=4,已接收=4,丟失=0 (0% 丟失),
往返行程的估計時間(以毫秒為單位):
最短=0ms,最長=0ms,平均=0ms
C:\Users\80771>ping combo71
正在 Ping combo71 [192.168.100.71] 具有 32 字節的數據:
來自 192.168.100.71 的回復: 字節=32 時間<1ms TTL=64
來自 192.168.100.71 的回復: 字節=32 時間<1ms TTL=64
來自 192.168.100.71 的回復: 字節=32 時間<1ms TTL=64
來自 192.168.100.71 的回復: 字節=32 時間<1ms TTL=64
192.168.100.71 的 Ping 統計信息:
數據包: 已發送=4,已接收=4,丟失=0 (0% 丟失),
往返行程的估計時間(以毫秒為單位):
最短=0ms,最長=0ms,平均=0ms
感謝閱讀到最后,關注我,持續給您帶來簡單,實用的Windows操作技巧。
腦開機的時候明明已經開啟來了,但是電腦就是沒有網絡,右下角的網絡連接一直轉圈圈,等待了10秒左右才會有網絡,其實這個時候是電腦在獲取路由器的IP地址,如果不想讓它轉圈圈,開機就有網絡,那么就需要手動設置了。
直接上圖加文字,多說無益,WIN7演示。
首先我們要知道路由器的IP段,網上鄰居右鍵屬性、點擊本地連接、詳情信息
151這個數值可以編輯2-200隨意編輯,192.168.31.1,默認網關,看到路由器給的IP段我們就可以進行設置了。
網上鄰居右鍵屬性、左鍵點本地連接
左鍵點擊屬性
雙擊協議版本4
IP段192.168.31.*,那么*就可以隨意輸入了,建議不要超過254。
小編的路由器IP段是31,路由器是不同的,所以首先要查看自己的IP段。
網絡極客”,全新視角、全新思路,伴你遨游神奇的網絡世界。
電腦主機常見的上網方式有兩種:
一起來看看電腦端如何設置靜態、動態IP地址,以及什么時候應用靜態和動態地址。
靜態IP地址
?