龙空技术网

centos8 - 设置静态IP

linux运维菜 123

前言:

现在我们对“centos网络设置为静态ip”大体比较讲究,看官们都需要分析一些“centos网络设置为静态ip”的相关文章。那么小编也在网络上收集了一些关于“centos网络设置为静态ip””的相关内容,希望看官们能喜欢,大家一起来了解一下吧!

简介

在CentOS8上已经完全使用了NetworkManager管理网络,已经没有network.service文件了。但是配置文件还是存放到/etc/sysconfig/network-scripts这个目录。这里面的配置文件可以通过nmcli命令生成。

命令帮助

Usage: nmcli [OPTIONS] OBJECT { COMMAND | help }

OPTIONS

-a, --ask ask for missing parameters

-c, --colors auto|yes|no whether to use colors in output

-e, --escape yes|no escape columns separators in values

-f, --fields <field,...>|all|common specify fields to output

-g, --get-values <field,...>|all|common shortcut for -m tabular -t -f

-h, --help print this help

-m, --mode tabular|multiline output mode

-o, --overview overview mode

-p, --pretty pretty output

-s, --show-secrets allow displaying passwords

-t, --terse terse output

-v, --version show program version

-w, --wait <seconds> set timeout waiting for finishing operations

OBJECT

g[eneral] NetworkManager's general status and operations

n[etworking] overall networking control

r[adio] NetworkManager radio switches

c[onnection] NetworkManager's connections

d[evice] devices managed by NetworkManager

a[gent] NetworkManager secret agent or polkit agent

m[onitor] monitor NetworkManager changes

常用命令组合

查看网络设备(网络设备状态等)

nmcli device

查看网络连接

ncmcli connection

创建网络连接

设置enp0s3网络的静态IPv4:192.168.57.100/24,网关:192.168.57.1,IP设置方式为manual

nmcli connection add type ethernet con-name enp0s3 ifname enp0s3 ipv4.addr 192.168.57.100/24 ipv4.gateway 192.168.57.1 ipv4.method manual

设置DHCP获取IP

nmcli c add type ethernet con-name enp0s3 ifname enp0s3 ipv4.method auto

修改IP

nmcli c modify enp0s3 ipv4.addr '192.168.57.200/24'

激活连接

nmcli c up enp0s3

关闭连接

nmcli down enp0s3

关闭并删除连接配置文件

nmcli delete enp0s3

查看网络具体信息

nmcli c show enp0s3

重载配置文件(不会马上生效)

nmcli c reload

重载配置文件(马上生效)

nmcli c up ens32nmcli d reapply ens32nmcli d connect ens32

激活网卡

nmcli d connect ens32

关闭无线网络

nmcli r all off

查看NetworkManager状态

nmcli n

开启NetworkManager状态

nmcli n on

关闭NetworkManager(谨慎执行,会断网)

nmcli n off
总结

CentOS8还兼顾了之前版本的配置,直接编辑文件也可以,但是还是使用命令生成比较准确。

标签: #centos网络设置为静态ip #centos网络配置静态ip