本文是通过VMware虚拟机的方式配置CentOS6.5 桥接模式访问网络。

一、设置虚拟机桥接模式

 

 

二、桥接模式配置VMware虚拟机网络

1. ipconfig查询宿主机网络信息:

连接特定的 DNS 后缀 . . . . . . . :
本地链接 IPv6 地址. . . . . . . . : fa81::5462:6445:2e21:7a6b%8
IPv4 地址 . . . . . . . . . . . . : 192.168.1.130
子网掩码  . . . . . . . . . . . . : 255.255.255.0
默认网关. . . . . . . . . . . . . : 192.168.1.1

2.  vi /etc/sysconfig/network-scripts/ifcfg-eth0 配置CentOS6.5 静态ip,子网掩码, 默认网关, DNS

DEVICE="eth0"
HWADDR="00:0C:29:47:0D:02"
IPV6INIT="yes"
NM_CONTROLLED="yes"
ONBOOT="yes"
TYPE="Ethernet"
UUID="1aa239ea-37d8-4bc8-be88-28a06204593f"


BOOTPROTO="static" #静态ip
IPADDR=192.168.1.130 #ip地址
NETMASK=255.255.255.0 #子网掩码
GATEWAY=192.168.1.1 #默认网关
DNS1=8.8.8.8 #DNS-谷歌的地址(免费)

ip地址:设置和宿主机同网段ip

NETMASK:子网掩码和宿主机相同

GATEWAY: 默认网关和宿主机相同

DNS1: 8.8.8.8 借助Google的

 

3.  vi /etc/sysconfig/network 添加网关地址

NETWORKING=yes
HOSTNAME=localhost.localdomain
GATEWAY=192.168.1.1

4. vi /etc/resolv.conf 添加DNS

# Generated by NetworkManager
nameserver 8.8.8.8

5. 重启network

service network restart

三、测试

1. 内网访问自身静态ip

[xxx@localhost ~]$ ping 192.168.1.130
PING 192.168.1.130 (192.168.1.130) 56(84) bytes of data.
64 bytes from 192.168.1.130: icmp_seq=1 ttl=64 time=0.026 ms
64 bytes from 192.168.1.130: icmp_seq=2 ttl=64 time=0.060 ms
64 bytes from 192.168.1.130: icmp_seq=3 ttl=64 time=0.056 ms
64 bytes from 192.168.1.130: icmp_seq=4 ttl=64 time=0.054 ms
64 bytes from 192.168.1.130: icmp_seq=5 ttl=64 time=0.061 ms
64 bytes from 192.168.1.130: icmp_seq=6 ttl=64 time=0.026 ms
^C
--- 192.168.1.130 ping statistics ---
6 packets transmitted, 6 received, 0% packet loss, time 5471ms
rtt min/avg/max/mdev = 0.026/0.047/0.061/0.015 ms

2. 访问公网

[xxx@localhost ~]$ ping www.baidu.com
PING www.a.shifen.com (115.239.210.27) 56(84) bytes of data.
64 bytes from 115.239.210.27: icmp_seq=2 ttl=48 time=25.5 ms
64 bytes from 115.239.210.27: icmp_seq=3 ttl=48 time=25.2 ms
64 bytes from 115.239.210.27: icmp_seq=4 ttl=48 time=25.1 ms
64 bytes from 115.239.210.27: icmp_seq=5 ttl=48 time=26.0 ms
^C
--- www.a.shifen.com ping statistics ---
5 packets transmitted, 4 received, 20% packet loss, time 4436ms
rtt min/avg/max/mdev = 25.111/25.481/26.057/0.395 ms

3. 宿主机访问虚拟机

C:\Users\xxx>ping 192.168.1.130

正在 Ping 10.255.206.129 具有 32 字节的数据:
来自 192.168.1.130 的回复: 字节=32 时间=1ms TTL=64
来自 192.168.1.130 的回复: 字节=32 时间<1ms TTL=64
来自 192.168.1.130 的回复: 字节=32 时间<1ms TTL=64
来自 192.168.1.130 的回复: 字节=32 时间<1ms TTL=64

192.168.1.130 的 Ping 统计信息:
    数据包: 已发送 = 4,已接收 = 4,丢失 = 0 (0% 丢失),
往返行程的估计时间(以毫秒为单位):
    最短 = 0ms,最长 = 1ms,平均 = 0ms

4. 虚拟机访问宿主机

[xxx@localhost ~]$ ping 192.168.1.129	 
PING 192.168.1.129 (192.168.1.129) 56(84) bytes of data.
64 bytes from 192.168.1.129: icmp_seq=1 ttl=128 time=0.269 ms
64 bytes from 192.168.1.129: icmp_seq=2 ttl=128 time=0.555 ms
64 bytes from 192.168.1.129: icmp_seq=3 ttl=128 time=0.221 ms
64 bytes from 192.168.1.129: icmp_seq=4 ttl=128 time=0.564 ms
^C
--- 192.168.1.129 ping statistics ---
4 packets transmitted, 4 received, 0% packet loss, time 3391ms
rtt min/avg/max/mdev = 0.221/0.402/0.564/0.158 ms

 

 

 

 

Logo

华为开发者空间,是为全球开发者打造的专属开发空间,汇聚了华为优质开发资源及工具,致力于让每一位开发者拥有一台云主机,基于华为根生态开发、创新。

更多推荐