项目开发中有时会出现测试环境不够用的情况,这时就可以考虑配置虚拟 ip 在自己家目录下搭建新的测试环境了。配置虚拟 ip 命令一般如下:
ifconfig eth0:1 10.35.128.11 netmask 255.255.255.0 up
配置后,在当前机器可以尝试 ping,应该是可以的。
[root@localhost lucas]# ping 10.35.128.11
PING 10.35.128.11 (10.35.128.11) 56(84) bytes of data.
64 bytes from 10.35.128.11: icmp_seq=1 ttl=64 time=0.026 ms
64 bytes from 10.35.128.11: icmp_seq=2 ttl=64 time=0.045 ms
64 bytes from 10.35.128.11: icmp_seq=3 ttl=64 time=0.047 ms
64 bytes from 10.35.128.11: icmp_seq=4 ttl=64 time=0.045 ms
^C
--- 10.35.128.11 ping statistics ---
4 packets transmitted, 4 received, 0% packet loss, time 2999ms
rtt min/avg/max/mdev = 0.026/0.040/0.047/0.011 ms
但如果在本地绑定host测试时,ping 域名依然还会有问题。
C:\Users\lucas>ping www.xxxxx.com.cn
正在 Ping www.xxxxx.com.cn [10.35.128.11] 具有 32 字节的数据:
请求超时。
请求超时。
请求超时。
请求超时。
10.35.128.11 的 Ping 统计信息:
数据包: 已发送 = 4,已接收 = 0,丢失 = 4 (100% 丢失),
这时由于 arp 缓存还没来得及更新,需要执行以下命令:
/sbin/arping -c 5 -U -I eth0 10.35.128.11
这时再 ping 对应域名就可以啦!
C:\Users\lucas>ping www.xxxxx.com.cn
正在 Ping www.xxxxx.com.cn [10.35.128.11] 具有 32 字节的数据:
来自 10.35.128.11 的回复: 字节=32 时间=207ms TTL=56
来自 10.35.128.11 的回复: 字节=32 时间=61ms TTL=56
来自 10.35.128.11 的回复: 字节=32 时间=45ms TTL=56
来自 10.35.128.11 的回复: 字节=32 时间=221ms TTL=56
10.35.128.11 的 Ping 统计信息:
数据包: 已发送 = 4,已接收 = 4,丢失 = 0 (0% 丢失),
往返行程的估计时间(以毫秒为单位):
最短 = 45ms,最长 = 221ms,平均 = 133ms
以上。