之前建了一台虚拟机,一块网卡vlan100(可访问公网),一块网卡vlan2(只能访问内网)

操作系统是centos 7

系统完整完成后发现无法上网,无法使用yum 进行软件安装以及系统升级。

  1. 首先使用ip addr 命令查看系统目前的IP地址
[root@localhost ~]# ip addr
1: lo:  mtu 65536 qdisc noqueue state UNKNOWN
    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: eno16777984:  mtu 1500 qdisc pfifo_fast state UP qlen 1000
    link/ether 00:50:56:b2:7a:6c brd ff:ff:ff:ff:ff:ff
    inet 172.24.3.37/24 brd 172.24.3.255 scope global dynamic eno16777984
       valid_lft 1125sec preferred_lft 1125sec
    inet6 fe80::250:56ff:feb2:7a6c/64 scope link
       valid_lft forever preferred_lft forever
3: eno33557248:  mtu 1500 qdisc pfifo_fast state UP qlen 1000
    link/ether 00:50:56:b2:68:6b brd ff:ff:ff:ff:ff:ff
    inet 172.25.2.189/23 brd 172.25.3.255 scope global dynamic eno33557248
       valid_lft 82125sec preferred_lft 82125sec
    inet6 fe80::250:56ff:feb2:686b/64 scope link
       valid_lft forever preferred_lft forever
2.查看路由
使用ip route或者ip route show命令
[root@localhost ~]# ip route show
default via 172.25.2.1 dev eno33557248  proto static  metric 1024
172.24.3.0/24 dev eno16777984  proto kernel  scope link  src 172.24.3.37
172.24.63.163 via 172.24.3.1 dev eno16777984  proto static  metric 1
172.25.2.0/23 dev eno33557248  proto kernel  scope link  src 172.25.2.189
3. 更改默认网关
使用
ip route add default via $GATEWAY
命令更改默认路由
其中 $GATEWAY 是你需要的设置的网关 IP
[root@localhost ~]# ip route add default via 172.25.2.1
  1. 改完后再看下路由
[root@localhost ~]# ip route show
default via 172.25.2.1 dev eno33557248
default via 172.25.2.1 dev eno33557248  proto static  metric 1024
172.24.3.0/24 dev eno16777984  proto kernel  scope link  src 172.24.3.37
172.24.63.163 via 172.24.3.1 dev eno16777984  proto static  metric 1
172.25.2.0/23 dev eno33557248  proto kernel  scope link  src 172.25.2.189

5.使用yum update 命令更新

[root@localhost ~]# yum -y update
Loaded plugins: fastestmirror
base                                                      | 3.6 kB  00:00:00
extras                                                    | 3.4 kB  00:00:00
updates                                                   | 3.4 kB  00:00:00
(1/4): extras/7/x86_64/primary_db                         |  54 kB  00:00:03
(2/4): updates/7/x86_64/primary_db                        | 1.7 MB  00:00:28
(3/4): base/7/x86_64/group_gz                             | 154 kB  00:00:54
(4/4): base/7/x86_64/primary_db                           | 5.1 MB  00:01:01
Determining fastest mirrors
 * base: centos.ustc.edu.cn
...