我们在VMware或VirtualBox中启动CentOS7的虚拟机,登录后,查看网卡的IP4地址,发现ens33的IP地址并未显示出来。
1 2 3 4 5 6 7 8 9
| ip a 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:d5:43:ca brd ff:ff:ff:ff:ff:ff
|
这时,需要执行ifup ens33
命令,让网卡连接起来。
连接好以后,再次查看IP地址。
1 2 3 4 5 6 7 8 9 10 11 12 13
| ip a 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:d5:43:ca brd ff:ff:ff:ff:ff:ff inet 172.16.64.233/24 brd 172.16.64.255 scope global noprefixroute dynamic ens33 valid_lft 1778sec preferred_lft 1778sec inet6 fe80::e8ec:c304:253f:44b7/64 scope link noprefixroute valid_lft forever preferred_lft forever
|
发现已经有IP地址了。
如果想让重启后配置也能生效,还需要修改/etc/sysconfig/network-scripts/ifcfg-ens33
网卡配置。
把ONBOOT=no
改为ONBOOT=yes
1
| sed -i s/ONBOOT=no/ONBOOT=yes/g /etc/sysconfig/network-scripts/ifcfg-ens33
|