Vmware CentOS虛擬機網絡初始設置

問題描述

在使用Vmware虛擬64位CentOS 7的過程中,每次新創建一個虛擬機後(網絡設置爲NAT模式),會發現網絡不可用,使用ping後會出現unknown host錯誤或者是network is unreachable等等,

[peng@localhost Desktop]$ ping baidu.com
ping: unknown host baidu.com

解決方案

  1. 首先使用ifconfig查看網卡信息,發現第一個網絡適配器eno1677736沒有獲得Ipv4的地址,也就是沒有在網絡中註冊成功:

    eno16777736: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
            ether 00:0c:29:91:5c:69  txqueuelen 1000  (Ethernet)
            RX packets 171  bytes 10260 (10.0 KiB)
            RX errors 0  dropped 0  overruns 0  frame 0
            TX packets 0  bytes 0 (0.0 B)
            TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0
    
    lo: flags=73<UP,LOOPBACK,RUNNING>  mtu 65536
            inet 127.0.0.1  netmask 255.0.0.0
            inet6 ::1  prefixlen 128  scopeid 0x10<host>
            loop  txqueuelen 0  (Local Loopback)
            RX packets 304  bytes 25880 (25.2 KiB)
            RX errors 0  dropped 0  overruns 0  frame 0
            TX packets 304  bytes 25880 (25.2 KiB)
            TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0
    
    virbr0: flags=4099<UP,BROADCAST,MULTICAST>  mtu 1500
            inet 192.168.122.1  netmask 255.255.255.0  broadcast 192.168.122.255
            ether 52:54:00:59:c4:0c  txqueuelen 0  (Ethernet)
            RX packets 0  bytes 0 (0.0 B)
            RX errors 0  dropped 0  overruns 0  frame 0
            TX packets 0  bytes 0 (0.0 B)
            TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0
  2. 進入etc/sysconfig/network-scripts,並找到這個網絡適配器的配置文件,使用nano或者vi編輯

    [root@localhost network-scripts]# cd /etc/sysconfig/network-scripts
    [root@localhost network-scripts]# ls
    ifcfg-eno16777736  ifdown-ppp       ifup-ib      ifup-Team
    ifcfg-lo           ifdown-routes    ifup-ippp    ifup-TeamPort
    ifdown             ifdown-sit       ifup-ipv6    ifup-tunnel
    ifdown-bnep        ifdown-Team      ifup-isdn    ifup-wireless
    ifdown-eth         ifdown-TeamPort  ifup-plip    init.ipv6-global
    ifdown-ib          ifdown-tunnel    ifup-plusb   network-functions
    ifdown-ippp        ifup             ifup-post    network-functions-ipv6
    ifdown-ipv6        ifup-aliases     ifup-ppp
    ifdown-isdn        ifup-bnep        ifup-routes
    ifdown-post        ifup-eth         ifup-sit
    [root@localhost network-scripts]# nano ifcfg-eno16777736
  3. ONBOOT=false 改爲ONBOOT=yes

    TYPE=Ethernet
    BOOTPROTO=dhcp
    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=94a36c28-dc0d-4999-bc65-334d30fff6fc
    DEVICE=eno16777736
    ONBOOT=yes
  4. 保存退出,最後使用service network restart重啓網絡

    service network restart
    Restarting network (via systemctl):                        [  OK  ]

檢驗

再次使用ifconfig檢查網卡情況,發現eno16777736獲得了ipv4的地址

[root@localhost network-scripts]# ifconfig
eno16777736: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
        inet 192.168.124.134  netmask 255.255.255.0  broadcast 192.168.124.255
        inet6 fe80::20c:29ff:fe91:5c69  prefixlen 64  scopeid 0x20<link>
        ether 00:0c:29:91:5c:69  txqueuelen 1000  (Ethernet)
        RX packets 276800  bytes 372561384 (355.3 MiB)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 121742  bytes 7389047 (7.0 MiB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

lo: flags=73<UP,LOOPBACK,RUNNING>  mtu 65536
        inet 127.0.0.1  netmask 255.0.0.0
        inet6 ::1  prefixlen 128  scopeid 0x10<host>
        loop  txqueuelen 0  (Local Loopback)
        RX packets 476  bytes 40664 (39.7 KiB)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 476  bytes 40664 (39.7 KiB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

virbr0: flags=4099<UP,BROADCAST,MULTICAST>  mtu 1500
        inet 192.168.122.1  netmask 255.255.255.0  broadcast 192.168.122.255
        ether 52:54:00:59:c4:0c  txqueuelen 0  (Ethernet)
        RX packets 0  bytes 0 (0.0 B)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 0  bytes 0 (0.0 B)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

再次使用ping檢查網絡情況,發現網絡正常:

[root@localhost network-scripts]# ping baidu.com
PING baidu.com (180.149.132.47) 56(84) bytes of data.
64 bytes from 180.149.132.47: icmp_seq=1 ttl=128 time=394 ms
64 bytes from 180.149.132.47: icmp_seq=2 ttl=128 time=390 ms
^C
--- baidu.com ping statistics ---
3 packets transmitted, 2 received, 33% packet loss, time 2000ms
rtt min/avg/max/mdev = 390.585/392.724/394.863/2.139 ms
發佈了46 篇原創文章 · 獲贊 132 · 訪問量 20萬+
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章