每次安装新镜像时会遇到物理机有网络新安装的linux中却无法与物理机通信(不能连网),只能玩一些预装功能、命令,无法使用各种常用工具(特别是MINI版连ifconfig都没有o(╥﹏╥)o),下面记录解决过程【提示cannot find a valid baseurl for repobase7x86_64也是因为没有网络】。
1、首先使用ip addr查看网卡名称
[root@ ~]# 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
2: ens33: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP group default qlen 1000
link/ether 00:0c:29:22:80:e3 brd ff:ff:ff:ff:ff:ff
从上面的信息中可以看到我的网卡名称叫ens33(不同版本的系统名称存在差异)
2、修改配置文件,将配置文件中的ONBOOT=no改为ONBOOT=yes并保存
[root@ ~]# cat -n /etc/sysconfig/network-scripts/ifcfg-ens33
1 TYPE=Ethernet
2 PROXY_METHOD=none
3 BROWSER_ONLY=no
4 BOOTPROTO=dhcp
5 DEFROUTE=yes
6 IPV4_FAILURE_FATAL=no
7 IPV6INIT=yes
8 IPV6_AUTOCONF=yes
9 IPV6_DEFROUTE=yes
10 IPV6_FAILURE_FATAL=no
11 IPV6_ADDR_GEN_MODE=stable-privacy
12 NAME=ens33
13 UUID=023bce24-ebd3-4d19-9911-e8b662axxxxx
14 DEVICE=ens33
15 ONBOOT=no
3、reboot重启
4、再次查看ip
[root@ ~]# 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:22:80:e4 brd ff:ff:ff:ff:ff:ff
inet 192.168.142.141/24 brd 192.168.142.255 scope global noprefixroute dynamic ens33
valid_lft 1653sec preferred_lft 1653sec
inet6 fe80::a0b:b3fa:fcdb:a92e/64 scope link noprefixroute
valid_lft forever preferred_lft forever
可以看到重启后正常联网了也能看到局域网所属ip了192.168.142.141
。
使用yum安装ifconfig试试能不能成功联网安装:
[root@ ~]# yum search ifconfig # 查找ifconfig所属包
已加载插件:fastestmirror
Loading mirror speeds from cached hostfile
* base: mirrors.shu.edu.cn
* extras: mirrors.zju.edu.cn
* updates: ftp.sjtu.edu.cn
========================================================================== 匹配:ifconfig ==========================================================================
net-tools.x86_64 : Basic networking tools
[root@ ~]# yum install net-tools.x86_64 # 安装对应工具包
已加载插件:fastestmirror
Loading mirror speeds from cached hostfile
* base: mirrors.shu.edu.cn
* extras: mirrors.zju.edu.cn
* updates: mirrors.nju.edu.cn
正在解决依赖关系
--> 正在检查事务
---> 软件包 net-tools.x86_64.0.2.0-0.24.20131004git.el7 将被 安装
--> 解决依赖关系完成
依赖关系解决
====================================================================================================================================================================
Package 架构 版本 源 大小
====================================================================================================================================================================
正在安装:
net-tools x86_64 2.0-0.24.20131004git.el7 base 306 k
事务概要
====================================================================================================================================================================
安装 1 软件包
总下载量:306 k
安装大小:918 k
Is this ok [y/d/N]: y
Downloading packages:
net-tools-2.0-0.24.20131004git.el7.x86_64.rpm | 306 kB 00:00:00
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
正在安装 : net-tools-2.0-0.24.20131004git.el7.x86_64 1/1
验证中 : net-tools-2.0-0.24.20131004git.el7.x86_64 1/1
已安装:
net-tools.x86_64 0:2.0-0.24.20131004git.el7
完毕!
# 测试ifconfig是否可用
[root@ ~]# ifconfig
ens33: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500
inet 192.168.142.141 netmask 255.255.255.0 broadcast 192.168.142.255
inet6 fe80::a0b:b3fa:fcdb:a93e prefixlen 64 scopeid 0x20<link>
ether 00:0c:29:22:80:e3 txqueuelen 1000 (Ethernet)
RX packets 8046 bytes 10053684 (9.5 MiB)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 2085 bytes 202580 (197.8 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 1000 (Local Loopback)
RX packets 4 bytes 352 (352.0 B)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 4 bytes 352 (352.0 B)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
成功安装,到此就成功解决不能联网的问题了^_^