centos7 ifconifg没有ip

来源:互联网 发布:算法英语 编辑:程序博客网 时间:2024/04/30 12:40

在安装时 设置了静态ip 但是 使用ifconfig命令时  只有 127.0.0.1的ip地址 

这时候查看/etc/sysconfig/network-scripts  目录下是否存在ifcfg-eth0 文件如果不存在 查看是否存在ifcfg-开头的文件 

我的系统存在ifcfg-eno16777736这样一个文件

more ifcfg-eno16777736

[liaomin@localhost network-scripts]$ more ifcfg-eno16777736
TYPE=Ethernet
BOOTPROTO=none
DEFROUTE=yes
IPV4_FAILURE_FATAL=no
IPV6INIT=yes
IPV6_AUTOCONF=yes
IPV6_DEFROUTE=yes
IPV6_FAILURE_FATAL=no
NAME=eno16777736
UUID=7170eda3-8183-41fc-b0b8-ee924d05ddc2
ONBOOT=no
IPADDR0=192.168.0.88
PREFIX0=24
HWADDR=00:0C:29:61:34:7D
IPV6_PEERDNS=yes
IPV6_PEERROUTES=yes

刚好为我在安装系统时添加的ip信息

此时 使用命令 cp  ifcfg-eno16777736 ifcfg-eth0  创建 ifcfg-eth0文件 同时将内容中的ONBOOT=no 改为 ONBOOT=yes

执行命令 service network restart 

执行 ifconfig 出现正确网络信息

eno16777736: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
        inet 192.168.0.88  netmask 255.255.255.0  broadcast 192.168.0.255
        inet6 fe80::20c:29ff:fe61:347d  prefixlen 64  scopeid 0x20<link>
        ether 00:0c:29:61:34:7d  txqueuelen 1000  (Ethernet)
        RX packets 102  bytes 10385 (10.1 KiB)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 128  bytes 13681 (13.3 KiB)
        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 818  bytes 71132 (69.4 KiB)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 818  bytes 71132 (69.4 KiB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0


如果安装环境为 vm虚拟机的host-only 下 想在虚拟机中上网  

找到win环境下的网卡vmnet1  通过属性 tcp/ip协议查看 他的ip地址 

假设这里为 192.168.0.12 而虚拟机中设置的ip是IPADDR0=192.168.0.88 需要在 ifcfg-eth0添加网关为 当前win的vmnet1的ip地址

即添加 GETEWAY=192.168.0.12 

在win上必须有一个能上网的网卡 比如我的笔记本为 无线网卡 右键属性 高级 允许其他网络通过此计算机的internet来连接勾上 下拉框 选上 vmnet的网卡

确定 如果弹出确认 选否即可

通过ipconfig -all命令 查看 无线网卡的 dns服务器 比如我的 如下

Ethernet adapter 无线网络连接:
       Connection-specific DNS Suffix  . :
        Description . . . . . . . . . . . : Broadcom 802.11n 网络
        Physical Address. . . . . . . . . : 08-3E-8E-4A-38-AB
        Dhcp Enabled. . . . . . . . . . . : Yes
        Autoconfiguration Enabled . . . . : Yes
        IP Address. . . . . . . . . . . . : 192.168.1.100
        Subnet Mask . . . . . . . . . . . : 255.255.255.0
        Default Gateway . . . . . . . . . : 192.168.1.1
        DHCP Server . . . . . . . . . . . : 192.168.1.1
        DNS Servers . . . . . . . . . . . : 211.162.66.66
                                            211.162.77.77

在  ifcfg-eth0添加DNS服务器 我这里有两个 

添加两行 

DNS1=211.162.66.66

DNS2=211.162.77.77

此时在虚拟机的 linux 重启 service network restart

ping www.baidu.com 成功


0 0
原创粉丝点击