通常最小安装是没有自动启动网络连接的,可以通过ifconfig
或ip addr
查看网络信息 (类似windows里的ipconfig
),然而最小安装是没有ifconfig
命令的, 这里我们使用ip addr
查看网络信息
[root@localhost ~]: ifconfig
-bash: ifconfig: command not found
[root@localhost ~]:
[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:16:27:c9 brd ff:ff:ff:ff:ff:ff
[root@localhost ~]:
这里看到ens33
并没有分配IP,使用vi
命令编辑配置文件,vi /etc/sysconfig/network-scripts/ifcfg-xxx
(xxx为查看到的网络名称),这里为ens33
[root@localhost ~]: vi /etc/sysconfig/network-scripts/ifcfg-ens33
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=c02aadee-742b-40f7-aa65-8dece35b4eae
DEVICE=ens33
ONBOOT=no
按i
键,进入insert模式,将ONBOOT=no
修改为ONBOOT=yes
, 按esc
键回到command模式,输入:wq
保存退出。
service network restart
重启网络服务
[root@localhost ~]: service network restart
Restarting network (via systemctl): [ OK ]
[root@localhost ~]:
最后再查看网络信息,可以看到已分配IP 192.168.254.131
[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:16:27:c9 brd ff:ff:ff:ff:ff:ff
inet 192.168.254.131/24 brd 192.168.254.255 scope global noprefixroute dynamic ens33
valid_lft 1676sec preferred_lft 1676sec
inet6 fe80::7807:42ed:927:f9e3/64 scope link noprefixroute
valid_lft forever preferred_lft forever
[root@localhost ~]:
附注
- 也可以使用网络配置工具
# nmtui