Centos7 最小安装不能联网

下载了Centos7最小化安装后,发现不能上网,ping 和 ifconfig都不能用

  1. 先用ip addr来查看ip,发现看不到ip,应该是网卡没有启动
    [root@localhost ~]# ip addr
    1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN group default qlen 1000
     link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
     inet 127.0.0.1/8 scope host lo
        valid_lft forever preferred_lft forever
     inet6 ::1/128 scope host 
        valid_lft forever preferred_lft forever
    2: ens33: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP group default qlen 1000
     link/ether 00:0c:29:70:22:8a brd ff:ff:ff:ff:ff:ff
  2. 进入到网络配置文件目录,找到前面在ip addr中看到的网卡为ens33
    [root@localhost  ~]# cd /etc/sysconfig/network-scripts
    [root@localhost  network-scripts]# ls
    ifcfg-ens33  ifdown-eth   ifdown-post    ifdown-Team      ifup-aliases  ifup-ipv6   ifup-post    ifup-Team      init.ipv6-global
    ifcfg-lo     ifdown-ippp  ifdown-ppp     ifdown-TeamPort  ifup-bnep     ifup-isdn   ifup-ppp     ifup-TeamPort  network-functions
    ifdown       ifdown-ipv6  ifdown-routes  ifdown-tunnel    ifup-eth      ifup-plip   ifup-routes  ifup-tunnel    network-functions-ipv6
    ifdown-bnep  ifdown-isdn  ifdown-sit     ifup             ifup-ippp     ifup-plusb  ifup-sit     ifup-wireless
  3. 修改ifcfg-ens33的文件
    修改 ONBOOT="yes",如查不存在ONBOOT创建一个并赋值为”yes”
  4. 重启网络服务,如果在虚拟机中,无法上网,重启一下
    [root@localhost  ~] service network restart
  5. 通过dhcp动态获取IP配置,参考文件
    TYPE="Ethernet"
    PROXY_METHOD="none"
    BROWSER_ONLY="no"
    BOOTPROTO="dhcp"
    DEFROUTE="yes"
    IPV4_FAILURE_FATAL="no"
    IPV6INIT="yes"
    IPV6_AUTOCONF="yes"
    IPV6_DEFROUTE="yes"
    IPV6_FAILURE_FATAL="no"
    IPV6_ADDR_GEN_MODE="stable-privacy"
    NAME="ens33"
    UUID="e4b1323f-5a09-46ce-a121-a51dabc1ee7b"
    DEVICE="ens33"
    ONBOOT="yes"
  6. 配置静态IP,参考文件
    TYPE="Ethernet"
    PROXY_METHOD="none"
    BROWSER_ONLY="no"
    BOOTPROTO="static"
    DEFROUTE="yes"
    IPV4_FAILURE_FATAL="no"
    IPV6INIT="yes"
    IPV6_AUTOCONF="yes"
    IPV6_DEFROUTE="yes"
    IPV6_FAILURE_FATAL="no"
    IPV6_ADDR_GEN_MODE="stable-privacy"
    NAME="ens33"
    UUID="e4b1323f-5a09-46ce-a121-a51dabc1ee7b"
    DEVICE="ens33"
    ONBOOT="yes"
    IPADDR="192.168.31.55"      # 静态IP 
    GATEWAY="192.168.31.1"    # 默认网关
    NETMASK="255.255.255.0"  # 子网掩码
    DNS1=192.168.31.1              # DNS 配置  
    DNS2=114.114.114.114         #
0%