下面主讲CentOS最小化安装后IP的配置,即DHCP获取IP地址、手动获取静态IP地址的方法。

一、CentOS最小化安装后IP的配置(DHCP获取IP地址)

图形化Linux的DHCP好配置,我就不讲了。主要讲一下Linux最小化安装后IP的配置。

linux最小化安装后没有ifconfig这个命令:

yum install net-tools.x86_64

这样就安装了ifconfig命令。

使用ifconfig看看IP:

centos最小化安装ifconfig centos最小化安装后 ip如何配置_最小化

可以看到并没有自动分配IP,我的VM是DHCP,网卡使用net连接:

centos最小化安装ifconfig centos最小化安装后 ip如何配置_最小化_02

首先,使用Linux自带网络工具试试:

nmtui

centos最小化安装ifconfig centos最小化安装后 ip如何配置_IP_03

这里Automatically connect是没法勾选的,退出使用命令行。

nmcli connection modify eno16777736 connection.autoconnect yes

表示对eno16777736这个网卡的自动连接修改(yes是打开,no是关闭)

centos最小化安装ifconfig centos最小化安装后 ip如何配置_centos最小化安装ifconfig_04

重启network服务:

systemctl restart network

再次使用ifconfig查看PI:(分配成功)

centos最小化安装ifconfig centos最小化安装后 ip如何配置_DHCP_05

使用nmtui试试:

centos最小化安装ifconfig centos最小化安装后 ip如何配置_centos最小化安装ifconfig_06

这里的勾已经打上。

 

二、CentOS最小化安装后IP的配置(手动获取静态IP地址)

1、图形化界面配置(假设为电脑A)

如果你的Linux安装有图形化界面,那么通过以下方式来配置:

centos最小化安装ifconfig centos最小化安装后 ip如何配置_DHCP_07

我这里是有两块网卡,第一个网卡在上面已经通过DHCP来配置了。

第一块王卡:

centos最小化安装ifconfig centos最小化安装后 ip如何配置_DHCP_08

看一下配置2:

centos最小化安装ifconfig centos最小化安装后 ip如何配置_最小化_09

另外一块网卡打算使用手动获取:

centos最小化安装ifconfig centos最小化安装后 ip如何配置_IP_10

看一下配置1:

centos最小化安装ifconfig centos最小化安装后 ip如何配置_DHCP_11

2、如果你的CentOS是最小安装请看下面的配置(电脑B)

centos最小化安装ifconfig centos最小化安装后 ip如何配置_最小化_12

也是两块网卡,第一块网卡同样是DHCP获取IP,在上面中已经通过DHCP来配置了。

打算第二块网卡手动配置IP。

1].查看电脑上安装的网卡

nmcli connection show 

centos最小化安装ifconfig centos最小化安装后 ip如何配置_centos最小化安装ifconfig_13

将在这个网卡上手动配置,查看该网卡的详细信息:

centos最小化安装ifconfig centos最小化安装后 ip如何配置_最小化_14

2].将ipv4的获取方式改为手动manual

nmcli connection modify Wired\ connection\ 1 ipv4.method manual

centos最小化安装ifconfig centos最小化安装后 ip如何配置_IP_15

只有先将IP的获取方式改为手动后才可以手动分配IP,否则不能设置IP。

3].修改IP的网关,地址,DNS

nmcli connection modify Wired\ connection\ 1 ipv4.addresses 196.168.1.2/24 ipv4.gateway 192.168.1.254 ipv4.dns 8.8.8.8

这句话相当于3句话(分别对地址,网关,DNS修改):

nmcli connection modify Wired\ connection\ 1 ipv4.addresses 196.168.1.2/24

nmcli connection modify Wired\ connection\ 1 ipv4.gateway 192.168.1.254

nmcli connection modify Wired\ connection\ 1 ipv4.dns 8.8.8.8

centos最小化安装ifconfig centos最小化安装后 ip如何配置_最小化_16

此处,还可以添加一个备用的dns:

nmcli connection modify Wired\ connection\ 1  +ipv4.dns 9.9.9.9

centos最小化安装ifconfig centos最小化安装后 ip如何配置_IP_17

4].重启服务

systemctl restart network

centos最小化安装ifconfig centos最小化安装后 ip如何配置_IP_18

5].激活网卡

centos最小化安装ifconfig centos最小化安装后 ip如何配置_IP_19

ifconfig查看:

centos最小化安装ifconfig centos最小化安装后 ip如何配置_DHCP_20

查看网卡信息:

nmcli connection show Wired\ connection\ 1 

centos最小化安装ifconfig centos最小化安装后 ip如何配置_最小化_21

可以看到已经成功。

ping一下A电脑:

centos最小化安装ifconfig centos最小化安装后 ip如何配置_centos最小化安装ifconfig_22

上图显示,已经成功。