網站首頁 編程語言 正文
1. 配置Linux hostname
下面配置兩臺centos7 虛擬機,主機名分別配置為client和server,它們主機IP 地址分別為192.168.30.8和192.168.30.9。
配置client主機
[root@client ~]# vi /etc/sysconfig/network
添加如下內容,保存:
# Created by anaconda NETWORKING=yes hostname=client
重啟網絡:
[root@client ~]# systemctl restart network [root@client ~]# hostname client [root@client ~]#
如果不生效可以使用如下命令:
[root@client ~]# hostnamectl set-hostname client
配置server主機
[root@server ~]# hostnamectl set-hostname server
重啟網絡:
[root@server ~]# systemctl restart network [root@server ~]# hostname server [root@server ~]# uname -n server
2. 配置hostname與IP映射
配置client和server的hosts文件
vi /etc/hosts
添加如下內容:
192.168.30.8 client 192.168.30.9 server
3. 測試
通過ping hostname來測試是否配置成功:
client ping server:
[root@client ~]# ping server -c 3 PING server (192.168.30.9) 56(84) bytes of data. 64 bytes from server (192.168.30.9): icmp_seq=1 ttl=64 time=0.616 ms 64 bytes from server (192.168.30.9): icmp_seq=2 ttl=64 time=0.384 ms 64 bytes from server (192.168.30.9): icmp_seq=3 ttl=64 time=0.566 ms --- server ping statistics --- 3 packets transmitted, 3 received, 0% packet loss, time 2001ms rtt min/avg/max/mdev = 0.384/0.522/0.616/0.099 ms [root@client ~]#
server ping client:
[root@Server ~]# ping client -c 3 PING client (192.168.30.8) 56(84) bytes of data. 64 bytes from client (192.168.30.8): icmp_seq=1 ttl=64 time=0.502 ms 64 bytes from client (192.168.30.8): icmp_seq=2 ttl=64 time=0.678 ms 64 bytes from client (192.168.30.8): icmp_seq=3 ttl=64 time=0.323 ms --- client ping statistics --- 3 packets transmitted, 3 received, 0% packet loss, time 2003ms rtt min/avg/max/mdev = 0.323/0.501/0.678/0.144 ms [root@Server ~]#
配置hostname與IP映射后,可以直接ping主機名而不用ping IP地址了。
4. 配置windows hosts
配置windows hosts,以便在windows下面能通過主機名進行訪問。
編輯 C:\Windows\System32\drivers\etc\hosts文件,添加如下內容:
192.168.30.8 client 192.168.30.9 server
保存
5. windows測試
C:\Users\10287>ping client -n 3 正在 Ping client [192.168.30.8] 具有 32 字節的數據: 來自 192.168.30.8 的回復: 字節=32 時間<1ms TTL=64 來自 192.168.30.8 的回復: 字節=32 時間<1ms TTL=64 來自 192.168.30.8 的回復: 字節=32 時間<1ms TTL=64 192.168.30.8 的 Ping 統計信息: 數據包: 已發送 = 3,已接收 = 3,丟失 = 0 (0% 丟失), 往返行程的估計時間(以毫秒為單位): 最短 = 0ms,最長 = 0ms,平均 = 0ms
原文鏈接:https://blog.51cto.com/u_15441270/4714431
相關推薦
- 2022-01-30 element table表格里的多選按鈕,根據條件判斷是否可以被選中
- 2022-07-07 Python筆記之a?=?[0]*x格式的含義及說明_python
- 2022-06-16 golang?gorm開發架構及寫插件示例_Golang
- 2022-08-04 基于python實現rpc遠程過程調用_python
- 2024-01-09 使用<scope>import</scope>解決Maven項目單繼承問題
- 2023-10-11 MP、MybatisPlus、聯表查詢、自定義sql、Constants.WRAPPER、ew (二
- 2022-12-15 深入了解Golang中的格式化輸出_Golang
- 2023-10-15 理解C/C++中的鏈接
- 最近更新
-
- window11 系統安裝 yarn
- 超詳細win安裝深度學習環境2025年最新版(
- Linux 中運行的top命令 怎么退出?
- MySQL 中decimal 的用法? 存儲小
- get 、set 、toString 方法的使
- @Resource和 @Autowired注解
- Java基礎操作-- 運算符,流程控制 Flo
- 1. Int 和Integer 的區別,Jav
- spring @retryable不生效的一種
- Spring Security之認證信息的處理
- Spring Security之認證過濾器
- Spring Security概述快速入門
- Spring Security之配置體系
- 【SpringBoot】SpringCache
- Spring Security之基于方法配置權
- redisson分布式鎖中waittime的設
- maven:解決release錯誤:Artif
- restTemplate使用總結
- Spring Security之安全異常處理
- MybatisPlus優雅實現加密?
- Spring ioc容器與Bean的生命周期。
- 【探索SpringCloud】服務發現-Nac
- Spring Security之基于HttpR
- Redis 底層數據結構-簡單動態字符串(SD
- arthas操作spring被代理目標對象命令
- Spring中的單例模式應用詳解
- 聊聊消息隊列,發送消息的4種方式
- bootspring第三方資源配置管理
- GIT同步修改后的遠程分支