zoukankan      html  css  js  c++  java
  • RHEL7使用NAT方式上网

    1.首先,Windows7无法设置网络共享VMNet8的问题,是因为禁用了Firewall服务,设置为自动,启用即可;且需要启动VMWare的DHCP和NAT两个服务,这两个服务在我的机器上是关闭的,启动后必须重启计算机,否则打开VMWare发现无法启动原来的虚拟机操作系统和添加新的,重启后恢复正常:

    参考:https://jingyan.baidu.com/article/ae97a646aca8a0bbfd461d80.html

    2.然后将物理机网络(本地或无线网络)设置共享VMNet8:

    VMNet8设置IP与DNS获取方式为自动获取:

    3.设置虚拟机为NAT方式,编辑->虚拟网络编辑器中使用默认子网和子网掩码,

    打开NAT设置记录其默认网关:

    打开DHCP设置记录其网段范围:

    虚拟机操作系统RHEL7的IP要设置在这个网段范围,网关要设置成这个网关,DNS设置成和物理机相同(但无论怎么设置,最后成功上网,但使用ping无法直接ping通www.baidu.com,也无法ping通这个设置的DNS地址,也许这就是无法ping通前者的原因,因为无法通过访问DNS正确解析域名,但wget www.baidu.com可以使用,可获取到网页html信息):

    详细配置:

    HWADDR=00:0C:29:8A:85:8E
    TYPE=Ethernet
    BOOTPROTO=static
    DEFROUTE=yes
    PEERDNS=yes
    PEERROUTES=yes
    IPV4_FAILURE_FATAL=no
    IPV6INIT=yes
    IPV6_AUTOCONF=yes
    IPV6_DEFROUTE=yes
    IPV6_PEERDNS=yes
    IPV6_PEERROUTES=yes
    IPV6_FAILURE_FATAL=no
    NAME=eno16777736
    UUID=34d2cc8f-6397-4aae-be8b-8dd5c65abe07
    ONBOOT=yes
    IPADDR=172.20.10.90
    NETMASK=255.255.255.0
    GATEWAY=172.20.10.30
    DNS1=192.168.0.1

    4.重启RHEL7网络服务:

    [root@localhost network-scripts]# service network restart
    Restarting network (via systemctl): [ OK ]

    5.虚拟机RHEL7与物理机互ping:

    --虚拟机ping--

    [root@localhost network-scripts]# ping 192.168.0.103
    PING 192.168.0.103 (192.168.0.103) 56(84) bytes of data.
    64 bytes from 192.168.0.103: icmp_seq=1 ttl=128 time=0.472 ms
    64 bytes from 192.168.0.103: icmp_seq=2 ttl=128 time=0.396 ms
    64 bytes from 192.168.0.103: icmp_seq=3 ttl=128 time=0.491 ms
    64 bytes from 192.168.0.103: icmp_seq=4 ttl=128 time=0.446 ms
    64 bytes from 192.168.0.103: icmp_seq=5 ttl=128 time=0.392 ms
    ^C
    --- 192.168.0.103 ping statistics ---
    5 packets transmitted, 5 received, 0% packet loss, time 4002ms
    rtt min/avg/max/mdev = 0.392/0.439/0.491/0.043 ms

    物理机ip可ping通

    [root@localhost network-scripts]# ping 192.168.0.1
    PING 192.168.0.1 (192.168.0.1) 56(84) bytes of data.
    ^C
    --- 192.168.0.1 ping statistics ---
    4 packets transmitted, 0 received, 100% packet loss, time 3014ms

    物理机DNS无法ping通,说明这不是一个可用DNS,同时造成设置同一个DNS的虚拟机RHEL7无法解析www.baidu.com这样的域名,无法ping通域名(但虚拟机RHEL7可ping通物理机和能上网以及wget可通过域名成功获取文件,说明网络设置没问题)

    [root@localhost network-scripts]# ping 172.20.10.30
    PING 172.20.10.30 (172.20.10.30) 56(84) bytes of data.
    64 bytes from 172.20.10.30: icmp_seq=1 ttl=128 time=0.127 ms
    64 bytes from 172.20.10.30: icmp_seq=2 ttl=128 time=0.109 ms
    64 bytes from 172.20.10.30: icmp_seq=3 ttl=128 time=0.122 ms
    ^C
    --- 172.20.10.30 ping statistics ---
    3 packets transmitted, 3 received, 0% packet loss, time 1998ms
    rtt min/avg/max/mdev = 0.109/0.119/0.127/0.011 ms

    虚拟机RHEL7网关即设置为和虚拟机网络编辑器中相同的地址,可以ping通


    [root@localhost network-scripts]# ping 172.20.10.1
    PING 172.20.10.1 (172.20.10.1) 56(84) bytes of data.
    64 bytes from 172.20.10.1: icmp_seq=1 ttl=128 time=0.354 ms
    64 bytes from 172.20.10.1: icmp_seq=2 ttl=128 time=0.192 ms
    64 bytes from 172.20.10.1: icmp_seq=3 ttl=128 time=0.175 ms
    64 bytes from 172.20.10.1: icmp_seq=4 ttl=128 time=0.214 ms
    ^C
    --- 172.20.10.1 ping statistics ---
    4 packets transmitted, 4 received, 0% packet loss, time 3000ms
    rtt min/avg/max/mdev = 0.175/0.233/0.354/0.073 ms

    VMNet8通过物理机ipconfig查看的ip地址,可以ping通


    [root@localhost network-scripts]# ping www.baidu.com
    PING www.a.shifen.com (61.135.169.121) 56(84) bytes of data.
    ^C
    --- www.a.shifen.com ping statistics ---
    10 packets transmitted, 0 received, 100% packet loss, time 9008ms

    百度域名无法直接ping通

    [root@localhost network-scripts]# wget www.baidu.com
    --2018-09-15 22:46:57-- http://www.baidu.com/
    Resolving www.baidu.com (www.baidu.com)... 61.135.169.121
    Connecting to www.baidu.com (www.baidu.com)|61.135.169.121|:80... connected.
    HTTP request sent, awaiting response... 200 OK
    Length: 2381 (2.3K) [text/html]
    Saving to: ‘index.html’

    100%[======================================>] 2,381 --.-K/s in 0s

    2018-09-15 22:46:57 (205 MB/s) - ‘index.html’ saved [2381/2381]

    通过wget 百度域名,成功下载到了百度首页index.html,查看了其内容,确实是百度首页内容

    --物理机ping--

    Microsoft Windows [版本 6.1.7601]
    版权所有 (c) 2009 Microsoft Corporation。保留所有权利。

    C:UsersAdministrator>ipconfig

    Windows IP 配置


    以太网适配器 Bluetooth 网络连接:

    媒体状态 . . . . . . . . . . . . : 媒体已断开
    连接特定的 DNS 后缀 . . . . . . . :

    无线局域网适配器 无线网络连接:

    媒体状态 . . . . . . . . . . . . : 媒体已断开
    连接特定的 DNS 后缀 . . . . . . . :

    以太网适配器 本地连接:

    连接特定的 DNS 后缀 . . . . . . . :
    本地链接 IPv6 地址. . . . . . . . : fe80::8048:5d1e:ba74:50ef%11
    IPv4 地址 . . . . . . . . . . . . : 192.168.0.103
    子网掩码 . . . . . . . . . . . . : 255.255.255.0
    默认网关. . . . . . . . . . . . . : 192.168.0.1

    --上面是物理机本地宽带连接地址信息

    以太网适配器 VMware Network Adapter VMnet1:

    连接特定的 DNS 后缀 . . . . . . . :
    本地链接 IPv6 地址. . . . . . . . : fe80::919:d10b:b0bc:4708%16
    IPv4 地址 . . . . . . . . . . . . : 192.168.240.1
    子网掩码 . . . . . . . . . . . . : 255.255.255.0
    默认网关. . . . . . . . . . . . . :

    以太网适配器 VMware Network Adapter VMnet8:

    连接特定的 DNS 后缀 . . . . . . . :
    本地链接 IPv6 地址. . . . . . . . : fe80::291e:35cd:6d4b:3aea%17
    IPv4 地址 . . . . . . . . . . . . : 172.20.10.1
    子网掩码 . . . . . . . . . . . . : 255.255.255.0
    默认网关. . . . . . . . . . . . . :

    --这是VMWare与NAT连接方式对应的VMNet8网络地址信息

    隧道适配器 isatap.{8ABE2338-F8A3-4E4F-B1CD-A82A867FB567}:

    媒体状态 . . . . . . . . . . . . : 媒体已断开
    连接特定的 DNS 后缀 . . . . . . . :

    隧道适配器 Teredo Tunneling Pseudo-Interface:

    媒体状态 . . . . . . . . . . . . : 媒体已断开
    连接特定的 DNS 后缀 . . . . . . . :

    隧道适配器 isatap.localdomain:

    媒体状态 . . . . . . . . . . . . : 媒体已断开
    连接特定的 DNS 后缀 . . . . . . . :

    隧道适配器 6TO4 Adapter:

    媒体状态 . . . . . . . . . . . . : 媒体已断开
    连接特定的 DNS 后缀 . . . . . . . :

    C:UsersAdministrator>ping www.baidu.com

    正在 Ping www.baidu.com [61.135.169.125] 具有 32 字节的数据:
    来自 61.135.169.125 的回复: 字节=32 时间=20ms TTL=55
    来自 61.135.169.125 的回复: 字节=32 时间=19ms TTL=55
    来自 61.135.169.125 的回复: 字节=32 时间=19ms TTL=55
    来自 61.135.169.125 的回复: 字节=32 时间=19ms TTL=55

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

    --物理机ping百度域名,可以直接ping通

    C:UsersAdministrator>ping 192.168.0.1

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

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

    --物理机ping通过"网络与共享中心"->"更改适配器设置"->"本地连接"查看的DNS地址(这里与其ipconfig默认网关地址相同,不知是否因此才ping通),可以ping通

    C:UsersAdministrator>ping 172.20.10.90

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

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

    --物理机ping虚拟机RHEL7地址,即我们设置的地址,可以顺利ping通

    C:UsersAdministrator>ping 172.20.10.30

    正在 Ping 172.20.10.30 具有 32 字节的数据:
    请求超时。
    请求超时。
    请求超时。

    172.20.10.30 的 Ping 统计信息:
    数据包: 已发送 = 3,已接收 = 0,丢失 = 3 (100% 丢失),
    Control-C
    ^C

    --物理机ping虚拟机网关,有意思的来了,无法ping通


    C:UsersAdministrator>ping 172.20.10.1

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

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

    C:UsersAdministrator>

    --物理机ping自己网关(通过"网络与共享中心"->"更改适配器设置"->"本地连接"查看的DNS地址也是这个),ping通

    参考博文:

    https://blog.csdn.net/chenjianqi0502/article/details/77871803

    https://blog.csdn.net/yueguanghaidao/article/details/7048836

    https://blog.csdn.net/gmnet/article/details/2668945

    http://blog.51cto.com/7539372/1760652

  • 相关阅读:
    fastjson 使用方法
    算法
    SHA算法
    MD5算法
    kindle推送服务
    DLL劫持
    Hook编程
    Hook技术
    权限验证
    虚拟机
  • 原文地址:https://www.cnblogs.com/free-wings/p/9655680.html
Copyright © 2011-2022 走看看